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

fix: CMake package and pkgconfig rework #916

Merged
merged 26 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
80356ae
add tests of the CMake package and pkgconfig
phlptp Aug 15, 2023
c3cec5f
style: pre-commit.ci fixes
pre-commit-ci[bot] Aug 15, 2023
bac5352
remove extraneous option
phlptp Aug 15, 2023
bf484d6
style: pre-commit.ci fixes
pre-commit-ci[bot] Aug 15, 2023
6b5dba4
tweak the workflows
phlptp Aug 15, 2023
70f3e84
add in addition find paths
phlptp Aug 15, 2023
0d0c043
style: pre-commit.ci fixes
pre-commit-ci[bot] Aug 15, 2023
1312011
tweak the directory lists
phlptp Aug 15, 2023
f9a2158
style: pre-commit.ci fixes
pre-commit-ci[bot] Aug 15, 2023
f88fa6e
update the package_config_tests
phlptp Aug 15, 2023
796c283
install package config to correct location
phlptp Aug 15, 2023
89a9232
add debug output to cmake
phlptp Aug 15, 2023
eab3fd2
reorder cmake calls
phlptp Aug 15, 2023
39142e7
try again
phlptp Aug 15, 2023
fb9a268
add precompiled package tests
phlptp Aug 15, 2023
4aacecf
fix incorrect cmake variable in install section
phlptp Aug 17, 2023
5bb3c90
add preconfig files for precompiled library
phlptp Aug 17, 2023
7f32799
style: pre-commit.ci fixes
pre-commit-ci[bot] Aug 17, 2023
cedfc7c
filter the ctest workflow
phlptp Aug 17, 2023
ff96dc2
fix the template file condition
phlptp Aug 17, 2023
7453e29
add single file install test
phlptp Aug 17, 2023
b1199a5
add a header for single file include so it has a CLI/CLI.hpp file jus…
phlptp Aug 17, 2023
1ccc25f
style: pre-commit.ci fixes
pre-commit-ci[bot] Aug 17, 2023
81974a5
fix configure location
phlptp Aug 17, 2023
757f0e0
style: pre-commit.ci fixes
pre-commit-ci[bot] Aug 17, 2023
1cb7547
simplify to single pc file for single_file and normal
phlptp Aug 18, 2023
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
53 changes: 52 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
cmake -S . -B build \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCLI11_SINGLE_FILE_TESTS=OFF \
-DCLI11_EXAMPLES=OFF \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is what caused the coverage change, but I don't think the examples should be built or tested during the single file tests, not entirely sure what is going on.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage upload is finicky, it's possible it just had too many jobs not able to report. Going to try a rebuild to see. Otherwise, not too worked about it.

Copy link
Collaborator Author

@phlptp phlptp Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should take another crack at getting back to 100% sometime soon. Probably not in this PR though

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-DCLI11_BUILD_EXAMPLES=OFF \
-DCLI11_PRECOMPILED=${{matrix.precompile}} \
-DCMAKE_BUILD_TYPE=Coverage

Expand Down Expand Up @@ -138,6 +138,57 @@ jobs:

- name: Build
run: meson compile -C build-meson

install:
name: install tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Configure
run: cmake -S . -B build -DCLI11_INSTALL_PACKAGE_TESTS=ON -DCMAKE_INSTALL_PREFIX=/home/runner/work/install
- name: Build
run: cmake --build build -j2
- name: install
run: cmake --install build
- name: Run tests
run: ctest --output-on-failure -L Packaging
working-directory: build

install-precompiled:
name: install tests precompiled
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Configure
run: cmake -S . -B build -DCLI11_INSTALL_PACKAGE_TESTS=ON -DCMAKE_INSTALL_PREFIX=/home/runner/work/install -DCLI11_PRECOMPILED=ON
- name: Build
run: cmake --build build -j2
- name: install
run: cmake --install build
- name: Run tests
run: ctest --output-on-failure -L Packaging
working-directory: build

install-single_file:
name: install tests single file
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Configure
run: cmake -S . -B build -DCLI11_INSTALL_PACKAGE_TESTS=ON -DCMAKE_INSTALL_PREFIX=/home/runner/work/install -DCLI11_SINGLE_FILE=ON
- name: Build
run: cmake --build build -j2
- name: install
run: cmake --install build
- name: Run tests
run: ctest --output-on-failure -L Packaging
working-directory: build

cmake-config-ubuntu-2004:
name: CMake config check (Ubuntu 20.04)
Expand Down
8 changes: 6 additions & 2 deletions cmake/CLI11GeneratePkgConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
configure_file("cmake/CLI11.pc.in" "CLI11.pc" @ONLY)
if(CLI11_PRECOMPILED)
configure_file("cmake/CLI11precompiled.pc.in" "CLI11.pc" @ONLY)
else()
configure_file("cmake/CLI11.pc.in" "CLI11.pc" @ONLY)
endif()

install(FILES "${PROJECT_BINARY_DIR}/CLI11.pc" DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig")
install(FILES "${PROJECT_BINARY_DIR}/CLI11.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
11 changes: 11 additions & 0 deletions cmake/CLI11precompiled.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: CLI11
Description: C++ command line parser
Version: @PROJECT_VERSION@

Cflags: -I${includedir} -DCLI11_COMPILE
Libs: -L${libdir} -lCLI11
10 changes: 10 additions & 0 deletions cmake/CLIsingle.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2017-2023, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause

#pragma once

//single file header
#include "../CLI11.hpp"
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ if(CLI11_SINGLE_FILE)
if(CLI11_INSTALL)
install(FILES "${PROJECT_BINARY_DIR}/include/CLI11.hpp"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
configure_file("${CLI11_SOURCE_DIR}/cmake/CLIsingle.hpp.in"
"${PROJECT_BINARY_DIR}/include/CLI/CLI.hpp" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/include/CLI/CLI.hpp"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CLI)
endif()
add_library(CLI11_SINGLE INTERFACE)
target_link_libraries(CLI11_SINGLE INTERFACE CLI11)
Expand All @@ -129,7 +133,7 @@ if(CLI11_INSTALL)
if(NOT CLI11_SINGLE_FILE)
install(FILES ${CLI11_headers} ${CLI11_library_headers}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CLI")
if(NOT CLI11_COMPILE)
if(NOT CLI11_PRECOMPILED)
install(FILES ${CLI11_impl_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CLI/impl")
endif()
endif()
Expand Down
77 changes: 77 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,80 @@ if(CMAKE_BUILD_TYPE STREQUAL Coverage)
${CLI11_TESTS}
${CLI11_MULTIONLY_TESTS})
endif()

set(CLI11_PACKAGE_SEARCH_LOC "")

# tests of the cmake package and pkg-config package
if(CLI11_INSTALL_PACKAGE_TESTS)
if(NOT MSVC)
set(package_test_command --test-command "${CMAKE_CTEST_COMMAND}")
else() # don't try to run the tests on MSVC since that would require copying the dll's and doing
# some other setup that isn't that important to run on all OS
set(package_test_command)
endif()

if(CMAKE_BUILD_TYPE)
set(CLI11_PACKAGE_TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE})
else()
set(CLI11_PACKAGE_TEST_BUILD_TYPE Release)
endif()

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests")

if(MSVC AND ${CMAKE_VERSION} VERSION_GREATER 3.12.9)
# Tests for other CMake projects including and using CLI11 using find_package
add_test(
NAME find-package-testsA
COMMAND
${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -A "${CMAKE_GENERATOR_PLATFORM}"
"-DCLI11_DIR=${CMAKE_INSTALL_PREFIX}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
"${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests")
else()
add_test(
NAME find-package-testsA
COMMAND
${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "-DCLI11_DIR=${CMAKE_INSTALL_PREFIX}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
"${CMAKE_CURRENT_SOURCE_DIR}/find_package_tests"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests")
endif()

add_test(NAME find-package-testsB
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests"
--config ${CLI11_PACKAGE_TEST_BUILD_TYPE})

add_test(
NAME find-package-testsC
COMMAND ${CMAKE_CTEST_COMMAND} -C ${CLI11_PACKAGE_TEST_BUILD_TYPE}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/find_package_tests")
set_property(TEST find-package-testsA PROPERTY LABELS Packaging)
set_property(TEST find-package-testsB PROPERTY LABELS Packaging)
set_property(TEST find-package-testsB PROPERTY DEPENDS find-package-testsA)
set_property(TEST find-package-testsC PROPERTY LABELS Packaging)
set_property(TEST find-package-testsC PROPERTY DEPENDS find-package-testsB)

if(NOT MSVC)
# Tests for other CMake projects using the package_config files
add_test(
package-config-tests
${CMAKE_CTEST_COMMAND}
-C
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/package_config_tests"
"${CMAKE_CURRENT_BINARY_DIR}/package_config_tests"
--build-generator
"${CMAKE_GENERATOR}"
--build-generator-platform
"${CMAKE_GENERATOR_PLATFORM}"
--build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCLI11_DIR=${CMAKE_INSTALL_PREFIX}"
${package_test_command})
set_property(TEST package-config-tests PROPERTY LABELS Packaging)
endif()
endif()
19 changes: 19 additions & 0 deletions tests/find_package_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.10...3.26)

project(CLI11-find-package-test)

include(CTest)

if(CLI11_DIR)
set(CMAKE_PREFIX_PATH ${CLI11_DIR})
endif()

# Test the CLI11 CMake package config
find_package(CLI11 2.0 REQUIRED)

# Test the target
add_executable(package-test ../../examples/positional_validation.cpp)
target_link_libraries(package-test CLI11::CLI11)

add_test(NAME package-test1 COMMAND package-test one)
set_property(TEST package-test1 PROPERTY PASS_REGULAR_EXPRESSION "File 1 = one")
21 changes: 21 additions & 0 deletions tests/package_config_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.10...3.26)

project(CLI11-package-config-test)

include(CTest)

find_package(PkgConfig)

if(CLI11_DIR)
set(CMAKE_PREFIX_PATH ${CLI11_DIR} ${CLI11_DIR}/lib)
endif()

message(STATUS "${CLI11_DIR}-- ${CMAKE_PREFIX_PATH}")
pkg_check_modules(CLI11 REQUIRED IMPORTED_TARGET CLI11)

# Test the target
add_executable(package-config-test ../../examples/positional_validation.cpp)
target_link_libraries(package-config-test PkgConfig::CLI11)

add_test(NAME package-config-test1 COMMAND package-config-test one)
set_property(TEST package-config-test1 PROPERTY PASS_REGULAR_EXPRESSION "File 1 = one")