开发者

cmake - Link custom library from higher level directory

开发者 https://www.devze.com 2023-04-08 07:14 出处:网络
I\'m learning about cmake and am finding it very fast to learn.However, documentation is not up to scratch.The tutorials are helpful, but only go so far.

I'm learning about cmake and am finding it very fast to learn. However, documentation is not up to scratch. The tutorials are helpful, but only go so far.

What I have is an existing project that I want to convert to using cmake.

The project structure currently looks like:

obsys/ obsys/client/ {client files} obsys/server/ {server files} obsys/utils/include obsys/utils/src

I've created CMakeLists.txt files at each level.

The top level looks currently like this:

make_minimum_required (VERSION 2.6)
project (osys)
add_subdirectory (server)
add_subdirectory (u开发者_如何学JAVAtils)

Inside utils I have a CMakeLists.txt that contains:

include_directories ("${PROJECT_SOURCE_DIR}/utils/include")
add_subdirectory (src)

and inside the utils src directory the CMakeLists.txt file contains:

add_library(utils myException.cpp)

The server needs to link to utils. It's CMakeLists.txt contains:

make_minimum_required (VERSION 2.6)
project (server)
include_directories ("../utils/include")
add_executable(serv serv.cpp)
add_subdirectory("../utils/src" utils)
target_link_libraries(obbsd utils)

The idea with this layout is I was hoping I could build the whole lot through the top level Makefile. Or, jump into server, or client and build either of them. It's not working out that way. What is the recommended way to do this?


Ok, I now have it working.

The problem is that my add_executable line wasn't listing all the source files. Link seemed to be complaining about something to do with utils which made me think it wasn't finding the library when actually it was.

0

精彩评论

暂无评论...
验证码 换一张
取 消