[CMake] Query build flags

Frank Hartmann soundart at gmx.net
Tue Jul 17 15:35:17 EDT 2012


Hi,

I have here a C/C++ project which builds several shared libraries and
executables on linux and windows.  

Makefile, Jom and Visual Studio 20xx build systems are generated with
cmake.

The code is organised hierachically: There is a root directory, followed
by a broad separation in source, test, and 3rd party code. Below that
there are lots of directories containg various components.

root/CMakeLists.txt
root/src/CMakeLists.txt
root/src/component_a/CMakeLists.txt
root/test/CMakeLists.txt
root/test/component_a/CMakeLists.txt
root/3rd_party/CMakeLists.txt
root/3rd_party/lib_a/CMakeLists.txt

and so on.. 

Several components have quite complex build systems doing
all kind of cool stuff (like 3rd_party/OpenCV) most list CFLAGS and
files and are relativly easy to understand.

Files in 
/src/ are compiled with -Wall -Werror, in /test/ with -Wall,
/3rd_party/ have no such general settings. Some ohter overall settings
are defined in root/CMakeLists.txt too.

My problem: I have noticed now, that for a library compiled with a
-DLIB_USE_PTHREADS defined in root/3rd_party/lib_a/CMakeLists.txt it
happens that upon usage (including headers and linking) from
root/src/component_a/CMakeLists.txt other flags are used, which leads to
quite unpleasent effects. 

The problem continues: Parts of the system use SSE for floating point
calculations, other parts use i387 hardware units. Parts use /EHa others
/EHsc and so on...

I though it would be useful to have some sort of check upfront and then
in a second step try to align the used switches. I would like to use
cmake for this check as I do not know for most windows build systems how
to make the used flags visible. 

I have tried today to make for every file ending with *.cpp
(file(GLOB_RECURSE ...) a list of all flags used during compilation. I
played on linux with get_property() on SOURCE, TARGET, DIRECTORY, GLOBAL
level, used the properties COMPILE_DEFINITIONS and COMPILE_FLAGS and
their _DEBUG and _RELEASE variants.

As this did not match the observed flags using "VERBOSE=1 make" I added
CMAKE_CXX_FLAGS and lots of other variables to my debug output. Still I
failed to generate the full list of flags being used. 


So my question is: How do I do this? How does cmake do it?

Is there a way to make query all flags or make the used flags visible
even for windows build tools? Or should I try something completely
different?

many thanks!
  Frank


More information about the CMake mailing list