Skip to content

Commit

Permalink
CMake: Fix linker issues on Windows and macOS
Browse files Browse the repository at this point in the history
- Windows: set `IMPORT_IMPLIB` property for `ida.lib`
- macOS: Use classic linker instead of `ld_prime` to work around assertion
  failure with LTO symbols (see [release notes](https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking)). This addresses #31.
- Drive-by: quote more variables in `cmake/Util.cmake`

PiperOrigin-RevId: 599807653
Change-Id: I84baf3da410bda0bc0eaa4f47d4ff30485ea6061
  • Loading branch information
cblichmann authored and copybara-github committed Jan 19, 2024
1 parent 93a545e commit 11e8e69
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
7 changes: 6 additions & 1 deletion cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ if(UNIX)
add_compile_options(-Wno-deprecated)
if(APPLE)
add_compile_options(-gfull)
add_link_options(-dead_strip)
add_link_options(
-dead_strip
# Work around assertion failure with LTO symbols
# https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking
LINKER:-ld_classic
)

# Suppress ranlib warnings "file has no symbols"
set(CMAKE_C_ARCHIVE_CREATE
Expand Down
2 changes: 2 additions & 0 deletions cmake/FindIdaSdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ elseif(WIN32)
)
add_library(ida64 SHARED IMPORTED)
set_target_properties(ida64 PROPERTIES IMPORTED_LOCATION "${IdaSdk_LIB64}")
set_target_properties(ida64 PROPERTIES IMPORTED_IMPLIB "${IdaSdk_LIB64}")

_ida_get_libpath_suffixes(_ida32_suffixes "x64_win_vc_32")
find_library(IdaSdk_LIB32 ida
Expand All @@ -206,6 +207,7 @@ elseif(WIN32)
)
add_library(ida32 SHARED IMPORTED)
set_target_properties(ida32 PROPERTIES IMPORTED_LOCATION "${IdaSdk_LIB32}")
set_target_properties(ida32 PROPERTIES IMPORTED_IMPLIB "${IdaSdk_LIB32}")
else()
message(FATAL_ERROR "Unsupported system type: ${CMAKE_SYSTEM_NAME}")
endif()
Expand Down
19 changes: 10 additions & 9 deletions cmake/Util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@

function(create_directory_symlink target link_name)
# Make sure parent directory exists
get_filename_component(_parent ${link_name} DIRECTORY)
file(MAKE_DIRECTORY ${_parent})
get_filename_component(_parent "${link_name}" DIRECTORY)
file(MAKE_DIRECTORY "${_parent}")

# Windows needs native paths. No-op on other systems.
file(TO_NATIVE_PATH ${target} _target)
file(TO_NATIVE_PATH ${link_name} _link_name)
file(TO_NATIVE_PATH "${target}" _target)
file(TO_NATIVE_PATH "${link_name}" _link_name)
if(WIN32)
# Fake directory symlinks by using junctions. While NTFS historically has
# always supported symlinks, nowadays they either require Windows 10 with
# Dev mode enabled or administrative privileges. The CI build hosts for
# BinExport have neither. Junctions always work for unprivileged users.
set(_cmd $ENV{ComSpec} /c mklink /J ${_link_name} ${_target}
# always supported symlinks, nowadays they either require Windows 10 or
# higher with Dev mode enabled or administrative privileges. The CI build
# hosts for BinExport have neither. Junctions always work for
# unprivileged users.
set(_cmd $ENV{ComSpec} /c mklink /J "${_link_name}" "${_target}"
ERROR_QUIET)
else()
set(_cmd ${CMAKE_COMMAND} -E create_symlink ${_target} ${_link_name})
set(_cmd ${CMAKE_COMMAND} -E create_symlink "${_target}" "${_link_name}")
endif()
execute_process(COMMAND ${_cmd})
endfunction()

0 comments on commit 11e8e69

Please sign in to comment.