Skip to content

Commit

Permalink
Test installed cmake config package
Browse files Browse the repository at this point in the history
Install cmake config package to <prefix>/lib
Install files less verbose
Add examples to cmake project
Use debug postfix for install asio library
  • Loading branch information
ClausKlein committed Nov 29, 2024
1 parent 0a50406 commit 7fcf4a4
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 15 deletions.
9 changes: 7 additions & 2 deletions asio/.CMakeUserPresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@
"name": "dev",
"configurePreset": "dev",
"configuration": "Debug",
"jobs": 12
"jobs": 12,
"targets": [
"install"
]
},
{
"name": "verify",
"configurePreset": "dev",
"jobs": 12,
"targets": ["all_verify_interface_header_sets"]
"targets": [
"all_verify_interface_header_sets"
]
}
],
"testPresets": [
Expand Down
1 change: 1 addition & 0 deletions asio/.cmakefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cmake/spell-targets.cmake
cmake/spell.cmake
cmake/variables.cmake
cmake/windows-set-path.cmake
src/examples/CMakeLists.txt
src/tests/CMakeLists.txt
'

Expand Down
4 changes: 3 additions & 1 deletion asio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ endif()

option(ASIO_SEPARATE_COMPILATION "build asio lib too" ${PROJECT_IS_TOP_LEVEL})

set(CMAKE_DEBUG_POSTFIX D)

# ---- add dependency libraries ----

find_package(Threads REQUIRED)
Expand Down Expand Up @@ -64,7 +66,7 @@ if(ASIO_SEPARATE_COMPILATION)

# FIXME: some header in include/asio/detail fails CMAKE_VERIFY_INTERFACE_HEADER_SETS!
# NOTE: we need them installed, but we used them install with asio_header INTERFACE! CK
set(_public_headers ${_asio_headers})
set(_public_headers include/asio.hpp ${_asio_headers})
list(FILTER _public_headers EXCLUDE REGEX [=[.*/detail/.*\.hpp]=])
list(FILTER _public_headers EXCLUDE REGEX [=[.*/impl/.*\.hpp]=])
list(FILTER _public_headers EXCLUDE REGEX [=[.*/spawn.*\.hpp]=])
Expand Down
9 changes: 8 additions & 1 deletion asio/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"hidden": true,
"cacheVariables": {
"CMAKE_CXX_EXTENSIONS": "OFF",
"CMAKE_CXX_STANDARD": "17",
"CMAKE_CXX_STANDARD": "20",
"CMAKE_CXX_STANDARD_REQUIRED": "ON"
}
},
Expand Down Expand Up @@ -177,6 +177,13 @@
{
"name": "ci-build",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/stagedir",
"cacheVariables": {
"CMAKE_PREFIX_PATH": {
"type": "path",
"value": "${sourceDir}/stagedir"
}
},
"hidden": true
},
{
Expand Down
2 changes: 2 additions & 0 deletions asio/cmake/dev-mode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ include(cmake/folders.cmake)
option(ASIO_BUILD_TESTING "Use ctest" ON)
if(ASIO_BUILD_TESTING)
enable_testing()

add_subdirectory(src/tests)
add_subdirectory(src/examples)
endif()

option(ASIO_BUILD_MCSS_DOCS "Build documentation using Doxygen and m.css" OFF)
Expand Down
11 changes: 7 additions & 4 deletions asio/cmake/install-rules.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(PROJECT_IS_TOP_LEVEL)
set(CMAKE_INSTALL_INCLUDEDIR "include/asio-${PROJECT_VERSION}" CACHE PATH "")
endif()
# if(PROJECT_IS_TOP_LEVEL)
# NO! set(CMAKE_INSTALL_INCLUDEDIR "include/asio-${PROJECT_VERSION}" CACHE PATH "")
# endif()

# Project is configured with no languages, so tell GNUInstallDirs the lib dir
set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "")
Expand All @@ -10,6 +10,9 @@ include(cmake/AddUninstallTarget.cmake)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# Print Installing but not Up-to-date messages.
set(CMAKE_INSTALL_MESSAGE LAZY)

# find_package(<package) call for consumers to find this project
set(_package asio)

Expand All @@ -25,7 +28,7 @@ endif()
write_basic_package_version_file("${_package}ConfigVersion.cmake" COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)

# Allow package maintainers to freely override the path for the configs
set(ASIO_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/${_package}"
set(ASIO_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${_package}"
CACHE PATH "CMake package config location relative to the install prefix"
)
mark_as_advanced(ASIO_INSTALL_CMAKEDIR)
Expand Down
6 changes: 3 additions & 3 deletions asio/cmake/lint-targets.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
set(FORMAT_PATTERNS src/*.cpp src/*.hpp include/*.hpp tests/*.cpp tests/*.hpp
set(ACIO_FORMAT_PATTERNS *.json # src/*.cpp src/*.hpp include/*.hpp tests/*.cpp tests/*.hpp
CACHE STRING "; separated patterns relative to the project source dir to format"
)

set(FORMAT_COMMAND clang-format CACHE STRING "Formatter to use")

add_custom_target(
format-check
COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${FORMAT_PATTERNS}" -P
COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${ACIO_FORMAT_PATTERNS}" -P
"${PROJECT_SOURCE_DIR}/cmake/lint.cmake"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMENT "Linting the code"
Expand All @@ -15,7 +15,7 @@ add_custom_target(

add_custom_target(
format-fix
COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${FORMAT_PATTERNS}" -D FIX=YES -P
COMMAND "${CMAKE_COMMAND}" -D "FORMAT_COMMAND=${FORMAT_COMMAND}" -D "PATTERNS=${ACIO_FORMAT_PATTERNS}" -D FIX=YES -P
"${PROJECT_SOURCE_DIR}/cmake/lint.cmake"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMENT "Fixing the code"
Expand Down
19 changes: 19 additions & 0 deletions asio/src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.25...3.31)

project(asio_examples LANGUAGES CXX)

if(PROJECT_IS_TOP_LEVEL)
find_package(asio 1.32.0.1 EXACT REQUIRED)
enable_testing()
endif()

set(ALL_EXAMPLES callback_wrapper)

message(STATUS "Examples to be built: ${ALL_EXAMPLES}")

foreach(example ${ALL_EXAMPLES})
add_executable(${example})
target_sources(${example} PRIVATE cpp20/operations/${example}.cpp)
target_link_libraries(${example} asio::asio_header)
add_test(NAME ${example} COMMAND echo Test | ${example})
endforeach()
28 changes: 24 additions & 4 deletions asio/src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.23...3.29)
cmake_minimum_required(VERSION 3.25...3.31)

project(asio_test LANGUAGES CXX)

Expand All @@ -9,7 +9,7 @@ include(../../cmake/windows-set-path.cmake OPTIONAL)
# ---- Dependencies ----

if(PROJECT_IS_TOP_LEVEL)
find_package(asio REQUIRED)
find_package(asio 1.32.0 EXACT REQUIRED)
enable_testing()
endif()

Expand All @@ -18,9 +18,29 @@ endif()
add_executable(asio_test unit/read_until.cpp)

if(TARGET asio::asio)
target_link_libraries(asio_test PRIVATE asio::asio)
target_link_libraries(asio_test asio::asio)
else()
target_link_libraries(asio_test PRIVATE asio::asio_header)
target_link_libraries(asio_test asio::asio_header)
endif()

if(NOT PROJECT_IS_TOP_LEVEL)
if(NOT DEFINED CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})
endif()

# test if the targets are findable from the build directory
# NOTE: For an INTERFACE library and multi config generators, we may always use
# the -C Debug config type instead of $<CONFIG> to prevent problems! CK
if(CMAKE_BUILD_TYPE STREQUAL Debug)
add_test(
NAME find-package-test
COMMAND ${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C Debug --build-and-test
"${CMAKE_SOURCE_DIR}/src/examples" "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator
${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
)
endif()
endif()

# ---- Setup strict Compiler Warnings ----
Expand Down

0 comments on commit 7fcf4a4

Please sign in to comment.