我最近决定将 FlameSteelFramework 的所有部分设为单独的共享库,然后我将展示 FlameSteelCore:
cmake_minimum_required(VERSION 3.5)
project (FlameSteelCore)
set(CMAKE_BUILD_TYPE Release)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
file(GLOB_RECURSE SOURCE_FILES
"src/FlameSteelCore/*.cpp"
)
add_library(FlameSteelCore SHARED ${SOURCE_FILES})
install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/FlameSteelCore"
DESTINATION include/FlameSteelFramework
FILES_MATCHING
PATTERN "*.h"
)
install(TARGETS FlameSteelCore DESTINATION lib)
CMake 执行的命令:将 src/FlameSteelCore/ 目录中所有带有 *.cpp 扩展名的文件收集到共享库中,将 src/FlameSteelCore 中带有 *.h 扩展名的所有标头复制到 include/FlameSteelFramework (在我的例子中)这是/usr/local/include/FlameSteelFramework),将共享lib复制到lib目录(/usr/local/lib)
安装后,可能需要更新LD缓存– sudo ldconfig。
要在 Ubuntu 上构建并安装(如果您有正确的构建工具链),只需运行以下命令:
cmake . && make && sudo make install
为了测试安装过程,我将 make 前缀传递到本地文件夹 makeInstallTestPlayground:
cmake -DCMAKE_INSTALL_PREFIX:PATH=/home/demensdeum/makeInstallTestPlayground . && make && make install
参考文献
https: //stackoverflow.com/questions/17511496/how-to-create-a-shared-library-with-cmake
https://stackoverflow.com/questions/6003374/what-is-cmake-equivalent-of-configure-prefix-dir-make-all-install