From aafd82fbaccc4e29ab28dde03cd25d8a172b38fa Mon Sep 17 00:00:00 2001 From: AlexandraTrifan Date: Tue, 22 Oct 2024 16:15:37 +0300 Subject: [PATCH] ci: update rpath on macos builds and don't force it to install in /usr Signed-off-by: AlexandraTrifan --- CMakeLists.txt | 25 ++++++++++++++----------- src/CMakeLists.txt | 18 +++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a95205a6..2c6ffaec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,18 @@ 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) option(BUILD_EXAMPLES "Build the default examples" OFF) @@ -123,7 +135,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() @@ -142,17 +154,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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3245fab6..1d1fdda3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,15 +138,15 @@ if (MSVC) endif() -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() -endif() +# if (APPLE) + + # 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() +# endif() install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"