My project structure is the following:
root
-CMakeLists.txt
----exec
-----CMakeLists.txt
-----src
------a.cpp
------a.h
----lib
-----CMakeLists.txt
-----src
------b.cpp
-----inc
------b.h
Exec target depends on lib target. My main CMakeLists.txt is just the following:
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0048 NEW)
project(FOO CXX)
add_subdirectory(lib)
add_subdirectory(exec)
In the CMakeLists.txt of the library I use add_library() and I use add_executable() in the exec folder. The problem is that the executable can't find the library and I don't know how to say in the exec CMakeLists.txt that another target exist called lib which is a library to use. I think I'm missing something in the project configuration.
Lib CmakeLists.txt
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0048 NEW)
project(BASIC CXX)
add_library(BASIC src/b.cpp)
set(HEADERS_FILE_DIRS inc)
include_directories(${HEADERS_FILE_DIRS})
#Linking
target_link_libraries(BASIC pthread)
Exec CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0048 NEW)
project(EXEC CXX)
add_executable(EXEC src/a.cpp)
set(HEADERS_FILE_DIRS src ${CMAKE_CURRENT_SOURCE_DIR}/../lib/inc)
include_directories(${HEADERS_FILE_DIRS})
set_target_properties(EXEC PROPERTIES OUTPUT_NAME "EXEC")
find_library(BASIC_LIBRARY BASIC HINTS <ABS PATH HERE>/lib)
#Linking
target_link_libraries(EXEC pthread ${BASIC_LIBRARY})