[CMake] Setting a cmake option via make targets?

Yngve Inntjore Levinsen yngve.levinsen at gmail.com
Wed Nov 2 14:32:19 EDT 2011


Onsdag 02 november 2011 skrev szalai endre:
> 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
> --
> 
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

Hi,

Just an idea, would it be possible to just add a second target and use 
set_target_properties() somehow? I'm guessing it would be something like:

set(sources HelloWorld.cc)
add_executable (myproject ${sources})
add_executable (myproject_purify ${sources} EXCLUDE_FROM_ALL)
set_target_properties(myproject_purify CMAKE_CXX_LINK_EXECUTABLE "purify 
${CMAKE_CXX_LINK_EXECUTABLE}")

I have not tested this, so I might be wrong.

Cheers,
Yngve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111102/c4503157/attachment-0001.htm>


More information about the CMake mailing list