How to pass COMPILE_DEFINITIONS cmake parameter via terminal? I tried to pass -DCOMPILE_DEFINITION(S)="MyOption1" , -DCOMPILE_DEFINITION_LIST="MyOption1 MyOption2" , -DMyOption1=ON - these parameters are not passed.

But if you write the string ADD_DEFINITIONS(-MyOption1 -MyOption2) in CMakeLists.txt , they are perceived.

How to transfer these parameters through the terminal?

    3 answers 3

    Problem in wrong DEFINITIONs task

     -DCOMPILE_DEFINITIONS_LIST:STRING="MyOption1;MyOption2" 

      If you write like this:

       cmake CMakeFiles.txt -Dtest=ON 

      it will not work. It is necessary so:

       cmake -Dtest=ON CMakeFiles.txt 
      • I just wrote cmake -Dtest = ON. Besides the parameter I needed, there were a lot of others there, and cmake understood them - neko69
      • And the desired parameter does not accidentally contain the symbol = or is it not accidentally written like this -D test=on or so "-D test=on" ? - KoVadim

      No The command line passes control commands for CMake. Everything else needs to be written in the file itself. For example. -D creates an entry in the CMake cache file. If you need to add some definitions, depending on the parameters passed to the cmake command, do this:

       if(MyOption1) add_definition(-MyOption1) endif() 

      And then call cmake -DMyOption1=ON