From 8cf2e78bd6cdce31e396e14cd710b3a40b3e0b18 Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Tue, 31 Jan 2023 01:19:56 +0000 Subject: [PATCH 1/3] [cmake] Add install library path to rpath This way rpath is correctly set by default, avoiding errors like: `libneko.so.2: cannot open shared object file` when installing to /usr/local/ --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28df7cef..1ddb3a7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,6 +175,8 @@ if (RELOCATABLE) endif() endif() +list(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) + if(UNIX AND NOT APPLE) add_definitions(-DABI_ELF) endif() From 53c000f7652410405413eaa5216d2306914ee573 Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Thu, 30 Mar 2023 03:03:11 +0100 Subject: [PATCH 2/3] [cmake] Don't set LD_LIBRARY_PATH during tests If rpath is set correctly then this is not necessary --- CMakeLists.txt | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ddb3a7f..07652bfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -397,12 +397,9 @@ set_target_properties(libneko if (CMAKE_HOST_WIN32) set(set_neko_env set NEKOPATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set(neko_exec $) -elseif(CMAKE_HOST_APPLE) - set(set_neko_env "") - set(neko_exec DYLD_FALLBACK_LIBRARY_PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} NEKOPATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} $) else() set(set_neko_env "") - set(neko_exec LD_LIBRARY_PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} NEKOPATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} $) + set(neko_exec NEKOPATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} $) endif() file(GLOB compilers_src @@ -783,11 +780,6 @@ if (WITH_NEKOML) COMMAND nekoml WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ) - - set_tests_properties(nekoml - PROPERTIES - ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - ) endif() add_test(NAME nekotools @@ -795,14 +787,6 @@ add_test(NAME nekotools WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ) -if (UNIX AND NOT APPLE) - set_tests_properties(-version test.n nekoc nekotools - PROPERTIES - ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - ) -endif() - - ####################### # debian source packages From 5dd4dbe070e3b6666eb4149da7ff9a8884791d15 Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Thu, 9 May 2024 12:26:45 +0100 Subject: [PATCH 3/3] [cmake] Clean up rpath settings Only build with install path if RELOCATABLE is on, otherwise we can stick to the default build rpath. We were setting these options to their default values: CMAKE_MACOS_RPATH, CMAKE_SKIP_BUILD_RPATH, CMAKE_SKIP_INSTALL_RPATH --- CMakeLists.txt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07652bfa..e2ddfdd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,17 +158,11 @@ endforeach() include(ExternalProject) - -# CMAKE_BUILD_WITH_INSTALL_RPATH should be set to true. -# It is because `nekotools boot` will use the neko in build dir during build. -set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) - if (RELOCATABLE) - # https://cmake.org/Wiki/CMake_RPATH_handling - set(CMAKE_SKIP_BUILD_RPATH FALSE) - set(CMAKE_SKIP_INSTALL_RPATH FALSE) + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + # Set this to true, otherwise the binaries won't be relocatable until after installation: + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) if(APPLE) - set(CMAKE_MACOSX_RPATH TRUE) set(CMAKE_INSTALL_RPATH @executable_path/) elseif(UNIX) set(CMAKE_INSTALL_RPATH \$ORIGIN)