Skip to content

Commit

Permalink
Fix compile problems with c++20
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Dec 22, 2023
1 parent 1abb90e commit e1e89c4
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 129 deletions.
28 changes: 16 additions & 12 deletions .cmake-format
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,26 @@ parse:
pargs: 1
spelling: CPMUsePackageLock
packageproject:
pargs:
nargs: '*'
flags: []
spelling: packageProject
kwargs:
BINARY_DIR: 1
COMPATIBILITY: 1
DEPENDENCIES: +
DISABLE_VERSION_SUFFIX: 1
EXPORT_HEADER: 1
INCLUDE_DESTINATION: 1
INCLUDE_DIR: 1
NAME: 1
NAMESPACE: 1
VERSION: 1
NAMESPACE: 1
INCLUDE_DIR: 1
INCLUDE_DESTINATION: 1
INCLUDE_HEADER_PATTERN: 1
BINARY_DIR: 1
COMPATIBILITY: 1
VERSION_HEADER: 1
pargs:
flags: []
nargs: '*'
spelling: packageProject
EXPORT_HEADER: 1
DISABLE_VERSION_SUFFIX: 1
CPACK: 1
DEPENDENCIES: +
TARGETS: +

format:
line_width: 123
tab_size: 2
Expand Down
94 changes: 56 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ cmake_minimum_required(VERSION 3.21...3.28)

project(Boost-CMake LANGUAGES C CXX VERSION 1.81.0)

if(NOT PROJECT_IS_TOP_LEVEL)
if(PROJECT_IS_TOP_LEVEL)
message(STATUS "PROJECT_IS_TOP_LEVEL")
else()
option(BOOST_DISABLE_TESTS "Do not build test targets, even if building standalone" ON)
endif()
option(BOOST_USE_ALL_OPTIONAL_LIBS "Prepare all optional libs" ON)

# ---- Add dependencies via CPM ----
# ---- Add/prepare dependency handling via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info

include(cmake/CPM.cmake)

if(EXISTS "$ENV{CPM_SOURCE_CACHE}/boost_1_81_0")
set(FETCHCONTENT_SOURCE_DIR_BOOST "$ENV{CPM_SOURCE_CACHE}/boost_1_81_0" CACHE PATH "Boost source DIR")
set(CPM_Boost_SOURCE ${FETCHCONTENT_SOURCE_DIR_BOOST} CACHE PATH "Manual override")
Expand All @@ -23,6 +24,7 @@ set(BOOST_URL_SHA256 "71feeed900fbccca04a3b4f2f84a7c217186f28a940ed8b7ed4725986b
CACHE STRING "Boost download URL SHA256 checksum"
)

# ---- Add Boost source tar archive via FetchContent ----
include(FetchContent)
FetchContent_Declare(Boost URL ${BOOST_URL} URL_HASH SHA256=${BOOST_URL_SHA256})

Expand All @@ -38,6 +40,13 @@ if(NOT Boost_POPULATED)
if(Patch_FOUND)
message("Patch found: ${Patch_EXECUTABLE}")
message("Patching Boost")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/patches/${PROJECT_VERSION}/thread_future-01.patch)
execute_process(
COMMAND ${Patch_EXECUTABLE} -N -p1 -i
${CMAKE_CURRENT_SOURCE_DIR}/patches/${PROJECT_VERSION}/thread_future-01.patch
WORKING_DIRECTORY ${BOOST_SOURCE}/boost COMMAND_ECHO STDOUT
)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/patches/${PROJECT_VERSION}/filesystem-01.patch)
execute_process(
COMMAND ${Patch_EXECUTABLE} -N -p1 -i ${CMAKE_CURRENT_SOURCE_DIR}/patches/${PROJECT_VERSION}/filesystem-01.patch
Expand Down Expand Up @@ -74,7 +83,7 @@ include(AddBoostLib)
include(AddBoostTest)

# NOTE: Install the missing CMakeList.txt file, but it will not yet used! CK
# If the tar achive contains one, it will not overridden.
# If the tar archive contains one, it will not overridden.
configure_file(cmake/CMakeLists.txt.in ${BOOST_SOURCE}/CMakeLists.txt @ONLY)
configure_file(cmake/Modules/ccache.cmake ${BOOST_SOURCE}/tools/cmake/include/ccache.cmake COPYONLY)

Expand All @@ -91,40 +100,45 @@ if(USE_ANDROID)
set(CMAKE_ASM_COMPILER_TARGET "${CMAKE_CXX_COMPILER_TARGET}")
endif()

set(BOOST_LIBS_REQUIRED # Header only libs
header
serialization
system
thread
chrono
# TODO(CK): atomic filesystem
)
set(BOOST_LIBS_REQUIRED header)
if(NOT BOOST_USE_ALL_OPTIONAL_LIBS)
list(APPEND
BOOST_LIBS_REQUIRED
serialization
system
thread
chrono
atomic
filesystem
)
endif()

set(BOOST_LIBS_OPTIONAL
# Compiled libs
atomic
chrono
container
container # warnings
context
coroutine
date_time
exception
fiber
fiber # warnings
filesystem
graph
graph # warnings
iostreams
json
# FIXME: locale # TODO(CK) to complex, refactory needed!
log
json # depends on container
# FIXME: locale # NOTE: to complex, refactory needed!
# TODO(CK) log # errors
math
mpi
graph_parallel # TODO(CK) does this realy depends on mpi?
mpi # warnings
graph_parallel # TODO(CK): depends on graph; does this really depends on mpi?
program_options
# XXX python # NOTE: not supported, to complex module!
random
random # warnings
regex
serialization
system
test
test # warnings
thread
timer
type_erasure
Expand All @@ -136,42 +150,42 @@ foreach(lib ${BOOST_LIBS_REQUIRED})
include("libs/${lib}.cmake")
endforeach()

# FIXME: disabled for now! CK
# foreach(lib ${BOOST_LIBS_OPTIONAL})
# # In case only a subset of modules is available (eg. after using bcp)
# if(EXISTS "${BOOST_SOURCE}/libs/${lib}")
# include("libs/${lib}.cmake")
# endif()
# endforeach()
if(BOOST_USE_ALL_OPTIONAL_LIBS)
foreach(lib ${BOOST_LIBS_OPTIONAL})
# In case only a subset of modules is available
if(EXISTS "${BOOST_SOURCE}/libs/${lib}")
include("libs/${lib}.cmake")
endif()
endforeach()
endif()

# TODO: Move those to option() calls in the right file
#############################################################
# TODO(CK): Move this to libs/header.cmake in the right file
find_package(Threads)

# Compilation options required by all platforms
target_compile_definitions(
boost
INTERFACE $<$<CONFIG:Release>:BOOST_DISABLE_ASSERT>
BOOST_ASIO_NO_DEPRECATED
BOOST_SYSTEM_NO_DEPRECATED
BOOST_THREAD_VERSION=5
BOOST_THREAD_USES_CHRONO
BOOST_THREAD_PROVIDES_EXECUTORS
)
target_link_libraries(boost INTERFACE Threads::Threads)
target_compile_definitions(boost INTERFACE BOOST_BIND_GLOBAL_PLACEHOLDERS)

if(PROJECT_IS_TOP_LEVEL)
message(STATUS "PROJECT_IS_TOP_LEVEL")
else()
if(NOT PROJECT_IS_TOP_LEVEL)
add_library(Boost::asio ALIAS boost)
endif()
#############################################################

if(UNIX)
if(USE_APPLE)
# TODO(CK): too many deprectated warnings!
# TODO(CK): too many deprecated warnings!
# intrusive/pointer_rebind.hpp:81:35: warning: 'rebind<std::pair<const int, int>>' is deprecated
# fiber/future/async.hpp:57 'result_of<void (*())()>' is deprecated
target_compile_options(boost INTERFACE -Wno-deprecated-declarations)
target_compile_options(boost INTERFACE -Wno-deprecated-declarations -Wno-deprecated-copy-with-user-provided-copy)
else()
target_compile_definitions(boost INTERFACE BOOST_NO_AUTO_PTR)
endif()
Expand All @@ -191,6 +205,7 @@ endif()
# PackageProject.cmake will be used to make our target installable

if(BOOST_USE_ORIGINAL_PackageProject)
include(cmake/CPM.cmake)
CPMAddPackage("gh:TheLartians/[email protected]")

set(BOOST_LIBS ${BOOST_LIBS_OPTIONAL})
Expand Down Expand Up @@ -218,15 +233,18 @@ else()
endif()

packageProject(
NAME Boost TARGETS ${BOOST_LIBS}
NAME Boost
TARGETS ${BOOST_LIBS}
VERSION ${BOOST_VERSION}
NAMESPACE Boost
BINARY_DIR ${PROJECT_BINARY_DIR} ARCH_INDEPENDENT NO
INCLUDE_DIR ${BOOST_SOURCE}/boost
INCLUDE_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/boost
DISABLE_VERSION_SUFFIX YES
COMPATIBILITY SameMajorVersion
CPACK NO
DEPENDENCIES "Threads" # TODO(CK): variable list needed for: BZIP2; Iconf; ICU; MPI; ZLIB
)

include(cmake/AddUninstallTarget.cmake)
include(CPack)
2 changes: 1 addition & 1 deletion CMakeReleasePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"BUILD_SHARED_LIBS": false,
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_EXTENSIONS": false,
"CMAKE_CXX_STANDARD": "20",
"CMAKE_CXX_STANDARD": "17",
"CMAKE_CXX_STANDARD_REQUIRED": true,
"CMAKE_DEBUG_POSTFIX": "-d",
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
Expand Down
24 changes: 24 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: all fresh configure build test install format
all: build

fresh:
cmake --workflow --preset Release --fresh

configure:
cmake --preset Release

build: configure
cmake --build --preset Release

test: build
ctest --build --preset Release

install: test
cmake --build --preset Release --target install

format:
git clang-format
find . \( -type d -name build -o -name stagedir \) -prune -o \( -name '*.cmake' -o -name CMakeLists.txt \) -print > .cmakefiles.log
#NO! cmake-format -i `cat .cmakefiles.log`
ls -1 *.json >> .cmakefiles.log
cmake-format -i CMakeLists.txt cmake/*.cmake cmake/*/*.cmake
2 changes: 1 addition & 1 deletion cmake/CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(BOOST_SUPERPROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/include)

option(CMAKE_CXX_EXTENSIONS "Default value for CXX_EXTENSIONS property of targets." NO)
option(CMAKE_CXX_STANDARD_REQUIRED "The c++ standard is requrired" YES)
option(CMAKE_CXX_STANDARD_REQUIRED "The c++ standard is required" YES)
option(BUILD_SHARED_LIBS "Build shared libraries" ${PROJECT_IS_TOP_LEVEL})

### see tools/cmake/include/BoostRoot.cmake
Expand Down
34 changes: 26 additions & 8 deletions cmake/Modules/AddBoostLib.cmake
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
function(_add_boost_lib)
set(options)
set(oneValueArgs NAME)
set(multiValueArgs SOURCES LINK DEFINE DEFINE_PRIVATE CXXFLAGS_PRIVATE INCLUDE_PRIVATE)
cmake_parse_arguments(BOOSTLIB "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(multiValueArgs
SOURCES
LINK
DEFINE
DEFINE_PRIVATE
CXXFLAGS_PRIVATE
INCLUDE_PRIVATE
)
cmake_parse_arguments(
BOOSTLIB
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)

add_library(${BOOSTLIB_NAME} STATIC ${BOOSTLIB_SOURCES})
add_library(Boost::${BOOSTLIB_NAME} ALIAS ${BOOSTLIB_NAME})
set_target_properties(${BOOSTLIB_NAME} PROPERTIES
OUTPUT_NAME "boost_${BOOSTLIB_NAME}"
FOLDER "Boost"
)
set_target_properties(${BOOSTLIB_NAME} PROPERTIES OUTPUT_NAME "boost_${BOOSTLIB_NAME}" FOLDER "Boost")
if(NOT BOOST_STANDALONE)
set_target_properties(${BOOSTLIB_NAME} PROPERTIES EXCLUDE_FROM_ALL 1)
endif()
target_link_libraries(${BOOSTLIB_NAME} PUBLIC Boost::headers)
if(MSVC)
target_compile_options(${BOOSTLIB_NAME} PRIVATE /W0)
else()
target_compile_options(${BOOSTLIB_NAME} PRIVATE -w)
elseif(NOT BOOST_USE_ALL_OPTIONAL_LIBS)
target_compile_options(
${BOOSTLIB_NAME}
PRIVATE # XXX -w
-Wall
-Wextra
-Wpedantic
-Werror
-Wshadow
)
endif()
if(BOOSTLIB_LINK)
target_link_libraries(${BOOSTLIB_NAME} PUBLIC ${BOOSTLIB_LINK})
Expand Down
18 changes: 9 additions & 9 deletions cmake/Modules/AddBoostTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ function(_add_boost_test)
set(options)
set(oneValueArgs NAME)
set(multiValueArgs LINK DEFINE INCLUDE TESTS)
cmake_parse_arguments(BOOSTTEST "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
cmake_parse_arguments(
BOOSTTEST
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)

# Split all arguments for TESTS in groups
list(LENGTH BOOSTTEST_TESTS arg_len)
Expand Down Expand Up @@ -39,13 +44,8 @@ function(_add_boost_test)
get_filename_component(source_name ${main_src} NAME_WE)
set(test_name Boost_${BOOSTTEST_NAME}_${source_name})
add_executable(${test_name} ${test_files})
add_test(NAME ${test_name}
COMMAND ${test_name}
WORKING_DIRECTORY ${BOOST_SOURCE}/status
)
set_target_properties(${test_name} PROPERTIES
FOLDER "Boost/Tests"
)
add_test(NAME ${test_name} COMMAND ${test_name} WORKING_DIRECTORY ${BOOST_SOURCE}/status)
set_target_properties(${test_name} PROPERTIES FOLDER "Boost/Tests")
if(MSVC)
target_compile_options(${test_name} PRIVATE /bigobj)
endif()
Expand Down
4 changes: 1 addition & 3 deletions cmake/Modules/CheckBoostVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ if(NOT EXISTS "${BOOST_SOURCE}/boost/version.hpp")
message(FATAL_ERROR "missing ${BOOST_SOURCE}/boost/version.hpp")
endif()

file(STRINGS "${BOOST_SOURCE}/boost/version.hpp" boost_version_raw
REGEX "define BOOST_VERSION "
)
file(STRINGS "${BOOST_SOURCE}/boost/version.hpp" boost_version_raw REGEX "define BOOST_VERSION ")
string(REGEX MATCH "[0-9]+" boost_version_raw "${boost_version_raw}")
math(EXPR BOOST_VERSION_MAJOR "${boost_version_raw} / 100000")
math(EXPR BOOST_VERSION_MINOR "${boost_version_raw} / 100 % 1000")
Expand Down
1 change: 0 additions & 1 deletion cmake/Modules/CheckPreprocessor.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ function(check_preprocessor output_variable symbol)
set(${output_variable} 0 CACHE INTERNAL "Have symbol ${symbol}" FORCE)
endif()
endfunction()

Loading

0 comments on commit e1e89c4

Please sign in to comment.