Skip to content

Commit bc468a6

Browse files
committed
[build] Use appropriate CMake to link against MacOS framework
The previous logic to link against MacOS frameworks was just passing the string "-framework <NAME>". This bypasses the CMake find_library logic, in particular it disregards CMake variables such as CMAKE_OSX_SYSROOT, CMAKE_FIND_ROOT_PATH, CMAKE_FRAMEWORK_PATH etc. Switch to the standard find_library function to find the framework and then use the result as a library target, thus benefiting from this logic described in the CMake documentation: ``` If the library found is a framework, then <VAR> will be set to the full path to the framework <fullPath>/A.framework. When a full path to a framework is used as a library, CMake will use a -framework A, and a -F<fullPath> to link the framework to the target. ```
1 parent abcfb95 commit bc468a6

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

core/macosx/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ if(NOT APPLE)
1212
return()
1313
endif()
1414

15+
find_library(CORESYMBOLICATION_FRAMEWORK CoreSymbolication PATHS "${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks" REQUIRED)
1516
target_link_libraries(Core PRIVATE
16-
"-F/System/Library/PrivateFrameworks -framework CoreSymbolication"
17+
${CORESYMBOLICATION_FRAMEWORK}
1718
)
1819

1920
if(cocoa)
2021
set_property(TARGET Core APPEND PROPERTY DICT_HEADERS TMacOSXSystem.h)
2122

2223
target_include_directories(Core PRIVATE inc)
2324

24-
target_link_libraries(Core PRIVATE "-framework Cocoa")
25+
find_library(COCOA_FRAMEWORK Cocoa REQUIRED)
26+
target_link_libraries(Core PRIVATE ${COCOA_FRAMEWORK})
2527

2628
ROOT_OBJECT_LIBRARY(Macosx
2729
src/CocoaUtils.mm

graf2d/cocoa/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# @author Pere Mato, CERN
1010
############################################################################
1111

12+
find_library(COCOA_FRAMEWORK Cocoa REQUIRED)
13+
find_library(OPENGL_FRAMEWORK OpenGL REQUIRED)
14+
1215
ROOT_STANDARD_LIBRARY_PACKAGE(GCocoa
1316
HEADERS
1417
TGCocoa.h
@@ -36,8 +39,8 @@ ROOT_STANDARD_LIBRARY_PACKAGE(GCocoa
3639
Gui
3740
LIBRARIES
3841
GQuartz
39-
"-framework Cocoa"
40-
"-framework OpenGL"
42+
${COCOA_FRAMEWORK}
43+
${OPENGL_FRAMEWORK}
4144
${FREETYPE_LIBRARIES}
4245
)
4346

graf2d/quartz/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
add_definitions("-ObjC++")
1313

14+
find_library(COCOA_FRAMEWORK Cocoa REQUIRED)
15+
1416
# Dictionary not needed.
1517
ROOT_LINKER_LIBRARY(GQuartz
1618
src/QuartzFillArea.mm
@@ -19,7 +21,7 @@ ROOT_LINKER_LIBRARY(GQuartz
1921
src/QuartzText.mm
2022
src/QuartzUtils.mm
2123
LIBRARIES
22-
"-framework Cocoa"
24+
${COCOA_FRAMEWORK}
2325
DEPENDENCIES
2426
Core
2527
MathCore

gui/cefdisplay/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ if(ROOT_ARCHITECTURE MATCHES macosx)
2323
set(CEF_platform src/gui_handler_mac.mm)
2424
set(CEF_RELEASE_DIR ${CEF_root}/Release/Chromium\ Embedded\ Framework.framework)
2525
set(CEF_LIBRARY ${CEF_RELEASE_DIR}/Chromium\ Embedded\ Framework)
26-
set(CEF_LIB_DEPENDENCY "-framework Foundation")
26+
find_library(FOUNDATION_FRAMEWORK Foundation REQUIRED)
27+
set(CEF_LIB_DEPENDENCY ${FOUNDATION_FRAMEWORK})
2728
set(CEF_DLL_WRAPPER ${CEF_root}/build/libcef_dll_wrapper/libcef_dll_wrapper.a)
2829
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Frameworks/Chromium\ Embedded\ Framework.framework)
2930
file(COPY ${CEF_RELEASE_DIR} DESTINATION ${CMAKE_BINARY_DIR}/Frameworks/)

0 commit comments

Comments
 (0)