Xcode: Installed framework targets are not linked when a library target links to it
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 myfoofunc(){}
foo.cpp
#include <iostream>
#include "foo.h"
void myfoofunc(){std::cout << "hi" << std::endl;}
After installing foo
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(Foo_DIR <path-to-where-foo-is-installed>)
find_package(Foo REQUIRED)
add_library(Bar bar.cpp bar.h)
target_link_libraries(Bar Foo)
bar.h
void mybarfunc(){}
bar.cpp
#include "bar.h"
#include "Foo/foo.h"
void mybarfunc(){myfoofunc();}
After we do mkdir build && cd build && cmake -G Xcode .. && cmake --build .
, we will see error fatal error: 'Foo/Foo.h' file not found
, and this is because the compilation command is missing a -F<path-to-where-foo-is-installed>
, or even more precise, a -iframework <path-to-where-foo-is-installed>
. Note that if Bar
is add_executable
instead of add_library
, it compiles. If we take the exact same code and generate a make
project instead of a Xcode project, it also compiles. For some reason, the combination of generating Xcode project + upstream being an installed framework target + downstream being a library target, triggers this error. Can we please fix this?
This error is reproducible in CMake 3.25.2.