CMake dependecy management

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
User avatar
paul_z
Gnoblar
Posts: 2
Joined: Wed Jan 27, 2016 9:45 am
Location: Romania

CMake dependecy management

Post 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 :)
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: CMake dependecy management

Post 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
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: CMake dependecy management

Post by dark_sylinc »

On Linux another option is to use "make -i" which will not stop on build errors; and then you build again.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: CMake dependecy management

Post 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
User avatar
paul_z
Gnoblar
Posts: 2
Joined: Wed Jan 27, 2016 9:45 am
Location: Romania

Re: CMake dependecy management

Post 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
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: CMake dependecy management

Post 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
Post Reply