Skip to content

Commit

Permalink
BLD: Make CMake install improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
threecgreen committed Jul 10, 2024
1 parent 11aca9c commit de47c72
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.20.1 - TBD

#### Enhancements
- Improved installation with `CMake`: license is now installed, transitive dependencies are configured
when importing package

## 0.20.0 - 2024-07-09

This release adds support for encoding DBN within the C++ client.
Expand Down
53 changes: 36 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ set(targets ${PROJECT_NAME})
if(NOT ${PROJECT_NAME_UPPERCASE}_USE_EXTERNAL_JSON)
list(APPEND targets nlohmann_json)
endif()
if(NOT ${PROJECT_NAME_UPPERCASE}_USE_EXTERNAL_HTTPLIB)
list(APPEND targets httplib)
endif()

include(GNUInstallDirs)
install(
Expand All @@ -303,16 +306,9 @@ install(
ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION
include
${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION
include
)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp
DESTINATION
include/${PROJECT_NAME}
${CMAKE_INSTALL_INCLUDEDIR}
)

install(
Expand All @@ -330,17 +326,33 @@ install(
# Install the `include` directory
#

set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
install(
DIRECTORY
include/${PROJECT_NAME}
DESTINATION
include
${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp
DESTINATION
${INCLUDE_INSTALL_DIR}
)

verbose_message("Install targets successfully built. Install with `cmake --build <build_directory> --target install --config <build_config>`.")
#
# Install license
#

install(
FILES
"LICENSE"
DESTINATION
${CMAKE_INSTALL_DATADIR}/licenses/${PROJECT_NAME}
)

#
# Quick `ConfigVersion.cmake` creation
# `ConfigVersion.cmake` creation
#

include(CMakePackageConfigHelpers)
Expand All @@ -349,24 +361,31 @@ write_basic_package_version_file(
VERSION
${PROJECT_VERSION}
COMPATIBILITY
SameMajorVersion
SameMinorVersion
)

#
# Generate package configuration and install it
#

configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
PATH_VARS INCLUDE_INSTALL_DIR
)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
# Install so it can be used in databentoConfig.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindZstd.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

verbose_message("Install targets successfully built. Install with `cmake --build <build_directory> --target install --config <build_config>`.")

#
# Generate export header if specified
#
Expand All @@ -378,7 +397,7 @@ if(${PROJECT_NAME_UPPERCASE}_GENERATE_EXPORT_HEADER)
FILES
${PROJECT_BINARY_DIR}/${PROJECT_NAME}_export.h
DESTINATION
include
${CMAKE_INSTALL_INCLUDEDIR}
)

message(STATUS "Generated the export header `${PROJECT_NAME}_export.h` and installed it.")
Expand Down
11 changes: 10 additions & 1 deletion cmake/databentoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ set(@PROJECT_NAME@_VERSION @PROJECT_VERSION@)

@PACKAGE_INIT@

set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
# Reuse FindZstd
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

# Add dependencies here so end-user doesn't have to
include(CMakeFindDependencyMacro)
find_dependency(date)
find_dependency(httplib)
find_dependency(nlohmann_json)
find_dependency(Threads)
find_dependency(Zstd)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@ add_compile_definitions(TEST_BUILD_DIR="${CMAKE_CURRENT_BINARY_DIR}")
verbose_message("Finished adding unit tests for ${CMAKE_PROJECT_NAME}.")

add_subdirectory(cmake_fetch_content)
add_subdirectory(cmake_import)
38 changes: 38 additions & 0 deletions test/cmake_import/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Install locally
add_test(
NAME cmake_import_install
COMMAND
${CMAKE_COMMAND}
--install ${CMAKE_BINARY_DIR}
--prefix ${CMAKE_CURRENT_BINARY_DIR}/pkg
)
# Configure test project
add_test(
NAME cmake_import_configure
COMMAND
${CMAKE_COMMAND}
-G "${CMAKE_GENERATOR}"
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-Ddatabento_DIR=${CMAKE_CURRENT_BINARY_DIR}/pkg/lib/cmake/databento
-Dnlohmann_json_DIR=${nlohmann_json_BINARY_DIR}
-Ddate_DIR=${CMAKE_CURRENT_BINARY_DIR}/pkg/lib/cmake/date
-Dhttplib_DIR=${CMAKE_CURRENT_BINARY_DIR}/pkg/lib/cmake/httplib
${CMAKE_CURRENT_SOURCE_DIR}/project
)
# Build test project
add_test(
NAME cmake_import_build
COMMAND ${CMAKE_COMMAND} --build .
)
set_tests_properties(
cmake_import_install
PROPERTIES FIXTURES_SETUP cmake_import
)
set_tests_properties(
cmake_import_configure
PROPERTIES FIXTURES_SETUP cmake_import
)
set_tests_properties(
cmake_import_build
PROPERTIES FIXTURES_REQUIRED cmake_import
)
8 changes: 8 additions & 0 deletions test/cmake_import/project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.14)

project(DummyImport LANGUAGES CXX)

find_package(databento REQUIRED)

add_executable(dummy main.cpp)
target_link_libraries(dummy databento::databento)
8 changes: 8 additions & 0 deletions test/cmake_import/project/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <databento/record.hpp>

int main(int argc, char** argv) {
databento::RecordHeader header{};
std::cout << header.Size() << '\n';

return 0;
}

0 comments on commit de47c72

Please sign in to comment.