[CMake] Setting a cmake option via make targets?

szalai endre hufilufi at freemail.hu
Wed Nov 2 05:25:43 EDT 2011


Hi guys,

I am using Rational Purify for runtime error checks in C++. To use it, you have to call purify instead of the C++ linker at link phase. To do so, I have the following cmake file:

//------------
project(myproject )
option (USE_PURIFY "Use Rational Purify for runtime error checks" OFF)
IF (USE_PURIFY)
    set(CMAKE_CXX_LINK_EXECUTABLE "purify ${CMAKE_CXX_LINK_EXECUTABLE}")
ENDIF (USE_PURIFY)
add_executable (myproject HelloWorld.cc)
//------------

This adds the option and changes the linker (prepending with "purify"). This works fine.

Now I would like to trigger the IF() line from a make target. Say, when I type "make myproject_purify", I would like to set the option (or prepend the linker, whichever is best).

I am quite uncertain how to do it with cmake. I did not find any hint if I can set options from cmake itself or not. Also, whenever I define a new make target, I have to supply a shell command and it seems I cannot execute cmake commands there.

So my question: how would you set an option via a make target? Any hints?

Thanks,
Mc


More information about the CMake mailing list