-
一般CMake项目文件结构说明
src
build
doc
CMakeLists.txt
README
runhello.sh
COPYRIGHT
src 中 CMakeLists.txt文件
-
一般CMake构建静、动态库项目文件结构说明
build
lib
CMakeLists.txt
lib中 CMakeLists.txt文件
-
内部构建项目文件结构及CMakeLists.txt语句
PROJECT(HELLO)
SET(SRC_LIST hello.c)
MESSAGE(STATUS "This is BINARY dir" ${HELLO_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir" ${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello ${SRC_LIST})
-
外部构建可安装项目文件结构及CMakeLists.txt语句
外面的CMakeLists.txt内容:
PROJECT(HELLO_PROJECT)
ADD_SUBDIRECTORY(src bin)
INSTALL(FILES COPYRIGHT README DESTINATION testcmake/install/cmake/)
INSTALL(PROGRAMS runhello.sh DESTINATION testcmake/install/cmake/bin)
INSTALL(DIRECTORY doc/ DESTINATION testcmake/install/cmake/doc)
src内部的CMakeLists.txt内容:
SET(SRC_LIST hello.c)
ADD_EXECUTABLE(hello ${SRC_LIST})
-
外部构建动、静态库文件结构及CMakeLists.txt语句
外面的CMakeLists.txt内容:
PROJECT(HELLO)
ADD_SUBDIRECTORY(lib bin)
lib内部的CMakeLists.txt内容:
SET(SRC_LIST hello.c)
ADD_LIBRARY(hello_static STATIC ${SRC_LIST})
SET_TARGET_PROPERTIES(hello_static PROPERTIES OUTPUT_NAME "hello")
SET_TARGET_PROPERTIES(hello_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ADD_LIBRARY(hello_so SHARED ${SRC_LIST})
SET_TARGET_PROPERTIES(hello_so PROPERTIES OUTPUT_NAME "hello")
SET_TARGET_PROPERTIES(hello_so PROPERTIES CLEAN_DIRECT_OUTPUT 1)
INSTALL(FILES hello.h DESTINATION /usr/include/hello)
INSTALL(TARGETS hello_static hello_so LIBRARY DESTINATION /usr/lib ARCHIVE DESTINATION /usr/lib)