Skip to content

Commit

Permalink
[cmake] Fix libneko.so loading error when installing to /usr/local (#…
Browse files Browse the repository at this point in the history
…271)

* [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/

* [cmake] Don't set LD_LIBRARY_PATH during tests

If rpath is set correctly then this is not necessary

* [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
  • Loading branch information
tobil4sk authored May 9, 2024
1 parent 90c8195 commit 7fbf5d6
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,19 @@ 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)
endif()
endif()

list(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})

if(UNIX AND NOT APPLE)
add_definitions(-DABI_ELF)
endif()
Expand Down Expand Up @@ -395,12 +391,9 @@ set_target_properties(libneko
if (CMAKE_HOST_WIN32)
set(set_neko_env set NEKOPATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(neko_exec $<TARGET_FILE:nekovm>)
elseif(CMAKE_HOST_APPLE)
set(set_neko_env "")
set(neko_exec DYLD_FALLBACK_LIBRARY_PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} NEKOPATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} $<TARGET_FILE:nekovm>)
else()
set(set_neko_env "")
set(neko_exec LD_LIBRARY_PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} NEKOPATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} $<TARGET_FILE:nekovm>)
set(neko_exec NEKOPATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} $<TARGET_FILE:nekovm>)
endif()

file(GLOB compilers_src
Expand Down Expand Up @@ -781,26 +774,13 @@ 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
COMMAND 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
Expand Down

0 comments on commit 7fbf5d6

Please sign in to comment.