0

Our Library uses Cmake while the Overall system uses Make file for build.

I want to port the value of a variable (preprocessor macro) defined in the makefile to Cmakefile and use it as preprocessor marco in source codes of my library.

How to do that?

1
  • You'll have to tell us more about how CMake is integrated into the Makefile. Commented Feb 5, 2014 at 18:13

1 Answer 1

1

You can define variable at CMake invocation like so:

cmake -DMY_VAR=ON <path_to_CMakeLists.txt>

Then later in your CMake file:

if (MY_VAR)
    add_definitions(-DENABLE_MY_VAR)
endif()

And finally in your code:

#ifdef ENABLE_MY_VAR
    // Your code
#endif
Sign up to request clarification or add additional context in comments.

8 Comments

can you please elaborate this? cmake -DMY_VAR=ON <path_to_CMakeLists.txt> Do I do this in makefile?
It is not clear from your question how CMake is triggered. Is it launched when you run make in the global project ?
yes ... global project is built using make...which will also trigger cmake to build our library as a shared library.
So when make launches cmake to generate makefiles, you can pass it variables based on the make variable by formatting the launch command accordingly. Adding example of the variable you want to pass on and the snippet from your makefile launching CMake will help in giving an answer.
it is sth like this @cd $(PROJECT_DIR)/build/CMake && ./bootstrap.sh
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.