CMake与系统和标准包括生成的c + +项目

关于标题,我发现很多讨论,但不幸的是没有适当的/普遍的答案。 对于Eclipse CDT,可以在全局范围内设置包含,但是如果编译器发生变化,则必须重新执行。 因此,我编写了以下CMakeFile.txt最小示例来设置编译器使用的includes。

 # Check wheter required CMake Version is installed cmake_minimum_required(VERSION 2.8.7 FATAL_ERROR) # Set the project name to the name of the folder string (REGEX MATCH "[^/]+$" PROJECT_NAME "${CMAKE_CURRENT_BINARY_DIR}") message (STATUS "Set PROJECT_NAME to ${PROJECT_NAME}") project ("${PROJECT_NAME}") # Grep the standard include paths of the c++ compiler execute_process(COMMAND echo COMMAND ${CMAKE_CXX_COMPILER} -Wp,-v -x c++ - -fsyntax-only ERROR_VARIABLE GXX_OUTPUT) set(ENV{GXX_OUTPUT} ${GXX_OUTPUT}) execute_process(COMMAND echo ${GXX_OUTPUT} COMMAND grep "^\ " OUTPUT_VARIABLE GXX_INCLUDES) # Add directories to the end of this directory's include paths include_directories( ${GXX_INCLUDES} ) # Defines executable name and the required sourcefiles add_executable("${PROJECT_NAME}" main.cpp) 

包括的内容是在a **中的一些痛苦,但它的工作原理。 还有一点是,它不适用于cmake 2.8.7以上版本的cmake 2.8.7 ,这个bug http://public.kitware.com/Bug/view.php?id=15211 。 那么,我想知道有没有人有更好的方法来设置系统包含?

我发现了一种解决方法,比cmake 2.8.7更高版本的cmake。 关键是,我必须与名单分开工作; 。 正如zaufi提到的那样,当然可以添加标准包含,但是这只能与标准环境一起工作,而不能用于交叉编译环境。

所以这里是工作CMakeLists.txt

 # Check wheter required CMake Version is installed cmake_minimum_required(VERSION 2.8.7 FATAL_ERROR) # Set the project name to the name of the folder string (REGEX MATCH "[^/]+$" PROJECT_NAME "${CMAKE_CURRENT_BINARY_DIR}") message (STATUS "Set PROJECT_NAME to ${PROJECT_NAME}") project ("${PROJECT_NAME}") # Grep the standard include paths of the c++ compiler execute_process(COMMAND echo COMMAND ${CMAKE_CXX_COMPILER} -Wp,-v -x c++ - -fsyntax-only ERROR_VARIABLE GXX_OUTPUT) set(ENV{GXX_OUTPUT} ${GXX_OUTPUT}) execute_process(COMMAND echo ${GXX_OUTPUT} COMMAND grep "^\ " COMMAND sed "s#\ ##g" COMMAND tr "\n" "\\;" OUTPUT_VARIABLE GXX_INCLUDES) # Add directories to the end of this directory's include paths include_directories( ${GXX_INCLUDES} ) # Defines executable name and the required sourcefiles add_executable("${PROJECT_NAME}" main.cpp)