Cmakelists. TXT is a configuration file for CMake, which is convenient for compiling large projects. I wrote a uniform template for my frequently used projects and wrote down the common grammar. Use the time to remove the corresponding comments can be.

cmake_minimum_required(VERSION 3.5)
project(pr) # compile option #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/")
#LISTAPPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules) # Set the compile mode#set(CMAKE_BUILD_TYPE "Debug")
#IF(NOT CMAKE_BUILD_TYPE)
#  SET(CMAKE_BUILD_TYPE Release)
#ENDIF() # use Qt Creater to open cmakelists.txt as required below2Line # -o0: no optimization #-O2: enable O2 optimization #-O3: Enable O3 optimization # -wall: display all warnings #-g: generate debugging information using the native format of the operating system # -ggDB: make GCC generate richer debugging information for GDBSET(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) # open (1) or close (0)C++11features#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(a)Specify the output directory#set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/libs)
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/bin)# Assign ${PROJECT_NAME} to LIBRARY_NAME #STRING(TOLOWER ${PROJECT_NAME} LIBRARY_NAME) # secondary cmakelists.txt path #ADD_SUBDIRECTORY(${LIBRARY_NAME})
#ADD_SUBDIRECTORY# add 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} #find_package(OpenNI2 REQUIRED)
#include_directories(# ${OpenNI2_INCLUDE_DIR} ##set(Eigen3_DIR /home/XXX/software/eigenunstable/share/eigen3/cmake)
#find_package(Eigen3 REQUIRED)
#include_directories(# ${EIGEN3_INCLUDE_DIRS} # /usr/include/eigen3 ##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)Find libraries and header files based on G2O_ROOT in findg2O.cmakefind_package(G2O REQUIRED) 
#include_directories( 
#    ${G2O_INCLUDE_DIR}
#)
#link_directories(${G2O_ROOT}/lib#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(a)
#include_directories(${Boost_INCLUDE_DIRS} ## /opt/boost/lib ## set (PCL_DIR/home/XXX/software/pcl180 / share/photo - 1.8)
#find_package(PCL REQUIRED)
#include_directories(${PCL_INCLUDE_DIRS})
#link_directories(${PCL_LIBRARY_DIRS})
#add_definitions(${PCL_DEFINITIONS}) # Remove a link library (if it causes an error, stop linking it with this statement)#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 #) # header file path #include_directories(
#	${PROJECT_SOURCE_DIR}/include	#(project location)
#	${CMAKE_SOURCE_DIR}
#	include#) # generate library#file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/ *. Cc) # GLOB: no recursive # add_library (${PROJECT_NAME} # STATIC | SHARED | MODULE # # ${source_files} SRC/lib/lib. Cc #) # generate libraries need to rely on #target_link_libraries(${PROJECT_NAME} # ${OpenCV_LIBS} # ${EIGEN3_LIBS} #) #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})Copy the code

Complete this introduction to CMakeLists formal environment templates common syntax.