Skip to content

Commit

Permalink
Make install better (#23)
Browse files Browse the repository at this point in the history
* improved install tree
- removed include/comp from install (probably not needed, otherwise should be somewhere else)
-  version file is written by cmake
- lincense,readme is installed as well
- gnuinstalldirs macro used to properly setup the install directories

* make install path independent of version -> this is already in cmake-version.cmake ...
If one wants multiple versions next to each other, there is the install_prefix which should be used for installation (e.g. /usr/local/opt/{foonathan_memory-0.5.9,foonathan_memory-0.61}

Fixes #22.
  • Loading branch information
gabyx authored and foonathan committed Mar 3, 2018
1 parent 7ad958b commit 2fed4a4
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/doc/html
/doc/*.tmp
# Created by .ignore support plugin (hsz.mobi)

build
.vscode
48 changes: 42 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ set(FOONATHAN_MEMORY_VERSION_PATCH 1 CACHE STRING "patch version of memory" FORC
set(FOONATHAN_MEMORY_VERSION "${FOONATHAN_MEMORY_VERSION_MAJOR}.${FOONATHAN_MEMORY_VERSION_MINOR}.${FOONATHAN_MEMORY_VERSION_PATCH}"
CACHE STRING "version of memory" FORCE)


# set a debug postfix
set(CMAKE_DEBUG_POSTFIX "-dbg")

# installation destinations
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE STRING "Install prefix (e.g. /usr/local/)" FORCE)
endif()
if(UNIX)
include(GNUInstallDirs)

set(FOONATHAN_MEMORY_INC_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/foonathan_memory")
set(FOONATHAN_MEMORY_RUNTIME_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
set(FOONATHAN_MEMORY_LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
set(FOONATHAN_MEMORY_ARCHIVE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
set(FOONATHAN_MEMORY_FRAMEWORK_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")

set(FOONATHAN_MEMORY_CMAKE_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/foonathan_memory/cmake")
set(FOONATHAN_MEMORY_ADDITIONAL_FILES_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/foonathan_memory")

set(FOONATHAN_MEMORY_RUNTIME_INSTALL_DIR "bin") # for the nodesize_dbg, just ignore version and the like
set(FOONATHAN_MEMORY_INC_INSTALL_DIR "include/foonathan_memory") # header filestree

elseif(WIN32)
set(FOONATHAN_MEMORY_INC_INSTALL_DIR "include/foonathan_memory")
set(FOONATHAN_MEMORY_RUNTIME_INSTALL_DIR "bin")
set(FOONATHAN_MEMORY_LIBRARY_INSTALL_DIR "bin")
set(FOONATHAN_MEMORY_ARCHIVE_INSTALL_DIR "lib")
set(FOONATHAN_MEMORY_FRAMEWORK_INSTALL_DIR "bin")

set(FOONATHAN_MEMORY_CMAKE_CONFIG_INSTALL_DIR "cmake")
set(FOONATHAN_MEMORY_ADDITIONAL_FILES_INSTALL_DIR "./")
else()
message(FATAL_ERROR "Could not set install folders for this platform!")
endif()

include(cmake/compatibility.cmake)
include(cmake/configuration.cmake)

Expand All @@ -28,10 +64,10 @@ if(FOONATHAN_MEMORY_BUILD_TOOLS)
add_subdirectory(tool)
endif()

# exporting
configure_file(cmake/foonathan_memory-config-version.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/foonathan_memory-config-version.cmake
@ONLY)
# install readme and license
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" "${CMAKE_CURRENT_SOURCE_DIR}/README.md" DESTINATION ${FOONATHAN_MEMORY_ADDITIONAL_FILES_INSTALL_DIR})

install(EXPORT foonathan_memoryTargets DESTINATION ${FOONATHAN_MEMORY_CMAKE_CONFIG_INSTALL_DIR}
FILE foonathan_memory-config.cmake)


install(FILES cmake/foonathan_memory-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/foonathan_memory-config-version.cmake DESTINATION ${main_lib_dest})
install(EXPORT foonathan_memory DESTINATION ${lib_dest})
4 changes: 2 additions & 2 deletions cmake/compatibility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ comp_target_features(_foonathan_memory_comp_runner INTERFACE
PREFIX "FOONATHAN_" NAMESPACE "foonathan_comp"
INCLUDE_PATH ${_foonathan_memory_comp_include_path}
NOFLAGS)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/foonathan DESTINATION include/comp)

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/foonathan DESTINATION "${FOONATHAN_MEMORY_INC_INSTALL_DIR}/comp")
function(_foonathan_use_comp target)
target_compile_options(${target} PUBLIC ${_foonathan_memory_comp_runner_COMP_COMPILE_OPTIONS})
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${_foonathan_memory_comp_include_path}>
$<INSTALL_INTERFACE:include/comp>)
$<INSTALL_INTERFACE:${FOONATHAN_MEMORY_INC_INSTALL_DIR}/comp>)
endfunction()
6 changes: 0 additions & 6 deletions cmake/configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
# defines configuration options
# note: only include it in memory's top-level CMakeLists.txt, after compatibility.cmake

# installation destinations
set(tool_dest "bin") # for the nodesize_dbg, just ignore version and the like
set(include_dest "include/foonathan_memory-${FOONATHAN_MEMORY_VERSION}") # header files
set(main_lib_dest "lib/foonathan_memory-${FOONATHAN_MEMORY_VERSION}") # library config file
set(lib_dest "${main_lib_dest}/${CMAKE_BUILD_TYPE}") # build type dependend files (config_impl.hpp/library file)

# what to build
# examples/tests if toplevel directory (i.e. direct build, not as subdirectory) and hosted
# tools if hosted
Expand Down
20 changes: 0 additions & 20 deletions cmake/foonathan_memory-config-version.cmake.in

This file was deleted.

8 changes: 0 additions & 8 deletions cmake/foonathan_memory-config.cmake

This file was deleted.

29 changes: 22 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,32 @@ _foonathan_use_comp(foonathan_memory)
comp_target_features(foonathan_memory PRIVATE CPP11)
target_include_directories(foonathan_memory PUBLIC $<BUILD_INTERFACE:${FOONATHAN_MEMORY_SOURCE_DIR}/include/> # for client in subdirectory
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> # for generated files in build mode
$<INSTALL_INTERFACE:${include_dest}> # for client in install mode
$<INSTALL_INTERFACE:${lib_dest}> # for generated files in install mdoe
$<INSTALL_INTERFACE:${FOONATHAN_MEMORY_INC_INSTALL_DIR}> # for client in install mode
PRIVATE ${header_path}) # for source files
target_compile_definitions(foonathan_memory PUBLIC
FOONATHAN_MEMORY=1
FOONATHAN_MEMORY_VERSION_MAJOR=${FOONATHAN_MEMORY_VERSION_MAJOR}
FOONATHAN_MEMORY_VERSION_MINOR=${FOONATHAN_MEMORY_VERSION_MINOR}
FOONATHAN_MEMORY_VERSION_PATCH=${FOONATHAN_MEMORY_VERSION_PATCH})

# installation
install(TARGETS foonathan_memory EXPORT foonathan_memory DESTINATION ${lib_dest})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config_impl.hpp DESTINATION ${lib_dest})
install(FILES ${header} DESTINATION ${include_dest}/foonathan/memory)
install(FILES ${detail_header} DESTINATION ${include_dest}/foonathan/memory/detail)
set_target_properties(foonathan_memory PROPERTIES
OUTPUT_NAME "foonathan_memory-${FOONATHAN_MEMORY_VERSION}")

install(TARGETS foonathan_memory EXPORT foonathan_memoryTargets
RUNTIME DESTINATION ${FOONATHAN_MEMORY_RUNTIME_INSTALL_DIR}
LIBRARY DESTINATION ${FOONATHAN_MEMORY_LIBRARY_INSTALL_DIR}
ARCHIVE DESTINATION ${FOONATHAN_MEMORY_ARCHIVE_INSTALL_DIR}
FRAMEWORK DESTINATION ${FOONATHAN_MEMORY_FRAMEWORK_INSTALL_DIR})

# Write/install version file
include(CMakePackageConfigHelpers)
set(version_file "${CMAKE_CURRENT_BINARY_DIR}/cmake/foonathan_memory-version.cmake")
write_basic_package_version_file(${version_file}
VERSION ${FOONATHAN_MEMORY_VERSION}
COMPATIBILITY AnyNewerVersion)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config_impl.hpp DESTINATION ${FOONATHAN_MEMORY_INC_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/container_node_sizes_impl.hpp DESTINATION ${FOONATHAN_MEMORY_INC_INSTALL_DIR}/foonathan/memory/detail)
install(FILES ${header} DESTINATION ${FOONATHAN_MEMORY_INC_INSTALL_DIR}/foonathan/memory)
install(FILES ${detail_header} DESTINATION ${FOONATHAN_MEMORY_INC_INSTALL_DIR}/foonathan/memory/detail)
install(FILES ${version_file} DESTINATION ${FOONATHAN_MEMORY_CMAKE_CONFIG_INSTALL_DIR})
3 changes: 2 additions & 1 deletion tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ target_compile_definitions(foonathan_memory_node_size_debugger PUBLIC
VERSION="${FOONATHAN_MEMORY_VERSION_MAJOR}.${FOONATHAN_MEMORY_VERSION_MINOR}")
set_target_properties(foonathan_memory_node_size_debugger PROPERTIES OUTPUT_NAME nodesize_dbg)

install(TARGETS foonathan_memory_node_size_debugger EXPORT foonathan_memory DESTINATION ${tool_dest})
install(TARGETS foonathan_memory_node_size_debugger EXPORT foonathan_memoryTargets
RUNTIME DESTINATION ${FOONATHAN_MEMORY_RUNTIME_INSTALL_DIR})

0 comments on commit 2fed4a4

Please sign in to comment.