[CMake] setting/removing compiler flag (-g) for a single project directory

René J.V. Bertin rjvbertin at gmail.com
Fri Sep 15 08:13:51 EDT 2017


Hi,

Is it possible to  set and/or remove compiler arguments on a project subdirectory that holds a tree with sources of a considerable number of build targets?

An example to make this more concrete: I have a project that contains

common_libs
plugins/foo
plugins/this_one

I'm just interested in building plugins/this_one and can do so by calling make && make install/fast inside the build/plugins/this_one directory. All plugin dependencies are already installed (with debug info). The build/common_libs directory gets pretty big and is expensive to build, so ideally I would build everything in there with different flags, basically replacing -O3|-O2 with -Os and removing the -g option, possibly even running a strip before continuing the rest of the build.

I know one can do this kind of thing per target or even per file, but how does one do it on a directory basis? Do I have to cache the original CMAKE_C*_FLAGS value before modifying it in common_libs/CMakeLists.txt , and restore it before returning from that file? Or is there a more elegant method?

Thanks,
René


More information about the CMake mailing list