Skip to content

Commit

Permalink
link correctly on darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed Nov 25, 2024
1 parent 6eca93b commit 278604f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 18 additions & 0 deletions cmake/DarwinBuild.cmake
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 3 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
1 change: 1 addition & 0 deletions test/DumpPayloads/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions test/X86Functions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 278604f

Please sign in to comment.