Skip to content

Commit

Permalink
Added CMake commands to install byteme for find_package. (#3)
Browse files Browse the repository at this point in the history
Also added an action to check that the installation can be used.
  • Loading branch information
LTLA authored Aug 5, 2023
1 parent 761e3c8 commit a1d9597
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/check-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
push:
branches:
- master
pull_request:

name: Check CMake install

jobs:
install:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Get latest CMake
uses: lukka/get-cmake@latest

- name: Configure the build
run: cmake -S . -B build

- name: Install the library
run: sudo cmake --install build

- name: Test downstream usage
run: |
mkdir _downstream
touch _downstream/source.cpp
cat << EOF > _downstream/CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(test_install)
add_executable(whee source.cpp)
find_package(ltla_byteme)
target_link_libraries(whee ltla::byteme)
EOF
cd _downstream && cmake -S . -B build
38 changes: 35 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.24)

project(byteme
VERSION 1.0.0
VERSION 1.0.1
DESCRIPTION "No-frills byte streaming from file"
LANGUAGES CXX)

add_library(byteme INTERFACE)
add_library(ltla::byteme ALIAS byteme)

target_include_directories(byteme INTERFACE include/)
include(GNUInstallDirs)
target_include_directories(byteme INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/byteme>")

# Building the test-related machinery, if we are compiling this library directly.
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
option(BYTEME_TESTS "Build byteme's test suite." ON)
else()
option(BYTEME_TESTS "Build byteme's test suite." OFF)
endif()

if(BYTEME_TESTS)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
endif()

# Installing for find_package.
include(CMakePackageConfigHelpers)

install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/byteme)

install(TARGETS byteme
EXPORT bytemeTargets)

install(EXPORT bytemeTargets
FILE ltla_bytemeTargets.cmake
NAMESPACE ltla::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ltla_byteme)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/ltla_bytemeConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ltla_byteme)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ltla_bytemeConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ltla_byteme)
3 changes: 3 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/ltla_bytemeTargets.cmake")
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ FetchContent_Declare(

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Avoid installing GoogleTest when installing this project.
option(INSTALL_GTEST "Enable installation of googletest." OFF)

FetchContent_MakeAvailable(googletest)

set(CMAKE_CXX_STANDARD 17) # for filesystem headers.
Expand Down

0 comments on commit a1d9597

Please sign in to comment.