[CMake] Target flags depending on compilation of another target

Jesper Eskilson jesper at eskilson.se
Fri Dec 21 03:15:19 EST 2007


Rodolfo Lima wrote:
> How can I set an executable compiler flags based on the result of the
> compilation of another target? Or, with another words, can I set a
> directory's COMPILER_FLAGS at build time?

Not generally, no. However, if you know that you'll be using Make with a 
bourne-shell to build you can sneak in things like "`cat somefile.txt`" 
into your CMAKE_CXX_FLAGS, and have your custom target write flags to 
"somefile.txt". This technique is commonly used in Unix makefiles to 
allow compiler-flags to be generated "on-the-fly" by a utility program.

If you need a general solution, you probably have to hijack your 
compiler executable (cl.exe, for example) to dynamically insert options 
before invoking the real compiler executable.

-- 
/Jesper




More information about the CMake mailing list