[CMake] How to rename the resulting Makefile.

Michael Wild themiwi at gmail.com
Thu Oct 14 02:42:52 EDT 2010


On 13. Oct, 2010, at 23:31 , william.crocker at analog.com wrote:

> 
>> Nevertheless,
>> I think may be you did not fully read my answer (unless I'm wrong)
>> but you CAN call [part of] your home made makefile rules
>> ** FROM THE SEPARATE CMAKE BUILD  **
> 
> I read it, I just did not get it, being a newbie and all.    :-)
> But, I see now.
> 
>> if you add some extra CMake lines like the following:
>> add_custom_target(save
>>                            COMMAND ${CMAKE_MAKE_PROGRAM} save
>>                            WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
>>                            COMMENT "Home brewed make save target")
>> The previous line will create in the CMake generated makefile
>> a rule which when invoked will call your makefile rule
>> (same name) in the source tree.
>> 
> 
> I leave my existing makefiles in the source tree and CMake will
> create the build Makefiles in the out-of-source area.
> In this way they will not step on my existing makefiles.
> 
> Then, simple targets in the CMake makefiles can be used
> to run the real targets in my existing makefile (which live
> in the source area.)
> 
> Very clever.
> 
> Bill

But please, put something like this in your CMakeLists.txt:

# detect symlink trickery
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
# prevent in-source builds
if("${srcdir}" STREQUAL "${bindir}")
  message(FATAL_ERROR "In-source builds are forbidden!")
endif()


Otherwise it is all too easy to shoot yourself in the foot!

Michael

--
There is always a well-known solution to every human problem -- neat, plausible, and wrong.
H. L. Mencken

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20101014/da6a6581/attachment.pgp>


More information about the CMake mailing list