Skip to content

Commit

Permalink
ci: update rpath on macos builds and don't force it to install in /usr
Browse files Browse the repository at this point in the history
Signed-off-by: AlexandraTrifan <[email protected]>
  • Loading branch information
AlexandraTrifan committed Oct 22, 2024
1 parent 9f1aa74 commit ff932a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
25 changes: 12 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/Modules)
# build a shared library by default
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")

# setup install location for MacOS frameworks
set(OSX_INSTALL_FRAMEWORKSDIR "/Library/Frameworks" CACHE STRING "Installation directory for frameworks")
option(OSX_FRAMEWORK "Create a OSX_FRAMEWORK" ON)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND OSX_FRAMEWORK)
option(OSX_PACKAGE "Create a OSX package" ON)

set(OSX_INSTALL_FRAMEWORKSDIR "/Library/Frameworks" CACHE STRING "Installation directory for frameworks")
get_filename_component(OSX_INSTALL_FRAMEWORKSDIR "${OSX_INSTALL_FRAMEWORKSDIR}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")

set(CMAKE_MACOSX_RPATH ON)
set(SKIP_INSTALL_ALL ${OSX_PACKAGE})
endif()

# generate docs by default
option(ENABLE_DOC "Generate documentation with Doxygen" OFF)
Expand Down Expand Up @@ -123,7 +131,7 @@ configure_file(${CMAKE_SOURCE_DIR}/version.hpp.cmakein ${CMAKE_BINARY_DIR}/${CMA
configure_file(${CMAKE_SOURCE_DIR}/cmake/libm2kConfig.cmake ${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake @ONLY)

# Set the default install path to /usr
if (NOT WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if (NOT APPLE AND NOT WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "default install path" FORCE)
endif()

Expand All @@ -142,17 +150,8 @@ set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CACHE PATH "Installation directory for pkgconfig (.pc) files")
mark_as_advanced(INSTALL_PKGCONFIG_DIR)

# handle RPATH issues on OS X
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
endif()
add_definitions(-D_DARWIN_C_SOURCE)
endif()

if (NOT CMAKE_BUILD_TYPE)
Expand Down
18 changes: 9 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

cmake_minimum_required(VERSION 3.1.3)

option(OSX_PACKAGE "Create OSX package" OFF)
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")

if(APPLE)
Expand Down Expand Up @@ -129,23 +128,24 @@ endif()

#Take care of the library properties
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION}
FRAMEWORK ${OSX_FRAMEWORK}
)

if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME libm2k)
endif()

option(OSX_FRAMEWORK "Create a OSX_FRAMEWORK" ON)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND OSX_FRAMEWORK)
option(OSX_PACKAGE "Create a OSX package" ON)

set(OSX_INSTALL_FRAMEWORKSDIR "/Library/Frameworks" CACHE STRING "Installation directory for frameworks")
get_filename_component(OSX_INSTALL_FRAMEWORKSDIR "${OSX_INSTALL_FRAMEWORKSDIR}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")

if (APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES FRAMEWORK FALSE)
set(CMAKE_MACOSX_RPATH ON)
if (OSX_PACKAGE)
set_target_properties(${PROJECT_NAME} PROPERTIES FRAMEWORK TRUE)
get_filename_component(OSX_INSTALL_FRAMEWORKSDIR "${OSX_INSTALL_FRAMEWORKSDIR}" REALPATH BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(SKIP_INSTALL_ALL ${OSX_PACKAGE})
endif()
set(SKIP_INSTALL_ALL ${OSX_PACKAGE})
endif()

install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets
Expand Down

0 comments on commit ff932a4

Please sign in to comment.