CMakeLists.txt语法
程序员文章站
2024-02-19 18:41:46
...
CMakeLists.txt是CMake的配置文件,方便编译大型项目。我为自己常用的项目写了一个统一的模板,把常用的语法记录下来。使用的时候去掉对应的注释就可以。
cmake_minimum_required(VERSION 2.8)
project(pr)
# ${CMAKE_SOURCE_DIR}: The directory of root CMakeLists.txt
# ${CMAKE_CURRENT_SOURCE_DIR}: The directory of this CMakeLists.txt
#SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/CMakeModules/")
#LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
#设置编译模式
#set(CMAKE_BUILD_TYPE "Debug")
#IF(NOT CMAKE_BUILD_TYPE)
# SET(CMAKE_BUILD_TYPE Release)
#ENDIF()
#使用Qt creater打开CMakeLists.txt需要有下面2行
#-O0:不优化
#-Wall:显示所有警告
#-g:利用操作系统的原生格式(native format)生成调试信息
#-ggdb:使GCC为GDB生成专用的更为丰富的调试信息
#SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
#SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
#C++11
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#add_compile_options(-std=c++11)
#打开(1)或关闭(0)C++11特性
#if(CONAN_LIBCXX STREQUAL "libstdc++11")
# add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
#elseif(CONAN_LIBCXX STREQUAL "libstdc++")
# add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
#endif()
#指定输出目录
#set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/libs)
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/bin)
#把${PROJECT_NAME}变量值的全小写赋值给变量LIBRARY_NAME
#STRING(TOLOWER ${PROJECT_NAME} LIBRARY_NAME)
#次级CMakeLists.txt所在路径
#ADD_SUBDIRECTORY(${LIBRARY_NAME})
#ADD_SUBDIRECTORY(examples)
#添加OpenCV
#set(OpenCV_DIR /home/XXX/software/OpenCV310/share/OpenCV)自定义安装的OpenCV目录
#set(CMAKE_PREFIX_PATH /home/master/local_install/)
#find_package(OpenCV 3.1.0 EXACT REQUIRED)
#find_package(OpenCV REQUIRED)
#MESSAGE(STATUS "opencv version: ${OpenCV_VERSION}")
#include_directories(
# ${OpenCV_DIRS}
# ${OpenCV_INCLUDE_DIRS}
#)
#添加openni
#find_package(OpenNI2 REQUIRED)
#include_directories(
# ${OpenNI2_INCLUDE_DIR}
#)
#添加Eigen
#set(Eigen3_DIR /home/boyob/software/eigenunstable/share/eigen3/cmake)
#find_package(Eigen3 REQUIRED)
#include_directories(
# ${EIGEN3_INCLUDE_DIRS}
# /usr/include/eigen3
#)
#添加G2O
#set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) #the location of FindG2O.cmake
#set(G2O_ROOT /home/boyob/software/g2o)
#set(G2O_DIR /home/boyob/software/g2o/share)
#在FindG2O.cmake中根据G2O_ROOT查找库和头文件
#find_package(G2O REQUIRED)
#include_directories(
# ${G2O_INCLUDE_DIR}
#)
#link_directories(${G2O_ROOT}/lib)
#添加Boost
##set(BOOST_ROOT "/opt/boost")
#set(BOOST_ROOT /home/boyob/software/boost159)
##set(BOOST_LIBRARY_DIR "" CACHE PATH " directory of the boost lib")
##set(BOOST_INCLUDE_DIR "" CACHE PATH " directory of the boost headers")
##SET(BOOST_LIBRARYDIR "${BOOST_LIBRARY_DIR}")
##SET(BOOST_INCLUDEDIR "${BOOST_INCLUDE_DIR}")
##set(Boost_USE_STATIC_LIBS ON)
##set(Boost_USE_MULTITHREADED ON)
##set(Boost_USE_STATIC_RUNTIME OFF)
#find_package(Boost REQUIRED COMPONENTS
# regex
# filesystem
# system
# thread
#)
#if(NOT Boost_FOUND)
# message("--Failed to find Boost.")
#endif()
#include_directories(
# ${Boost_INCLUDE_DIRS}
## /opt/boost/lib
#)
#添加pcl
#set(PCL_DIR /home/boyob/software/pcl180/share/pcl-1.8)
#find_package(PCL REQUIRED)
#include_directories(${PCL_INCLUDE_DIRS})
#link_directories(${PCL_LIBRARY_DIRS})
#add_definitions(${PCL_DEFINITIONS})
#set(BUILD_USE_64BITS on)
#第三方库路径
#Equivalent to add "LD_LIBRARY_PATH" in ~/.bashrc
#link_directories(
# ${PROJECT_SOURCE_DIR}/libs
#)
#头文件路径
#include_directories(
# ${PROJECT_SOURCE_DIR}/include #(project location)
# ${CMAKE_SOURCE_DIR}
# include
#)
#生成库
#file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) #GLOB:不递归
#add_library(${PROJECT_NAME} #STATIC | SHARED | MODULE
# ${source_files}
# src/lib/lib.cc
#)
#生成库需要的依赖
#target_link_libraries(${PROJECT_NAME}
# ${OpenCV_LIBS}
# ${EIGEN3_LIBS}
#)
#生成可执行文件
add_executable(run main.cc)
#生成可执行文件需要的依赖
#target_link_libraries(run
# ${OpenCV_LIBS}
# ${OpenNI2_LIBRARY}
# ${PROJECT_NAME}
# g2o_core g2o_stuff
# ${Boost_LIBRARIES}
# ${PCL_LIBRARIES}
# pthread
#)
#add_dependencies(run ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})