参考文档
官方文档
变量的简单使用:
set(A ON) if (A) message(STATUS "${A}") message(STATUS "${PROJECT_NAME}") message(STATUS "${PROJECT_SOURCE_DIR}") message(STATUS "${PROJECT_BINARY_DIR}")
|
强制使用静态链接:
set(CMAKE_EXE_LINKER_FLAGS "-static")
|
改可执行文件名:
add_executable(use_easyx main.cpp)
|
链接库:
link_directories(${PROJECT_SOURCE_DIR}/lib) target_link_libraries(use_easyx easyx)
|
include链接目录(头文件):
include_directories(${PROJECT_SOURCE_DIR}/include)
|
添加子项目目录:
文件:
flie(GLOB TEST "${PROJECT_SOURCE_DIR}/*.h" "${PROJECT_SOURCE_DIR}/*.cpp" ) aux_source_directory(${PROJECT_SOURCE_DIR}/src TEST2) foreach(c $(TEST)) endforeach()
|
外部命令:
execute_process(COMMAND git clone https://github.com/<username>/<repository>.git WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/deps/<repository>)
|
包管理:
include(FetchContent)
FetchContent_Declare( my-logger GIT_REPOSITORY https://github.com/ACking-you/my-logger.git GIT_TAG v1.6.2 GIT_SHALLOW TRUE ) FetchContent_MakeAvailable(my-logger)
add_excutable(main ${SRC})
target_link_libraries(main my-logger)
|
这样引入第三方库的好处显而易见,优点类似于包管理的效果了,但缺少了最关键的中心仓库来确保资源的有效和稳定。参考golang再做个proxy层级就好了。 同样可以拉取最新的googletest可以使用下列语句:
FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG release-1.12.1 GIT_SHALLOW TRUE )
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest)
target_link_libraries(main gtest_main)
|
vcpkg有空了解一下(备忘)
未完待续…….