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
CMake dependecy management
- paul_z
- Gnoblar
- Posts: 2
- Joined: Wed Jan 27, 2016 9:45 am
- Location: Romania
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: CMake dependecy management
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
- dark_sylinc
- OGRE Team Member
- Posts: 5296
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1278
- Contact:
Re: CMake dependecy management
On Linux another option is to use "make -i" which will not stop on build errors; and then you build again.
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: CMake dependecy management
Oh I forgot about add_dependencies (https://cmake.org/cmake/help/v3.3/comma ... ncies.html), that's likely what suits you best
- paul_z
- Gnoblar
- Posts: 2
- Joined: Wed Jan 27, 2016 9:45 am
- Location: Romania
Re: CMake dependecy management
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.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 think I need to use 'add_custom_target' with 'DEPENDS' option for file-level dependencies because add_dependencies only works for top-level targets.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
Thanks
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: CMake dependecy management
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:
The resulting makefiles / project will have 3 targets, and each will build in the correct order and link against each other using CMake magic
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")