Inherited COMPILE_OPTION "-include foo.h" is mutilated
Consider the following example using the "Unix Makefiles" generator and Gcc and cmake 3.8.2.
# CMakeLists.txt
cmake_minimum_required (VERSION 3.8.2)
project(CMakeBug)
set(CMAKE_VERBOSE_MAKEFILE ON)
if( (NOT ${CMAKE_GENERATOR} MATCHES "Unix Makefiles") AND ( NOT CMAKE_COMPILER_IS_GNUCXX ))
message(FATAL_ERROR "Example requires gcc and \"Unix Makefiles\"" )
endif()
add_library( libFoo INTERFACE )
target_compile_options( libFoo INTERFACE -include "${CMAKE_CURRENT_SOURCE_DIR}/foo.h" )
add_executable( bar main.cpp bar.h)
target_compile_options( bar PRIVATE -include "${CMAKE_CURRENT_SOURCE_DIR}/bar.h" )
target_link_libraries( bar PUBLIC libFoo )
during compilation it produces the error:
/usr/bin/c++ -include "/home/knitschi/CppLibraries/CMakeIssue unknown/bar.h" "/home/knitschi/CppLibraries/CMakeIssue unknown/foo.h" -o CMakeFiles/bar.dir/main.cpp.o -c "/home/knitschi/CppLibraries/CMakeIssue unknown/main.cpp"
c++: fatal error: cannot specify -o with -c, -S or -E with multiple files
compilation terminated.
The second -include
from the inherited options seems to be removed by cmake.
Edited by Knitschi