From 278604f8ec25f51e6a4f37fde87a2bec0fa64549 Mon Sep 17 00:00:00 2001 From: Markus Schmidl Date: Mon, 25 Nov 2024 12:25:07 +0100 Subject: [PATCH] link correctly on darwin --- CMakeLists.txt | 2 ++ cmake/DarwinBuild.cmake | 18 ++++++++++++++++++ src/CMakeLists.txt | 15 +++------------ test/DumpPayloads/CMakeLists.txt | 1 + test/X86Functions/CMakeLists.txt | 1 + 5 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 cmake/DarwinBuild.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f08b844c..db358cf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ endif() include(cmake/GitSubmoduleUpdate.cmake) git_submodule_update() +include(cmake/DarwinBuild.cmake) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") else() SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O2 -fdata-sections -ffunction-sections") diff --git a/cmake/DarwinBuild.cmake b/cmake/DarwinBuild.cmake new file mode 100644 index 00000000..9519a6de --- /dev/null +++ b/cmake/DarwinBuild.cmake @@ -0,0 +1,18 @@ +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + find_library( COREFOUNDATION_LIBRARY CoreFoundation ) + find_library( IOKIT_LIBRARY IOKit ) +endif() + +# Function to link against the correct libraries on darwin +function(target_link_libraries_darwin) + set(oneValueArgs NAME) + cmake_parse_arguments(TARGET "" "${oneValueArgs}" + "" ${ARGN} ) + + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_link_libraries(${TARGET_NAME} + ${COREFOUNDATION_LIBRARY} + ${IOKIT_LIBRARY} + ) + endif() +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5db9d285..2e37fd21 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,6 @@ target_link_libraries(firestartercore nlohmann_json::nlohmann_json ) - # Create the linux firestarter library that is used for specific linux only features if(CMAKE_SYSTEM_NAME STREQUAL "Linux") add_library(firestarterlinux STATIC @@ -209,6 +208,8 @@ elseif(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER") ) endif() + target_link_libraries_darwin(NAME FIRESTARTER) + # static linking is not supported on Darwin, see Apple Technical QA1118 if((NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") AND FIRESTARTER_LINK_STATIC) target_link_libraries(FIRESTARTER @@ -236,14 +237,4 @@ elseif(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER") Threads::Threads ) endif() - - # static linking is not supported on Darwin, see Apple Technical QA1118 - if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - find_library( COREFOUNDATION_LIBRARY CoreFoundation ) - find_library( IOKIT_LIBRARY IOKit ) - target_link_libraries(FIRESTARTER - ${COREFOUNDATION_LIBRARY} - ${IOKIT_LIBRARY} - ) - endif() -endif() +endif() \ No newline at end of file diff --git a/test/DumpPayloads/CMakeLists.txt b/test/DumpPayloads/CMakeLists.txt index c42fd887..6ebd81f8 100644 --- a/test/DumpPayloads/CMakeLists.txt +++ b/test/DumpPayloads/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(DumpPayloads Main.cpp) target_link_libraries(DumpPayloads firestartercore) +target_link_libraries_darwin(NAME DumpPayloads) add_ref_test(NAME DumpPayloads) \ No newline at end of file diff --git a/test/X86Functions/CMakeLists.txt b/test/X86Functions/CMakeLists.txt index c97e311a..c2a2649b 100644 --- a/test/X86Functions/CMakeLists.txt +++ b/test/X86Functions/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(X86Functions Main.cpp) target_link_libraries(X86Functions firestartercore) +target_link_libraries_darwin(NAME X86Functions) add_ref_test(NAME X86Functions) \ No newline at end of file