[CMake] List of components being build.

Alexander Neundorf a.neundorf-work at gmx.net
Fri Feb 5 13:06:32 EST 2010


On Tuesday 02 February 2010, Schwartz, Philip wrote:
> My current project has many components that need to be built. Some portions
> of our code depend on others and using add_subdirectory, I am having an
> issue where I get multiple of my targets loaded causing a faliure.
>
> I placed the add_subdirectory in a macro that uses a simple hash style of
> access
>
> set ( BUILD_MAP_${_name} 1 ) where ${_name} is the target name.
>
> I have an if statement in the macro that tests if BUILD_MAP_${_name} is
> defined. The issue is say I have a custom mysqlclient that is used by 3 of
> my projects that are all built as part of "all".
>
> Project A: Depends on Mysqlclient
> Project B: Depends on Mysqlclient
> Project C: Depends on Mysqlclient
>
> Dir structure
> all/
>    /lib/Mysqlclient
>    /bin/Project A
>    /bin/Project B
>    /bin/Project C
>
> each of these folders have a CMakeLists.txt. The all/CMakeLists.txt has the
> following
>
> project(all)
> add_subdirectory(lib/Mysqlclient)
> add_subdirectory(bin/Project A)
> add_subdirectory(bin/Project B)
> add_subdirectory(bin/Project C)
>
> When building from the top level and having a definition of "-lmysqlclient"
> everything works as expected. The issue comes up when I do not want to
> build all of the source.
>
> Say I would like to build only Project B.
>
> from my build directory, I would run cmake ~/all/Project B.
>
> The cmake process ends without issue, but the make fails on link due to the
> missing Mysqlclient library not being built. 

Yes, because it's not part of the project then.
I would suggest you always run cmake on the top level directory, but make it 
possible to disable the other subdirectories (Project A..C)

Alex


More information about the CMake mailing list