Framework headers are not being treated as `-isystem` when linking to installed framework targets
Please see below minimal example to reproduce the problem,
Upstream framework project:
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(upstream)
add_library(Foo foo.cpp foo.h)
set_target_properties(Foo PROPERTIES FRAMEWORK TRUE PUBLIC_HEADER "foo.h")
install(
TARGETS Foo
EXPORT FooTargets
FRAMEWORK DESTINATION .)
file(WRITE ${CMAKE_BINARY_DIR}/FooConfig.cmake
"include(CMakeFindDependencyMacro)\n"
"include(\$(CMAKE_CURRENT_LIST_DIR)/FooTargets.cmake)\n")
install(FILES ${CMAKE_BINARY_DIR}/FooConfig.cmake DESTINATION lib/cmake/Foo)
install(EXPORT FooTargets DESTINATION lib/cmake/Foo)
foo.h
void myfunc(){
int a;
}
After installing it via mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=<path-to-where-we-want-to-install-foo> .. && make install
Downstream project:
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(downstream)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra")
set(Foo_DIR <path-to-where-foo-is-installed>)
find_package(Foo REQUIRED)
add_executable(sample main.cpp)
target_link_libraries(sample Foo)
main.cpp
#include <Foo/foo.h>
int main(){return 0;}
After we do mkdir build && cd build && cmake .. && make
, we see error error: unused variable 'a' [-Werror, -Wunused-variable]
, because CMake does not treat installed framework headers as -isystem
headers. However, if upstream isn't a framework and is a normal library, e.g.
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(upstream)
add_library(Foo foo.cpp foo.h)
target_include_directories(Foo PUBLIC $<INSTALL_INTERFACE:include>)
install(FILES foo.h DESTINATION include/Foo)
install(
TARGETS Foo
EXPORT FooTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR})
file(WRITE ${CMAKE_BINARY_DIR}/FooConfig.cmake
"include(CMakeFindDependencyMacro)\n"
"include(\$(CMAKE_CURRENT_LIST_DIR)/FooTargets.cmake)\n")
install(FILES ${CMAKE_BINARY_DIR}/FooConfig.cmake DESTINATION lib/cmake/Foo)
install(EXPORT FooTargets DESTINATION lib/cmake/Foo)
and downstream is exactly the same, after we do mkdir build && cd build && cmake .. && make
the downstream will compile successfully because CMake correctly treats installed headers as -isystem
headers.
Can we fix it so that cmake also treats installed framework headers as -isystem
headers? We cannot control how strict third party frameworks write their code, and we want to be able to link to third party frameworks while enabling -Wall -Werror -Wextra
for our own project.