CMakeLists 正式环境模板常用语法

CMakeLists 正式环境模板常用语法CMakeLists.txt是CMake的配置文件,方便编译大型项目。我为自己常用的项目写了一个统一的模板,把常用的语法记录下来。使用的时候去掉对应的注释就可以。cmake_minimum_required(VERSION 3.# ${CMAKE_SOURCE_DIR}: The…

CMakeLists.txt是CMake的配置文件,方便编译大型项目。我为自己常用的项目写了一个统一的模板,把常用的语法记录下来。使用的时候去掉对应的注释就可以。

cmake_minimum_required(VERSION 3.5)
project(pr)
 
#编译选项
#add_definitions("-DXXX")
 
# ${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:不优化 
#-O2:开启O2优化
#-O3:开启O3优化
#-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/OpenCV340/share/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/XXX/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/XXX/software/g2o)
#set(G2O_DIR /home/XXX/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/XXX/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/XXX/software/pcl180/share/pcl-1.8)
#find_package(PCL REQUIRED)
#include_directories(${PCL_INCLUDE_DIRS})
#link_directories(${PCL_LIBRARY_DIRS})
#add_definitions(${PCL_DEFINITIONS})
#移除某个链接库(当它引起错误时,通过这条语句不再链接它)
#list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
 
#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}) 

到此 CMakeLists 正式环境模板常用语法介绍完成。

今天的文章CMakeLists 正式环境模板常用语法分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/15346.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注