# sb7code-CMake练习 **Repository Path**: Arcadia1989/sb7-code-cmake-exercise ## Basic Information - **Project Name**: sb7code-CMake练习 - **Description**: sb7随书源码中CMake部分有些写死的地方, 想改成自己喜欢的样子, 现在卡在引入的第三方库glfw没能自动加头文件与导入库的目录 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-07 - **Last Updated**: 2024-01-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 记录一下在Gitee怎么提交, 这一个问题在Gitee搜索也是找不到答案的 原因是: 使用了SSH的方式克隆库, 一但用这个方式, 就会出现 "Permission denied" 官方是有教程, 但是官方的教程用官方的搜索是搜不到的: 《提交第一行代码》 https://gitee.com/help/articles/4122 # 对库引用做处理的视频教程: https://www.bilibili.com/video/BV1hz4y1H7YA?p=20 # 视频教程学习笔记 第一步 将[目标安装]添加导出 ``` install(TARGETS ${installable_libs} EXPORT MathFunctionsTargets DESTINATION lib) ``` 在对应库的CMaketLists.txt里添加 有了这步之后, 就可以生成配置文件 接下来是头文件搜索路径 还是在库的CMakeLists.txt ``` target_include_directories(MathFunctions INTERFACE "$" "$" ) ``` 作用:如果是本地构建的版本则返回当前路径, 如果是安装版本,则是include路径 第三步 安装生成的 MathFunctionsTargets.cmake ``` install(EXPORT MathFunctionsTargets FILE MathFunctionsTargets.cmake DESTINATION lib/cmake/MathFunctions ) ``` 第四步 准备MathFunctionsConfig.cmak文件模板与生成 CMakeLists.txt相对目录下建Config.cmake.in模板文件 BEGIN 模板文件内容 ``` @PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/MathFunctionsTargets.cmake") ``` END 模板文件内容 第四步2 在CMakeLists.txt中写: 注意修改INSTALL_DESTINATION安装路径 ``` configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfig.cmake" INSTALL_DESTINATION "lib/cmake/MathFunctions" NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO ) ``` 第五步 生成版本文件(非必需) 也是在CMakeLists.txt里修改 ``` write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfigVersion.cmake" VERSION "${Tutorial_VERSION_MAJOR}.${Tutorial_VERSION_MINOR}" COMPATIBILITY AnyNewerVersion ) ``` 第六步 安装生成文件 也是在CMakeLists.txt里修改 ``` install(FILES ${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfigVersion.cmake DESTINATION lib/cmake/MathFunctions ) ``` # 记录Git 提交时的一个冲突问题 "refusing to merge unrelated histories" 网络上的解决方案: ``` We’ve done enough talking. To solve this issue, you can use the --allow-unrelated-histories flag when pulling data from a repository: Git pull origin master –allow-unrelated-histories You’ll want to substitute origin with the remote repository from which you are pulling resources. You should replace master with the branch that you want to retrieve. This command was added to handle the rare event that you are working with two projects that have their own branches. Alternatively, you could clone a new version of the remote repository using git clone and start over. However, this is not usually necessary. You can read more about the –allow-unrelated-histories flag on the official Git documentation. ``` 引用https://careerkarma.com/blog/git-fatal-refusing-to-merge-unrelated-histories/ 关键的命令: ``` git pull --allow-unrelated-histories ``` 执行命令后, 需要修改冲突文件