Skip to content

Commit 3ec4e5c

Browse files
authored
Merge pull request #404 from systemcrash/cmake
make: improve make (install) on macOS
2 parents 0cde6c7 + 7424c3b commit 3ec4e5c

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,35 @@ set(CLI_SOURCES main.c)
170170
add_executable(ucode ${CLI_SOURCES})
171171
target_link_libraries(ucode uc_defines libucode)
172172

173+
# Ensure rpath is used on macOS
174+
set(CMAKE_MACOSX_RPATH ON)
175+
176+
# Automatically include linked library paths in rpath
177+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
178+
179+
if(APPLE)
180+
set_target_properties(libucode PROPERTIES
181+
INSTALL_NAME_DIR "@rpath"
182+
)
183+
set_target_properties(ucode PROPERTIES
184+
INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}"
185+
)
186+
endif()
187+
188+
if(APPLE AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
189+
execute_process(
190+
COMMAND brew --prefix
191+
OUTPUT_VARIABLE HOMEBREW_PREFIX
192+
OUTPUT_STRIP_TRAILING_WHITESPACE
193+
ERROR_QUIET
194+
)
195+
196+
if(HOMEBREW_PREFIX AND EXISTS "${HOMEBREW_PREFIX}")
197+
message(STATUS "Using Homebrew prefix: ${HOMEBREW_PREFIX}")
198+
set(CMAKE_INSTALL_PREFIX "${HOMEBREW_PREFIX}" CACHE PATH "Install path" FORCE)
199+
endif()
200+
endif()
201+
173202
check_function_exists(dlopen DLOPEN_FUNCTION_EXISTS)
174203
if(NOT DLOPEN_FUNCTION_EXISTS)
175204
target_link_libraries(libucode dl)

0 commit comments

Comments
 (0)