我正在尝试为项目编写CMakeLists.txt。
文件夹结构为:
root
|-- CMakelists.txt
|-- src
|-- module
|-- source files
|-- CMakeLists.txt
(模块是项目模块之一的子目录)。
每个模块目录都有一个构建静态库的CMakeLists.txt。
``main''CMakeLists.txt调用子CMakeLists,链接每个库和main并构建可执行文件。
子CMakeLists运行良好:他们构建了库而没有错误(现在我正在使用正确的代码进行测试)。
但是当我尝试使用根CMakeLists构建(构建可执行文件)时,我遇到了错误:
make[2]: *** No rule to make target 'src/Physics/lib/Debug/libPhysics.a', needed by 'bin/Debug/PolyBarres'. Stop.
错误发生在集合中的第一个库(PROJECT_LIBS ....)
主要的CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
project(PolyBarres)
include("compil-option.cmake")
set(GUIDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/GUI)
# ... same for other modules
set(CMAKE_USE_RELATIVE_PATHS TRUE)
add_subdirectory("${LOBBYDIR}")
# ... same for other modules
set(PROJECT_LIBS ${PROJECT_LIBS}
"${PHYDIR}/lib/${CMAKE_BUILD_TYPE}/libPhysics.a"
# ... same for other modules
)
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} ${PROJECT_LIBS})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
compil-option.cmake:
# ... compilation flags ...
if(CMAKE_BUILD_TYPE EQUAL Debug)
set(EXEC_NAME "${EXEC_NAME}_debug")
endif(CMAKE_BUILD_TYPE EQUAL Debug)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/Debug)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib/Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib/Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/Release)
模块的CMakeLists.txt(此处为GUI):
cmake_minimum_required(VERSION 2.6)
set(module "GUI")
file(GLOB SRC . *.cpp)
add_library(${module} ${SRC})
include("${CMAKE_CURRENT_SOURCE_DIR}/../../compil-option.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/../../testing.cmake")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../include")
SET_TARGET_PROPERTIES(${module} PROPERTIES LINKER_LANGUAGE CXX)
我该如何解决这个问题?
编辑:更换问题解决了问题:
set(PROJECT_LIBS ${PROJECT_LIBS}
"${PHYDIR}/lib/${CMAKE_BUILD_TYPE}/libPhysics.a"
# ... same for other modules
)
通过
set(PROJECT_LIBS ${PROJECT_LIBS}
"Physics"
# ... same for other modules
)