-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from tcbrindle/pr/cmake_improvements
CMake improvements
- Loading branch information
Showing
52 changed files
with
182 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <iostream> | ||
#include <vector> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <iostream> | ||
#include <vector> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <vector> | ||
|
||
int main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <vector> | ||
|
||
int main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <vector> | ||
|
||
int main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <sstream> | ||
#include <vector> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <vector> | ||
|
||
int main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <string> | ||
#include <vector> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
#include <flux.hpp> | ||
|
||
#include <cassert> | ||
#include "assert.hpp" | ||
#include <string> | ||
#include <vector> | ||
|
||
|
Oops, something went wrong.