¶ 传入宏定义
option(MACRO_NAME
“Descriptions of the macro”OFF)
if (MACRO_NAME)
add_compile_definitions(MACRO_NAME)
endif ()
然后cmake .. -DMACRO_NAME=ON
,再make
就好了。
¶
find_library
https://stackoverflow.com/questions/29657195/how-to-test-if-cmake-found-a-library-with-find-library
find_library(LUA_LIB lua)
if(NOT LUA_LIB)
message(FATAL_ERROR "lua library not found")
endif()
¶ message
https://cmake.org/cmake/help/latest/command/message.html
¶ PUBLIC, PRIVATE, INTERFACE
Difference between PRIVATE and PUBLIC with target_link_libraries
假设A PRIVATE依赖B,A是静态库,B是动态库。如果executable C依赖A的话,cmake会自动把B链接到C上。
¶ 已知的问题
¶
忽略LD_LIBRARY_PATH
CMake会忽略LD_LIBRARY_PATH
。因此把库放进LD_LIBRARY_PATH
里CMake还是找不到。
不过可以在cmake里读取环境变量LD_LIBRARY_PATH
:https://stackoverflow.com/a/49738486/13688160
然后就可以把它作为find_package
的参数或者加入到target_link_directories
里。