From 8dbedf8a19def01c4ec42db00e668998ab6158e4 Mon Sep 17 00:00:00 2001 From: nihui Date: Wed, 29 Jun 2022 15:25:18 +0800 Subject: [PATCH] use cmake gnuinstalldirs for install destination (#3968) --- src/CMakeLists.txt | 14 ++++++++------ tools/CMakeLists.txt | 5 ++++- tools/pnnx/src/CMakeLists.txt | 5 +++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 95878bae6..98414d690 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -474,10 +474,12 @@ endif() add_dependencies(ncnn ncnn-generate-spirv) if(NCNN_INSTALL_SDK) + include(GNUInstallDirs) + install(TARGETS ncnn EXPORT ncnn - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(FILES allocator.h @@ -506,11 +508,11 @@ if(NCNN_INSTALL_SDK) ${CMAKE_CURRENT_BINARY_DIR}/layer_shader_type_enum.h ${CMAKE_CURRENT_BINARY_DIR}/layer_type_enum.h ${CMAKE_CURRENT_BINARY_DIR}/platform.h - DESTINATION include/ncnn + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ncnn ) - install(EXPORT ncnn DESTINATION lib/cmake/ncnn) + install(EXPORT ncnn DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ncnn) configure_file(${CMAKE_CURRENT_LIST_DIR}/../cmake/ncnnConfig.cmake.in ncnnConfig.cmake @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ncnnConfig.cmake DESTINATION lib/cmake/ncnn) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ncnnConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ncnn) endif() # add ncnn and generate-spirv to a virtual project group diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 7bcd05904..965046be4 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,8 +1,11 @@ cmake_minimum_required(VERSION 3.1) # for CMAKE_CXX_STANDARD set(CMAKE_CXX_STANDARD 11) + +include(GNUInstallDirs) macro(ncnn_install_tool toolname) - install(TARGETS ${toolname} RUNTIME DESTINATION bin) + install(TARGETS ${toolname} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endmacro() + if(MSVC) # warning C4018: '<': signed/unsigned mismatch # warning C4244: 'argument': conversion from 'uint64_t' to 'const unsigned int', possible loss of data diff --git a/tools/pnnx/src/CMakeLists.txt b/tools/pnnx/src/CMakeLists.txt index fa963b79f..a55e53192 100644 --- a/tools/pnnx/src/CMakeLists.txt +++ b/tools/pnnx/src/CMakeLists.txt @@ -535,9 +535,10 @@ else() endif() set_target_properties(pnnx PROPERTIES MACOSX_RPATH TRUE) -install(TARGETS pnnx RUNTIME DESTINATION bin) +include(GNUInstallDirs) +install(TARGETS pnnx RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if (WIN32) file(GLOB TORCH_DLL "${TORCH_INSTALL_PREFIX}/lib/*.dll") - install(FILES ${TORCH_DLL} DESTINATION bin) + install(FILES ${TORCH_DLL} DESTINATION ${CMAKE_INSTALL_BINDIR}) endif()