[CMake] Making with purify
William A. Hoffman
billlist at nycap.rr.com
Mon Oct 18 11:56:49 EDT 2004
Your right. It is broken. It would only work with a SUBDIR.
I am thinking something like this:
SET(CMAKE_PURIFY_LINK_C "purify ${CMAKE_C_LINK_EXECUTABLE}")
SET_TARGET_PROPERTIES(my_exe.purify PROPERTIES LINK_RULE CMAKE_PURIFY_LINK_C )
Basically, allow the user to change the rule variable used for linking a target
via a property on the target.
-Bill
At 09:40 PM 10/14/2004, Eric Bolz wrote:
>There seems to be a problem with your solution. Without the SET_TARGET_PROPERTIES() command I would expect to get 2 binaries when I type 'make', one with purify and one without. But I get 2 binaries and they are both built with purify. Perhaps I made a mistake. Your example does not include any TARGET_LINK_LIBRARIES() commands. I assume I need one for each binary.
>Where should they be placed?
>I did the following:
>ADD_EXECUTABLE(my_exe ${MY_SOURCES})
>SET(CMAKE_C_LINK_EXECUTABLE "purify ${CMAKE_C_LINK_EXECUTABLE}")
>TARGET_LINK_LIBRARIES(my_exe ${MY_LIBRARIES})
>ADD_EXECUTABLE(my_exe.purify ${MY_SOURCES})
>TARGET_LINK_LIBRARIES(my_exe.purify ${MY_LIBRARIES})
>
>Whats wrong?
>
>
>
>William A. Hoffman wrote:
>
>>I think a more simple approach would be to add a property to targets:
>>IN_ALL.
>>
>>Then you can do this:
>>
>># create normal executable part of all build
>>ADD_EXECUTABLE(my_exe etc...)
>># change the rule for linking a c executable to run purify before all the other commands
>>SET(CMAKE_C_LINK_EXECUTABLE "purify ${CMAKE_C_LINK_EXECUTABLE}") # modified example from p. 56
>># add a new executable that is the same as my_exe but with a .purify
>>ADD_EXECUTABLE(my_exe.purify etc...)
>># tell cmake not to build this target every time
>>SET_TARGET_PROPERTIES(my_exe.purify PROPERTIES IN_ALL FALSE)
>>
>>
>>I tried it and it seems to work well, I should be able to commit on Monday.
>>This will allow any target (exe or library) to be optionally built.
>>
>>-Bill
>>
>>
>>At 03:57 PM 10/14/2004, Eric Bolz wrote:
>>
>>
>>>There is a way to use ADD_CUSTOM_TARGET to do almost what I want.
>>>Here is the command:
>>>ADD_CUSTOM_TARGET(pure purify ${CMAKE_COMPILER} {$COMPILE_FLAGS} $CMAKE_C_LINK_FLAGS} ${LINK_FLAGS} ${FLAGS} ${MY_OBJECTS} my_exe.purify ${MY_LIBRARIES})
>>>
>>>With this custom target I can type 'make pure' and it will build my_exe.purify
>>>However, this solution is poor because dependencies are not picked up.
>>>But as long as I do a plain old 'make' first it works.
>>>
>>>It seems to me it would not be difficult to modify the ADD_EXECUTABLE command as follows:
>>>ADD_EXECUTABLE( executableName [WIN32] [MACOSX_BUNDLE]
>>> [ NAME name ]
>>>(Optional parameter)
>>> [ OPT purify | valgrind | quantify | other] (Optional parameter)
>>> source1 source2 source3 ... source(n)}
>>>It would build the executable only if you typed 'make name'
>>>The OPT parameter would cause the execuable to be build with any command the user wants such as purify, quantiy, or valgard.
>>>
>>>
>>>William A. Hoffman wrote:
>>>
>>>
>>>
>>>>Currently, there is no way to to make a target optionally part of the all build.
>>>>If you are just using make, you might be able to do something like this:
>>>>
>>>>SET(CMAKE_CXX_LINK_EXECUTABLE "$(PURIFY) ${CMAKE_CXX_LINK_EXECUTABLE}")
>>>>ADD_EXECUTABLE(my_exe etc...)
>>>>
>>>># to build a purified my_exe
>>>>rm my_exe
>>>>make PURIFY=purify # to build the regular my_exe
>>>>rm my_exe
>>>>make The $(PURIFY) variable will be treated as a make variable, and
>>>>will expand to nothing when you do not define it on the command line.
>>>>
>>>>
>>>>-Bill
>>>>
>>>>
>>>>
>>>>At 03:52 PM 10/13/2004, Eric Bolz wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>In Mastering CMake, page 56, the example for building a purify version works fine but sometimes I want to build with purify and sometimes I don't. How is that done? I can do the following:
>>>>>ADD_EXECUTABLE(my_exe etc...)
>>>>>SET(CMAKE_C_LINK_EXECUTABLE "purify etc...") as per the example on page 56
>>>>>ADD_EXECUTABLE(my_exe.purify etc...)
>>>>>
>>>>>But now my makefile produces both the purify and non-purify executables every time.
>>>>>I just want to type 'make' to build my regular executable and I want to type 'make purify' when I want the purified version. Can this be done?
>>>>>
>>>>>_______________________________________________
>>>>>CMake mailing list
>>>>>CMake at www.cmake.org
>>>>>http://www.cmake.org/mailman/listinfo/cmake
>>>>>
>>>>>
>>>>
>>>_______________________________________________
>>>CMake mailing list
>>>CMake at www.cmake.org
>>>http://www.cmake.org/mailman/listinfo/cmake
>>>
>>
>>
More information about the CMake
mailing list