Skip to content

Commit

Permalink
Merge pull request #146 from tcbrindle/pr/cmake_improvements
Browse files Browse the repository at this point in the history
CMake improvements
  • Loading branch information
tcbrindle authored Jan 9, 2024
2 parents a45d844 + b03d276 commit 531a249
Show file tree
Hide file tree
Showing 52 changed files with 182 additions and 181 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ jobs:
run: ctest

- name: Generate coverage report
working-directory: ${{runner.workspace}}/build/test/CMakeFiles/test-libflux.dir
working-directory: ${{runner.workspace}}/build/test/CMakeFiles/test-flux.dir
run: |
lcov --directory . --capture --gcov gcov-13 --output-file coverage.info
lcov --remove coverage.info '*/test/*' --output-file coverage.info
- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
files: ${{runner.workspace}}/build/test/CMakeFiles/test-libflux.dir/coverage.info
files: ${{runner.workspace}}/build/test/CMakeFiles/test-flux.dir/coverage.info

122 changes: 59 additions & 63 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,121 +1,117 @@

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
cmake_minimum_required(VERSION 3.23)

project(libflux CXX)
project(flux CXX)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)


set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

add_library(flux INTERFACE)
file(GLOB_RECURSE FLUX_HPPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp" )
target_sources(flux INTERFACE $<BUILD_INTERFACE:${FLUX_HPPS}>)

if (MSVC)
target_compile_features(flux INTERFACE cxx_std_23)
target_compile_options(flux INTERFACE /permissive-)
else()
target_compile_features(flux INTERFACE cxx_std_20)
endif()

target_include_directories(
flux
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
add_library(flux::flux ALIAS flux)

file(GLOB_RECURSE FLUX_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp" )

target_sources(flux INTERFACE
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
FILES ${FLUX_HEADERS})

target_compile_features(flux INTERFACE $<IF:$<CXX_COMPILER_ID:MSVC>,cxx_std_23,cxx_std_20>)
set_target_properties(flux PROPERTIES CXX_STANDARD_REQUIRED On)

add_library(flux-internal INTERFACE)
target_link_libraries(flux-internal INTERFACE flux)
set_target_properties(flux-internal PROPERTIES CXX_EXTENSIONS Off)

target_compile_options(flux-internal INTERFACE
$<$<CXX_COMPILER_ID:Clang,AppleClang,GNU,Intel>:
-Wall -Wextra -Wconversion -pedantic
-fno-omit-frame-pointer
-ftemplate-backtrace-limit=0
>

$<$<CXX_COMPILER_ID:GNU>: -fconcepts-diagnostics-depth=2>

$<$<CXX_COMPILER_ID:MSVC>:
# Various options for closer standard conformance
/utf-8 /Zc:__cplusplus /Zc:throwingNew /Zc:inline /Zc:externConstexpr
/Zc:templateScope /Zc:checkGwOdr /Zc:enumTypes
/W4
/wd4459 # local variable name hides global variable
/wd4702 # unreachable code
>
)

set(CMAKE_CXX_EXTENSIONS Off)

option(FLUX_BUILD_DOCS "Build Flux documentation (requires Sphinx)" Off)
option(FLUX_BUILD_EXAMPLES "Build Flux examples" On)
option(FLUX_BUILD_TESTS "Build Flux tests" On)
option(FLUX_BUILD_EXAMPLES "Build Flux examples" ${PROJECT_IS_TOP_LEVEL})
option(FLUX_BUILD_TESTS "Build Flux tests" ${PROJECT_IS_TOP_LEVEL})
option(FLUX_BUILD_BENCHMARKS "Build Flux benchmarks" Off)
option(FLUX_BUILD_TOOLS "Build single-header generator tool" Off)
option(FLUX_BUILD_MODULE "Build C++20 module (experimental)" Off)
option(FLUX_ENABLE_ASAN "Enable Address Sanitizer for tests" Off)
option(FLUX_ENABLE_UBSAN "Enable Undefined Behaviour Sanitizer for tests" Off)

if (${FLUX_BUILD_DOCS})
if (FLUX_BUILD_DOCS)
add_subdirectory(docs)
endif()

if (${FLUX_BUILD_EXAMPLES})
if (FLUX_BUILD_EXAMPLES)
enable_testing()
add_subdirectory(example)
endif()

if (${FLUX_BUILD_BENCHMARKS})
if (FLUX_BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif()

if (${FLUX_BUILD_TESTS})
if (FLUX_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()

if (${FLUX_BUILD_TOOLS})
if (FLUX_BUILD_TOOLS)
add_subdirectory(tools)
endif()

if (${FLUX_BUILD_MODULE})
if (FLUX_BUILD_MODULE)
add_subdirectory(module)
endif()

set(PORT_NAME flux)
set(CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PORT_NAME}")
set(FLUX_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/flux)

# 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"
"${PROJECT_BINARY_DIR}/flux-version.cmake"
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
ARCH_INDEPENDENT
)
set(CMAKE_SIZEOF_VOIDP ${ORIGINAL_CMAKE_SIZEOF_VOIDP})

configure_package_config_file(
"${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
NO_CHECK_REQUIRED_COMPONENTS_MACRO
"${PROJECT_SOURCE_DIR}/cmake/flux-config.cmake.in"
"${PROJECT_BINARY_DIR}/flux-config.cmake"
INSTALL_DESTINATION ${FLUX_INSTALL_CMAKE_DIR}
)

# 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}"
TARGETS flux
EXPORT flux-targets
FILE_SET HEADERS
)

#install the targets files
install(
EXPORT ${PORT_NAME}-targets
NAMESPACE ${PORT_NAME}::
DESTINATION "${CONFIG_DESTINATION}"
EXPORT flux-targets
NAMESPACE flux::
DESTINATION ${FLUX_INSTALL_CMAKE_DIR}
)

# 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}"
"${PROJECT_BINARY_DIR}/flux-config.cmake"
"${PROJECT_BINARY_DIR}/flux-version.cmake"
DESTINATION ${FLUX_INSTALL_CMAKE_DIR}
)

# install the headers
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/.."
PATTERN "build2file" EXCLUDE
)
3 changes: 2 additions & 1 deletion cmake/flux-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/flux-targets.cmake")
list(APPEND CMAKE_MODULE_PATH "@PACKAGE_cmakeModulesDir@")

check_required_components(flux)
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

function(ADD_EXAMPLE NAME SOURCE)
add_executable(${NAME} ${SOURCE})
target_link_libraries(${NAME} flux)
target_link_libraries(${NAME} flux-internal)
if(${${NAME}_SKIP_TEST})
#pass
else()
Expand Down
11 changes: 7 additions & 4 deletions example/calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ auto to_week_lines = [](flux::sequence auto&& month) {
auto week_lines = FLUX_FWD(month)
.chunk_by(week_num)
.map(week_to_string);
std::vector<std::string> pad_lines(max_weeks_in_month - flux::count(week_lines), std::string(week_str_size, ' '));
std::vector<std::string> pad_lines(size_t(max_weeks_in_month - flux::count(week_lines)),
std::string(week_str_size, ' '));
return flux::chain(flux::single(std::move(month_str)),
std::move(week_lines),
std::move(pad_lines),
Expand All @@ -113,13 +114,14 @@ auto append_column = [](std::vector<std::string>&& months_per_line, flux::sequen
// Out: std::vector<std::string> (months organized in columns)
auto to_columns = [](flux::sequence auto&& month_chunk) {
auto n_rows = month_chunk.front()->count();
return FLUX_FWD(month_chunk).fold(append_column, std::vector<std::string>(n_rows, col_sep));
return FLUX_FWD(month_chunk).fold(append_column,
std::vector<std::string>(size_t(n_rows), col_sep));
};

const auto current_year = ymd{floor<days>(system_clock::now())}.year();

struct app_args_t {
unsigned per_line = 3;
int per_line = 3;
ymd from = current_year / January / 1d;
ymd to = from + years{1};
};
Expand All @@ -146,7 +148,8 @@ app_args_t parse_args(int argc, char** argv) {

auto to_pair = [](const auto& s) {
auto pos = flux::find(flux::ref(s), '=');
return std::pair{s.substr(0, pos), s.substr(std::min(flux::count(s), pos + 1))};
return std::pair{s.substr(0, size_t(pos)),
s.substr(size_t(std::min(flux::count(s), pos + 1)))};
};

for (const auto& [key, val] : flux::ref(args).map(to_pair)) {
Expand Down
2 changes: 1 addition & 1 deletion example/docs/adjacent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <iostream>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion example/docs/adjacent_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <iostream>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion example/docs/all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <vector>

int main()
Expand Down
2 changes: 1 addition & 1 deletion example/docs/any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <vector>

int main()
Expand Down
15 changes: 15 additions & 0 deletions example/docs/assert.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

// Copyright (c) 2024 Tristan Brindle (tcbrindle at gmail dot com)
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef FLUX_EXAMPLE_DOCS_ASSERT_HPP_INCLUDED
#define FLUX_EXAMPLE_DOCS_ASSERT_HPP_INCLUDED

#ifdef NDEBUG
#undef NDEBUG
#endif

#include <cassert>

#endif
2 changes: 1 addition & 1 deletion example/docs/compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <cmath>
#include <limits>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion example/docs/contains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <vector>

int main()
Expand Down
2 changes: 1 addition & 1 deletion example/docs/count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <sstream>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion example/docs/cycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include <flux.hpp>

#include "assert.hpp"
#include <array>
#include <cassert>
#include <string_view>

int main()
Expand Down
2 changes: 1 addition & 1 deletion example/docs/drop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <vector>

int main()
Expand Down
2 changes: 1 addition & 1 deletion example/docs/ends_with.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <string>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion example/docs/find_max.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <string>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion example/docs/find_min.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <string>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion example/docs/find_minmax.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <string>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion example/docs/mask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <flux.hpp>

#include <cassert>
#include "assert.hpp"
#include <string>
#include <vector>

Expand Down
Loading

0 comments on commit 531a249

Please sign in to comment.