1)对于共享库:
add_library(kdevbooklib SHARED source.cpp)
更多信息。
2)链接。
更新:
根 CMakeList.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
PROJECT(MyGreatProject)
SET(LIBRARY_OUTPUT_PATH ${MyGreatProject_BINARY_DIR}/bin CACHE PATH
"Single output directory for building all libraries.")
SET(EXECUTABLE_OUTPUT_PATH ${MyGreatProject_BINARY_DIR}/bin CACHE PATH
"Single output directory for building all executables.")
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
ADD_SUBDIRECTORY(MyGreatProjectLib)
ADD_SUBDIRECTORY(MyGreatProjectBin)
库 MyGreatProjectLib/CMakeLists.txt:
PROJECT(MyGreatProjectLib)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR})
add_library(MyGreatProjectLib SHARED source.cpp)
Bin MyGreatProjectBin/CMakeLists.txt
PROJECT(MyGreatProjectBin)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${MyGreatProjectLib_SOURCE_DIR})
add_executable(MyGreatProjectBin main.cpp)
target_link_libraries(MyGreatProjectBin MyGreatProjectLib)