C ++ project created by CMake with system and standard includes

As for the name, I found a lot of discussion, but, unfortunately, no correct / universal answer. You can set global inclusions for the Eclipse CDT, but if your compiler changes, you must do it again. Thus, I wrote the following working minimal example CMakeFile.txtto set the inclusions that are used by the compiler.

# 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 include paths
include_directories(
    ${GXX_INCLUDES}
)

# Defines executable name and the required sourcefiles
add_executable("${PROJECT_NAME}" main.cpp)

greping involves some pain in **, but it works. Another thing is that it does not work for cmake above cmake 2.8.7regarding this error http://public.kitware.com/Bug/view.php?id=15211 . So, I want to know if anyone has a better way to install the system?

0
1

cmake, cmake 2.8.7. , , ;. 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 include paths
include_directories(
    ${GXX_INCLUDES}
)

# Defines executable name and the required sourcefiles
add_executable("${PROJECT_NAME}" main.cpp)
+1

All Articles