From ff932a4437756810acb56445e33112f78181d4d5 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, 21 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a95205a6..d7514749 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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() @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3245fab6..51bcee01 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) @@ -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