Skip to content

Commit

Permalink
Added Cmake commands to install byteme for find_package. (#1)
Browse files Browse the repository at this point in the history
Also added an action to check for correct installation.
  • Loading branch information
LTLA authored Aug 5, 2023
1 parent 2486b63 commit 889c7be
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/check-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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: Install byteme
run: |
git clone https://github.com/LTLA/byteme dep-byteme --depth=1
cd dep-byteme
cmake -S . -B build
sudo cmake --install build
- 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(tatami_eminem)
target_link_libraries(whee tatami::eminem)
EOF
cd _downstream && cmake -S . -B build
42 changes: 38 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,59 @@ project(eminem
set(CMAKE_CXX_STANDARD 17)

add_library(eminem INTERFACE)
add_library(tatami::eminem ALIAS eminem)

add_subdirectory(extern)
option(EMINEM_FETCH_EXTERN "Automatically fetch eminem's external dependencies." ON)
if(EMINEM_FETCH_EXTERN)
add_subdirectory(extern)
else()
find_package(ltla_byteme CONFIG REQUIRED)
endif()

target_link_libraries(eminem INTERFACE byteme)
target_link_libraries(eminem INTERFACE ltla::byteme)

# Switch between include directories depending on whether the downstream is
# using the build directly or is using the installed package.
include(GNUInstallDirs)
target_include_directories(eminem
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/eminem>"
)

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

if(EMINEM_TESTS)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
add_subdirectory(perf)
endif()

# Installing for find_package.
include(CMakePackageConfigHelpers)

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

install(TARGETS eminem
EXPORT eminemTargets)

install(EXPORT eminemTargets
FILE tatami_eminemTargets.cmake
NAMESPACE tatami::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tatami_eminem)

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

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tatami_eminemConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tatami_eminem)

6 changes: 6 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(ltla_byteme CONFIG REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/tatami_eminemTargets.cmake")
2 changes: 1 addition & 1 deletion extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(FetchContent)
FetchContent_Declare(
byteme
GIT_REPOSITORY https://github.com/LTLA/byteme
GIT_TAG 1baca1ffddfbf0cd71fa7e285554959e3a116911
GIT_TAG master
)

FetchContent_MakeAvailable(byteme)
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)
Expand Down

0 comments on commit 889c7be

Please sign in to comment.