From e2c095fad2a1d506712be0b22616f97cc927c05b Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Fri, 21 May 2021 15:15:50 -0700 Subject: [PATCH] fix installation directories on unix to use /lib, /include, /share; fix issues #399, #223, and #89 --- CMakeLists.txt | 35 ++++++++++++++++++++--------------- cmake/mimalloc-config.cmake | 11 ++++++++++- test/CMakeLists.txt | 6 +++--- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3589d83f..ca2ce3e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,11 +208,13 @@ endif() # ----------------------------------------------------------------------------- if (MI_INSTALL_TOPLEVEL) - set(mi_install_dir "") - set(mi_install_libdir "lib") + set(mi_install_libdir "lib") + set(mi_install_incdir "include") + set(mi_install_cmakedir "cmake") else() - set(mi_install_dir "lib/mimalloc-${mi_version}") - set(mi_install_libdir "${mi_install_dir}") + set(mi_install_libdir "lib/mimalloc-${mi_version}") + set(mi_install_incdir "include/mimalloc-${mi_version}") + set(mi_install_cmakedir "share/mimalloc-${mi_version}/cmake") endif() if(MI_SECURE) @@ -246,7 +248,7 @@ if(MI_USE_CXX) else() message(STATUS "Compiler : ${CMAKE_C_COMPILER}") endif() -message(STATUS "Install directory: ${mi_install_dir}") +message(STATUS "Version : ${mi_version}") message(STATUS "Build targets : ${mi_build_targets}") message(STATUS "") @@ -263,7 +265,7 @@ if(MI_BUILD_SHARED) target_link_libraries(mimalloc PUBLIC ${mi_libraries}) target_include_directories(mimalloc PUBLIC $ - $ + $ ) if(WIN32) # On windows copy the mimalloc redirection dll too. @@ -280,7 +282,7 @@ if(MI_BUILD_SHARED) endif() install(TARGETS mimalloc EXPORT mimalloc DESTINATION ${mi_install_libdir} LIBRARY) - install(EXPORT mimalloc DESTINATION ${mi_install_dir}/cmake) + install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir}) endif() # static library @@ -292,7 +294,7 @@ if (MI_BUILD_STATIC) target_link_libraries(mimalloc-static PUBLIC ${mi_libraries}) target_include_directories(mimalloc-static PUBLIC $ - $ + $ ) if(WIN32) # When building both static and shared libraries on Windows, a static library should use a @@ -307,18 +309,21 @@ if (MI_BUILD_STATIC) endif() # install include files -install(FILES include/mimalloc.h DESTINATION ${mi_install_dir}/include) -install(FILES include/mimalloc-override.h DESTINATION ${mi_install_dir}/include) -install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_dir}/include) -install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_dir}/cmake) -install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_dir}/cmake) +install(FILES include/mimalloc.h DESTINATION ${mi_install_incdir}) +install(FILES include/mimalloc-override.h DESTINATION ${mi_install_incdir}) +install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_incdir}) +install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_cmakedir}) +install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_cmakedir}) if(NOT WIN32 AND MI_BUILD_SHARED AND NOT MI_INSTALL_TOPLEVEL) # install a symlink in the /usr/local/lib to the versioned library + # note: use delayed prefix expansion as \${CMAKE_INSTALL_PREFIX} set(mi_symlink "${CMAKE_SHARED_MODULE_PREFIX}${mi_basename}${CMAKE_SHARED_LIBRARY_SUFFIX}") set(mi_soname "mimalloc-${mi_version}/${mi_symlink}.${mi_version}") install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${mi_soname} ${mi_symlink} WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib)") install(CODE "MESSAGE(\"-- Symbolic link: \${CMAKE_INSTALL_PREFIX}/lib/${mi_symlink} -> ${mi_soname}\")") + install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${mi_soname} ${mi_symlink}.${mi_version} WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib)") + install(CODE "MESSAGE(\"-- Symbolic link: \${CMAKE_INSTALL_PREFIX}/lib/${mi_symlink}.${mi_version} -> ${mi_soname}\")") endif() # single object file for more predictable static overriding @@ -329,11 +334,11 @@ if (MI_BUILD_OBJECT) target_compile_options(mimalloc-obj PRIVATE ${mi_cflags}) target_include_directories(mimalloc-obj PUBLIC $ - $ + $ ) # the following seems to lead to cmake warnings/errors on some systems, disable for now :-( - # install(TARGETS mimalloc-obj EXPORT mimalloc DESTINATION ${mi_install_dir}) + # install(TARGETS mimalloc-obj EXPORT mimalloc DESTINATION ${mi_install_libdir}) # the FILES expression can also be: $ # but that fails cmake versions less than 3.10 so we leave it as is for now diff --git a/cmake/mimalloc-config.cmake b/cmake/mimalloc-config.cmake index 12da076e..024c97d9 100644 --- a/cmake/mimalloc-config.cmake +++ b/cmake/mimalloc-config.cmake @@ -1,2 +1,11 @@ include(${CMAKE_CURRENT_LIST_DIR}/mimalloc.cmake) -get_filename_component(MIMALLOC_TARGET_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH) +get_filename_component(MIMALLOC_SHARE_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH) # one up from the cmake dir, e.g. /usr/local/share/mimalloc-2.0 +if (MIMALLOC_SHARE_DIR MATCHES "/share/") + string(REPLACE "/share/" "/lib/" MIMALLOC_LIBRARY_DIR ${MIMALLOC_SHARE_DIR}) + string(REPLACE "/share/" "/include/" MIMALLOC_INCLUDE_DIR ${MIMALLOC_SHARE_DIR}) +else() + # if MI_INSTALL_TOPLEVEL==ON + set(MIMALLOC_LIBRARY_DIR "${MIMALLOC_SHARE_DIR}/lib") + set(MIMALLOC_INCLUDE_DIR "${MIMALLOC_SHARE_DIR}/include") +endif() +set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}") # legacy diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7392d20e..7986d2da 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,7 +14,7 @@ endif() # Import mimalloc (if installed) find_package(mimalloc 1.7 REQUIRED NO_SYSTEM_ENVIRONMENT_PATH) -message(STATUS "Found mimalloc installed at: ${MIMALLOC_TARGET_DIR}") +message(STATUS "Found mimalloc installed at: ${MIMALLOC_LIBRARY_DIR}") # overriding with a dynamic library add_executable(dynamic-override main-override.c) @@ -26,8 +26,8 @@ target_link_libraries(dynamic-override-cxx PUBLIC mimalloc) # overriding with a static object file works reliable as the symbols in the # object file have priority over those in library files -add_executable(static-override-obj main-override.c ${MIMALLOC_TARGET_DIR}/mimalloc.o) -target_include_directories(static-override-obj PUBLIC ${MIMALLOC_TARGET_DIR}/include) +add_executable(static-override-obj main-override.c ${MIMALLOC_LIBRARY_DIR}/mimalloc.o) +target_include_directories(static-override-obj PUBLIC ${MIMALLOC_INCLUDE_DIR}) target_link_libraries(static-override-obj PUBLIC pthread)