Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make ARCH_INDEPENDENT libraries to have CMake configs installed to share #42

Merged
merged 10 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ jobs:
cmake -S test -B build/local
cmake --build build/local
cmake --build build/local --target test
sudo -E cmake --build build/local --target install
cmake --install build/local --prefix ./install_dir

- name: test installed build
run: |
cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1
sudo apt install fzf ripgrep
fzf --walker-root=./install_dir -f "lib /cmake/ /dependencyConfig.cmake" | rg lib | rg cmake | rg Config.cmake
fzf --walker-root=./install_dir -f header_onlyConfig.cmake | rg share/cmake
cmake -S test -B build/installed -DCMAKE_INSTALL_PREFIX=./install_dir -D TEST_INSTALLED_VERSION=1
Arniiiii marked this conversation as resolved.
Show resolved Hide resolved
cmake --build build/installed
cmake --build build/installed --target test

Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/build
/out
/.vs
/.vs
.cache/
compile_commands.json
Arniiiii marked this conversation as resolved.
Show resolved Hide resolved
install_dir/
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ function(packageProject)

if(PROJECT_ARCH_INDEPENDENT)
set(wbpvf_extra_args ARCH_INDEPENDENT)
# install to architecture independent (share) directory
set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_DATADIR})
else()
# if x32 or multilib->x32 , install to (lib) directory. if x64, install to (lib64) directory
set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_LIBDIR})
endif()

write_basic_package_version_file(
Expand All @@ -141,7 +146,7 @@ function(packageProject)
)

set("${PROJECT_NAME}_INSTALL_CMAKEDIR"
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}"
"${INSTALL_DIR_FOR_CMAKE_CONFIGS}/cmake/${PROJECT_NAME}${PROJECT_VERSION_SUFFIX}"
CACHE PATH "CMake package config location relative to the install prefix"
)

Expand Down
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ project(

if(TEST_INSTALLED_VERSION)
find_package(dependency 1.2 REQUIRED)
find_package(header_only 1.0 REQUIRED)
find_package(namespaced_dependency 4.5.6 REQUIRED)
find_package(transitive_dependency 7.8.9 REQUIRED)
else()
if(TEST_CPACK)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Foo Bar <[email protected]>")
endif()
add_subdirectory(dependency)
add_subdirectory(header_only)
add_subdirectory(namespaced_dependency)
add_subdirectory(transitive_dependency)
endif()

add_executable(main main.cpp)

target_link_libraries(
main dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
main dependency header_only ns::namespaced_dependency
transitive_dependency::transitive_dependency
)

enable_testing()
Expand Down
28 changes: 28 additions & 0 deletions test/header_only/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.14...3.22)

project(
header_only
VERSION 1.0
LANGUAGES CXX
DESCRIPTION "A header only dependency for testing PackageProject.cmake"
)

add_library(${PROJECT_NAME} INTERFACE)

target_include_directories(
dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)

packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${PROJECT_NAME}/version.h"
DEPENDENCIES ""
CPACK "${TEST_CPACK}"
)
5 changes: 5 additions & 0 deletions test/header_only/include/header_only/adder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

inline constexpr long add(int a, int b) {
return a + b;
}
8 changes: 8 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <namespaced_dependency/version.h>
#include <transitive_dependency/transitive_dependency.h>
#include <transitive_dependency/version.h>
#include <header_only/adder.h>
#include <header_only/version.h>

#include <string>

Expand All @@ -27,5 +29,11 @@ int main() {
result &= TRANSITIVE_DEPENDENCY_VERSION_MINOR == 8;
result &= TRANSITIVE_DEPENDENCY_VERSION_PATCH == 9;
result &= TRANSITIVE_DEPENDENCY_VERSION_TWEAK == 21948124;
result &= (5 == add(2,3));
result &= HEADER_ONLY_VERSION == std::string("1.0");
result &= HEADER_ONLY_VERSION_MAJOR == 1;
result &= HEADER_ONLY_VERSION_MINOR == 0;
result &= HEADER_ONLY_VERSION_PATCH == 0;
result &= HEADER_ONLY_VERSION_TWEAK == 0;
return result ? 0 : 1;
}
Loading