On 03/14/2011 11:55 PM, Óscar Fuentes wrote: > Hendrik Sattler <p...@hendrik-sattler.de> > writes: > >>> "The COMPILE_FLAGS property sets additional compiler flags used to build >>> sources within the target." >>> >>> So it *adds* flags. I want to *set* flags, i.e. replace the existing >>> ones. >> >> So you add global compiler flags which are not meant to be global? A usual >> person would say: "then do not set them globally!". >> It's really that simple... > > No, I want to replace those automatically setted by CMake.
AFAIK, CMake doesn't set compilation flags by itself, perhaps unless a specific toolchain/platform file enforces this. Rather, the flags are roughly set up as follows - for C compilations: 1) CMAKE_C_FLAGS for all configurations; explicitly set or initialized by the CFLAGS environment variable when CMake is run initially. 2) Addition of CMAKE_C_FLAGS_<CONFIG> for the configuration. 3) Addition of COMPILE_FLAGS source/target properties. If you set neither CFLAGS/CMAKE_C_FLAGS nor CMAKE_C_FLAGS_<CONFIG> nor COMPILE_FLAGS, your source files should be compiled without any flags, so the art is to specify the latters such that each source file will be compiled with the correct/desired set of them. However, you're right insofar that there's no possibility to specify flags which will be used solely for a certain target *and* a certain configuration, but in my experience, this is almost never necessary. Do you have a special problem in this regard, i.e. a flag that must be activated for one target in one configuration only? Furthermore, the user is free to choose the compiler for the project, and the compilation flags are - basically, at least - specific to the compiler, so one should be particularly conservative w.r.t. hardcoding them in CMakeLists.txt files, IMO. Besides, the compilation flags are also mentioned in the linker command line which is required sometimes [1]; not doing so might result in subtle failures. The CMAKE_C_FLAGS and CMAKE_C_FLAGS_<CONFIG> are passed to the linker, too, but the COMPILE_FLAGS aren't, AFAICS. Finally, if you really need to drop a flag from a compilation command and can't avoid its addition by other means, you could use one of the RULE_LAUNCH_COMPILE properties to intercept the compiler command and adjust the command line to whatever is necessary [2]. Regrettably, this is restricted to the Makefile generators. Alternatively, you might modify the CMAKE_C_COMPILE_OBJECT rule variable within the affected directories, especially w.r.t. the <FLAGS> placeholder, see [3]. Regards, Michael [1] http://www.mail-archive.com/cmake@cmake.org/msg30015.html [2] http://www.mail-archive.com/cmake@cmake.org/msg35215.html [3] http://www.mail-archive.com/cmake@cmake.org/msg35282.html _______________________________________________ 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