M
M
Mars362021-04-12 23:07:46
CMake
Mars36, 2021-04-12 23:07:46

How to properly use your options in cmake?

I want to add my options to the project. I do so

option(DEPEND_DOWNLOAD_FROM_GIT "Select download dependens" OFF)

When trying to use an option in the console
cmake -DEPEND_DOWNLOAD_FROM_GIT=ON ..

cmake tries to configure the project in a folder named option, for example:
-- Build files have been written to: F:/code/C++/test/build/DEPEND_DOWNLOAD_FROM_GIT=ON

If you call cmake with the option
-LH
, then cmake will show this option. the documentation ( https://cmake.org/cmake/help/latest/command/option.html ) only says that the user can select OFF, ON and the case when the option is not set. I did not find an example of use. How do I use self-written options correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2021-04-13
@Mars36

1. The first parameter when starting cmake is the path to the CMakeLists.txt file to be processed.
Usually, the build process using cmake looks something like this:
I create an empty directory for building the project in an arbitrary place, go to it, and execute there: cmake <путь к cmakelists.txt>
In this case, the source directory is not filled with build artifacts that are not needed there.
2. options in cmake are passed like cmake ... -D<имя опции>[=значение]
this -D is the key followed by the option name. Now compare with how you apply it.
The syntax is similar to defining macros on the command line of C/C++ compilers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question