Page 1 of 1

CMake dependecy management

Posted: Wed Jan 27, 2016 11:12 am
by paul_z
Hello,

I'm trying to make a multiplayer spacesim and I've hit a wall. My code is split in three subprojects:
"clancer" - this is the client binary
"clserver" - this is the server binary
"ClCommon" - this is a shared library that contains shared binary code between client and server.

I'm using the 'add_subdirectory' CMake function from the root project.

My problem: when I build the root project, I get unresolved references to symbols in my shared library. How do I tell CMake to build my shared library first and then the binaries. I know this is a RTFM question but I'm hopping to get a quick answer here.

Thanks :)

Re: CMake dependecy management

Posted: Wed Jan 27, 2016 5:39 pm
by c6burns
I use ExternalProject_Add to manage my dependencies, but I'm by no means a CMake expert so perhaps someone else has something better and brighter

Re: CMake dependecy management

Posted: Thu Jan 28, 2016 2:15 am
by dark_sylinc
On Linux another option is to use "make -i" which will not stop on build errors; and then you build again.

Re: CMake dependecy management

Posted: Thu Jan 28, 2016 4:24 am
by c6burns
Oh I forgot about add_dependencies (https://cmake.org/cmake/help/v3.3/comma ... ncies.html), that's likely what suits you best

Re: CMake dependecy management

Posted: Thu Jan 28, 2016 2:21 pm
by paul_z
dark_sylinc wrote:On Linux another option is to use "make -i" which will not stop on build errors; and then you build again.
I love Linux, but I would like to target windows as well and there is/should be a CMake solution. I'm using Qt Creator as an IDE and I need to run CMake & build twice. In the first run, it builds the library and in the second CMake finds my library with "file(GLOB)" dirrective and builds my executables.
c6burns wrote:Oh I forgot about add_dependencies (https://cmake.org/cmake/help/v3.3/comma ... ncies.html), that's likely what suits you best
I think I need to use 'add_custom_target' with 'DEPENDS' option for file-level dependencies because add_dependencies only works for top-level targets.
Thanks :D

Re: CMake dependecy management

Posted: Mon Feb 01, 2016 4:53 am
by c6burns
OK maybe I am late responding to this, so you already have it solved, but I guess I am not understanding how top level target dependencies aren't good enough for this. For example you have your top level dir, with the 3 subproject dirs (client, server and common). Common is a library target so in its subproject it calls add_library which creates your library target. Then your other projects just need to use target_link_libraries on the common target ... CMake handles everything else.

Anyway, if it's not worth the time to explain what I'm missing no worries. I just want to give a quick example because I just set this up on a new project so it's fresh:

Code: Select all

project(AwesomeProject)

# this is where add_library(AwesomeCommon) is called
add_subdirectory("AwesomeCommon")

# inside this project we target_link_libraries(AwesomeClient AwesomeCommon)
add_subdirectory("AwesomeClient")

#same here ... link against the common library target
add_subdirectory("AwesomeServer")
The resulting makefiles / project will have 3 targets, and each will build in the correct order and link against each other using CMake magic