cmake学习笔记

传入宏定义

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_PATHhttps://stackoverflow.com/a/49738486/13688160

然后就可以把它作为find_package的参数或者加入到target_link_directories里。

posted @ 2024-09-28 13:05  寻找繁星  阅读(0)  评论(0编辑  收藏  举报