[CMake] Selectively adding source files and compiling assembly sources

Johannes Bauer dfnsonfsduifb at gmx.de
Sun May 27 06:35:47 EDT 2012


Hi list,

I'm a total beginner to CMake as a developer (although I've used it in
the past for other projects before). Now I'm starting by converting a
rather large Automake-Project to CMake. I'm doing it from scratch.

In the project, executables and a shared library are created from the
same objects. Which objects are chosen, however, depends on the
configuration. For example consider the following sources:

featurea/obj1.c
featurea/obj2.c
featurea/obj3.c
featureb/obj1.c
featureb/obj2.c
featureb/obj3.c
common.c

let's say I want to create a executable only from common.c, but it
should also compile and link featurea/*.c if the option WITH_A is set
and should also compile and link featureb/*.c if the option WITH_B is
set. These I've specified in the CMakeLists file:

option(WITH_A "Enable FOO support" ON)
option(WITH_B "Enable BAR component" OFF)

However, I see no way of adding features to the "add_executable" option
after it has been specified (something like add_source or the likes).
How can this be done?

Another problem I've run into is that the project has some assembly
files ("*.s"), which even though I specify them in the add_executables
command are just ignored (leading to unresolved symbols, of course, at
link time). Any pointers for this?

And is it maybe possible (not dramatic if it isn't) to group options
into subgroups so they're easier to configure using cmake-gui? There is
a "Grouped" checkbox, but it only uses the string representation (i.e.
FOO_BAR is group FOO, subitem BAR) and allows only one level of nesting.
Something like configuration of the linux kernel (with multiple levels
of configuration) maybe?

Best regards,
Joe


More information about the CMake mailing list