CMake project organisation

2019-08-29 12:32发布

I have different projects (executables and libraries) that use the same internal libraries. Each project and internal library folder is located in the same base folder.

Let's say I have a shell tool named shelltool1 and shelltool2 that use lib1. They are located in

/path/to/base/shelltool1
/path/to/base/shelltool2
/path/to/base/lib1

Do I build the executable/library in the respective folders and link them in the CMakeLists.txt inside /path/to/base ?

So my idea would be

base: CMakeLists.txt

add_subdirectory(shelltool1)
add_subdirectory(shelltool2)
add_subdirectory(lib1)

target_link_libraries(shelltool1 lib1)
target_link_libraries(shelltool2 lib1)

shelltool1: CMakeLists.txt

add_executable(shelltool1 ${SRC})

shelltool2: CMakeLists.txt

add_executable(shelltool2 ${SRC})

lib1: CMakeLists.txt

add_library(lib1 ${SRC})

Is this sensible, or will I run into troubles?

0条回答
登录 后发表回答