cotire
cotire copied to clipboard
target_include_directories(... SYSTEM ...) does not work with cotire
Given this code:
cmake_minimum_required(VERSION 3.6)
project(foo)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
include(cotire)
add_library(foo a.cpp b.cpp c.cpp)
add_library(bar a.cpp b.cpp c.cpp)
target_include_directories(foo PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
target_include_directories(bar SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
set_property(TARGET foo PROPERTY COTIRE_CXX_PREFIX_HEADER_INIT "${CMAKE_CURRENT_SOURCE_DIR}/prefix.hpp")
set_property(TARGET bar PROPERTY COTIRE_CXX_PREFIX_HEADER_INIT "${CMAKE_CURRENT_SOURCE_DIR}/prefix.hpp")
cotire(foo)
cotire(bar)
foo can build, but bar cannot if the prefix header contains files that should be found through the include directories list.
If you want to test. (It is called genexp because I thought that it was due to generator expressions at the beginning...)
Looks like "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}} expands to "-isystem " (note the trailing space). Thus, the system include is passed as '-isystem include/dir', which seems to be ignored by the compiler. A possible solution is to remove the space:
// cotire.cmake:934, inside cotire_add_includes_to_cmd
if (_index GREATER -1)
string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _systemIncludeFlag)
list (APPEND ${_cmdVar} "${_systemIncludeFlag}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}")
else()
list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}")
endif()