From cd181b88198e3629bbff32451a04ea0ad53c3956 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Wed, 7 Feb 2024 21:35:01 +0800 Subject: [PATCH] fix cmake install --- CMakeLists.txt | 24 ++++++++++++++++++++++++ src/CMakeLists.txt | 5 ++++- src/apps/CMakeLists.txt | 3 +++ src/base/CMakeLists.txt | 4 ++++ src/sdl/CMakeLists.txt | 4 ++++ src/util/CMakeLists.txt | 3 +++ 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e89d5aa..387fd3da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,30 @@ else () endif () endif () +# rpath +set(CMAKE_MACOSX_RPATH ON) +set(CMAKE_SKIP_BUILD_RPATH OFF) +set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) +set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) + +if (APPLE) + set(CMAKE_INSTALL_RPATH "@loader_path;@loader_path/../bin;@loader_path/../lib") +elseif (UNIX) + set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../bin;$ORIGIN/../lib") +endif () + +if (NOT CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "dist") +endif () + +# set up install directories +include(GNUInstallDirs) +if (NOT WIN32) + # DLLs are installed in the same directory as executables + set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_BINDIR}) +endif () + set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL) set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index db7409c3..3aa7f141 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,6 +56,9 @@ function(luisa_render_add_plugin name) set_target_properties(${lib_name} PROPERTIES UNITY_BUILD OFF DEBUG_POSTFIX "") + install(TARGETS ${lib_name} + LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endfunction() add_subdirectory(films) @@ -74,8 +77,8 @@ add_subdirectory(environments) add_subdirectory(lightsamplers) add_subdirectory(phasefunctions) add_subdirectory(texturemappings) -add_library(luisa-render INTERFACE) +add_library(luisa-render INTERFACE) target_link_libraries(luisa-render INTERFACE luisa-render-ext luisa-render-sdl diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index 62c249bb..7af1b1a8 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -2,6 +2,9 @@ function(luisa_render_add_application name) cmake_parse_arguments(APP "" "" "SOURCES" ${ARGN}) add_executable(${name} ${APP_SOURCES}) target_link_libraries(${name} PRIVATE luisa::render) + install(TARGETS ${name} + LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endfunction() luisa_render_add_application(luisa-render-cli SOURCES cli.cpp) diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index 87977da2..5a41327f 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -30,3 +30,7 @@ target_link_libraries(luisa-render-base PUBLIC set_target_properties(luisa-render-base PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON UNITY_BUILD ${LUISA_RENDER_ENABLE_UNITY_BUILD}) + +install(TARGETS luisa-render-base + LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 61bd4424..3f857eff 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -13,3 +13,7 @@ target_link_libraries(luisa-render-sdl PUBLIC set_target_properties(luisa-render-sdl PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON UNITY_BUILD ${LUISA_RENDER_ENABLE_UNITY_BUILD}) + +install(TARGETS luisa-render-sdl + LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 2e7b1fe0..af055436 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -29,3 +29,6 @@ target_link_libraries(luisa-render-util PUBLIC set_target_properties(luisa-render-util PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON UNITY_BUILD ${LUISA_RENDER_ENABLE_UNITY_BUILD}) +install(TARGETS luisa-render-util + LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})