-- Common command
1. cmake_minimum_required
set the min version, eg.cmake_minimum_required(VERSION 2.6)
2. project
set the project name, eg. project (mypj)
3. CMAKE_SOURCE_DIR
The main CMakeLists.txt absolutely directory,
This var is no need to set, Just use it!
4. CMAKE_LIBRARY_DIR
output library path
5. CMAKE_BINARY_DIR
output binary path
6. add_subdirectory
add subdirectory of CMakeLists.txt
7. set
set a variable
8. include_directories
the header path
9. link_directories
the path of libraries to be linked
10. link_libraries
the libraries to be linked, eg. link_libraries(pthread m)
11. target_link_libraries
which is similar to link_libraries, but they have diffrent:
target_link_libraries is always in the end of CMakeLists.txt
12. add_executable
set the build target to binary, eg. add_executable(hello hello.c)
13. add_library
set the build target to library(shared or static)
build shared: eg. add_library(mylib SHARED test.c)
build static: eg. add_library(mylib STATIC test.c)
14. add_definitions
You can see it as Makefile's CFLAGS/CXXFLAGS
eg. add_definitions("-Wall -O3")
--Other command
1. aux_source_directory(<dir> <variable>)
Add all source file into list of the very directory
eg. aux_source_directory(../src MY_SRCS)
2. file
Now, We just use the add function, which is similar to aux_source_directory,
but more powerful because it can specify the type of files.
(1) add file
file(GLOB/GLOB_RECURSE variable [globbing expressions]...)
eg. file(GLOB MYSRCS ../src/*.cpp)
3. list
Now , We just use the remove function, which will remove the item(s) from a
variable
1) remove
list(REMOVE_ITEM <variable> value)
eg. list(REMOVE_ITEM MYSRCS ../src/test.cpp)
4. source_group
which can group the sources, it's very useful in the windows platform for
visual studio.
source_group("src\\abc" FILES MYSRCS)
cmake common usage
最新推荐文章于 2024-08-13 10:48:46 发布