cmake common usage

-- 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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值