cmake备忘
获取文件夹下的所有文件
aux_source_directory(<dir>, <variable>)
collects the names of all source files in the specified directory and store the list in the variable provided.
1
2
3
4AUX_SOURCE_DIRECTORY(libraries/api API_SRC)
AUX_SOURCE_DIRECTORY(libraries/net NET_SRC)
AUX_SOURCE_DIRECTORY(libraries/rpc RPC_SRC)
file(GLOB <variable> [<globbing-expressions>...])
generate a list of files that matchand store it in variable.
1
2
3
4
5
6
7
8
9file( GLOB LEVEL_DB_SOURCES "${LEVEL_DB_DIR}/db/*.cc"
"${LEVEL_DB_DIR}/helpers/memenv/memenv.cc"
"${LEVEL_DB_DIR}/table/*.cc"
"${LEVEL_DB_DIR}/util/*.cc" )
foreach( filename ${LEVEL_DB_SOURCES} )
if( ${filename} MATCHES ".*_test.cc" OR ${filename} MATCHES ".*_bench.cc" OR ${filename} MATCHES ".*_main.cc" )
list( REMOVE_ITEM LEVEL_DB_SOURCES ${filename} )
endif()
endforeach()
执行(内嵌)目录下的CMakeList.txt
include(path\CMakeList.txt)
获取路径信息/文件名信息
get_filenamecomponent(<VAR> <FileName> <COMP> [CACHE])
1 | get_filenamecomponent(dir "${CMAKE_CURRENT_LIST_FILE}" PATH) |
信息的输出
message([<mode>] "messages to display" ...)
添加include以及lib
- impact on directory scope
include_directories(path...)
link_libraries(path...)
- only impact on target
target_include_directories()
target_link_libraries()
匹配编译器
CMAKE_[language]_COMPILER_ID
1 | if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |