I'm trying to write a CMakeLists.txt for a project.
The folder structure is :
root
|-- CMakelists.txt
|-- src
|-- module
|-- source files
|-- CMakeLists.txt
(module being the sub directory of one of the project's module).
Each module directory have a CMakeLists.txt that build a static library.
The ``main'' CMakeLists.txt call the sub-CMakeLists, link every library and with the main and build the executable.
The sub-CMakeLists work well : they build the library without error (for now I'm testing with correct code).
But when I try to build with the root CMakeLists (to build an executable), I've got an error :
make[2]: *** No rule to make target 'src/Physics/lib/Debug/libPhysics.a', needed by 'bin/Debug/PolyBarres'. Stop.
The error is on the first library in set(PROJECT_LIBS ....)
The main 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 of a module (here 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)
How can I fix this ?
EDIT : problem solved by replacing :
set(PROJECT_LIBS ${PROJECT_LIBS}
"${PHYDIR}/lib/${CMAKE_BUILD_TYPE}/libPhysics.a"
# ... same for other modules
)
by
set(PROJECT_LIBS ${PROJECT_LIBS}
"Physics"
# ... same for other modules
)