cmake: fix -framework dependencies (fixes #8045)
This commit is contained in:
parent
80390dd987
commit
5cbc8f866c
|
@ -502,6 +502,20 @@ class ConverterTarget:
|
|||
self.link_libraries = [x for x in self.link_libraries if x.lower() not in blacklist_link_libs]
|
||||
self.link_flags = [x for x in self.link_flags if check_flag(x)]
|
||||
|
||||
# Handle OSX frameworks
|
||||
def handle_frameworks(flags: T.List[str]) -> T.List[str]:
|
||||
res: T.List[str] = []
|
||||
for i in flags:
|
||||
p = Path(i)
|
||||
if not p.exists() or not p.name.endswith('.framework'):
|
||||
res += [i]
|
||||
continue
|
||||
res += ['-framework', p.stem]
|
||||
return res
|
||||
|
||||
self.link_libraries = handle_frameworks(self.link_libraries)
|
||||
self.link_flags = handle_frameworks(self.link_flags)
|
||||
|
||||
# Handle explicit CMake add_dependency() calls
|
||||
for i in self.depends_raw:
|
||||
dep_tgt = output_target_map.target(i)
|
||||
|
|
|
@ -23,6 +23,16 @@ target_link_libraries(cmModLib ZLIB::ZLIB)
|
|||
target_link_libraries(cmModLibStatic ;ZLIB::ZLIB;)
|
||||
target_link_libraries(testEXE cmModLib)
|
||||
|
||||
if(APPLE)
|
||||
find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
|
||||
if(NOT COREFOUNDATION_FRAMEWORK)
|
||||
message(FATAL_ERROR "CoreFoundation framework not found")
|
||||
endif()
|
||||
|
||||
target_link_libraries(cmModLibStatic "${COREFOUNDATION_FRAMEWORK}")
|
||||
target_compile_definitions(cmModLibStatic PUBLIC USE_FRAMEWORK)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(cmModLibStatic PUBLIC CMMODLIB_STATIC_DEFINE)
|
||||
|
||||
install(TARGETS testEXE LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
|
||||
|
|
|
@ -6,10 +6,19 @@
|
|||
#error "Invalid value of CONFIG_OPT"
|
||||
#endif
|
||||
|
||||
#ifdef USE_FRAMEWORK
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
cmModClass::cmModClass(string foo) {
|
||||
str = foo + " World " + zlibVersion();
|
||||
|
||||
#ifdef USE_FRAMEWORK
|
||||
CFStringRef ref = CFStringCreateWithCString(NULL, str.c_str(), kCFStringEncodingUTF8);
|
||||
CFRelease(ref);
|
||||
#endif
|
||||
}
|
||||
|
||||
string cmModClass::getStr() const {
|
||||
|
|
Loading…
Reference in New Issue