Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/.cache
/compile_commands.json
/build
build/

# ignore emacs temp files
*~
Expand Down
50 changes: 41 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.28...4.2)
cmake_minimum_required(VERSION 3.30...4.3)

include(./cmake/prelude.cmake)

project(
beman.transform_view # CMake Project Name, which is also the name of the top-level
Expand All @@ -10,6 +12,9 @@ project(
VERSION 0.1.0
)

# Modules opt in only on compilers that support it: msvc, g++-15 and clang-20+
include(./cmake/cxx-modules-rules.cmake)

# [CMAKE.SKIP_TESTS]
option(
BEMAN_TRANSFORM_VIEW_BUILD_TESTS
Expand All @@ -30,24 +35,51 @@ include(infra/cmake/beman-install-library.cmake)
add_library(beman.transform_view INTERFACE)
add_library(beman::transform_view ALIAS beman.transform_view)

target_sources(
beman.transform_view
PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_sources(beman.transform_view PUBLIC FILE_SET HEADERS BASE_DIRS include)

set_target_properties(
beman.transform_view
PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON
PROPERTIES VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL}
)

add_subdirectory(include/beman/transform_view)

include(CTest)
if(BEMAN_USE_MODULES)
add_library(beman.transform_view_module STATIC)
add_library(beman::transform_view_module ALIAS beman.transform_view_module)
target_compile_features(
beman.transform_view_module
PUBLIC cxx_std_${CMAKE_CXX_STANDARD}
)
if(BEMAN_HAS_IMPORT_STD)
target_compile_definitions(
beman.transform_view_module
PUBLIC BEMAN_HAS_IMPORT_STD
)
set_target_properties(
beman.transform_view_module
PROPERTIES CXX_MODULE_STD ON
)
endif()

target_sources(
beman.transform_view_module
PUBLIC
FILE_SET HEADERS
BASE_DIRS include
FILES include/beman/transform_view/transform_view.hpp
)

add_subdirectory(src/beman/transform_view)
endif()

# NOTE: CTest.cmake creates a lot of unused target here! CK
# NOT needed! include(CTest)
enable_testing()

beman_install_library(beman.transform_view TARGETS beman.transform_view)
beman_install_library(beman.transform_view TARGETS beman.transform_view beman.transform_view_module)

if(BEMAN_TRANSFORM_VIEW_BUILD_TESTS)
enable_testing()
add_subdirectory(tests/beman/transform_view)
endif()

Expand Down
47 changes: 43 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,31 @@
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"BEMAN_USE_MODULES": true,
"BEMAN_USE_STD_MODULE": true,
"CMAKE_CXX_STANDARD": "23",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "./infra/cmake/use-fetch-content.cmake"
"CMAKE_CXX_EXTENSIONS": true,
"CMAKE_CXX_STANDARD_REQUIRED": true,
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_INSTALL_MESSAGE": "LAZY",
"CMAKE_SKIP_TEST_ALL_DEPENDENCY": false,
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "infra/cmake/use-fetch-content.cmake"
}
},
{
"name": "_debug-base",
"hidden": true,
"warnings": {
"dev": true,
"deprecated": true,
"uninitialized": true,
"unusedCli": true,
"systemVars": false
},
"errors": {
"dev": false,
"deprecated": false
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BEMAN_BUILDSYS_SANITIZER": "MaxSan"
Expand Down Expand Up @@ -57,7 +74,11 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/llvm-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/llvm-libc++-toolchain.cmake"
},
"environment": {
"CXX": "clang++",
"CMAKE_CXX_FLAGS": "-stdlib=libc++"
}
},
{
Expand All @@ -68,7 +89,11 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/llvm-toolchain.cmake"
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/llvm-libc++-toolchain.cmake"
},
"environment": {
"CXX": "clang++",
"CMAKE_CXX_FLAGS": "-stdlib=libc++"
}
},
{
Expand All @@ -79,6 +104,8 @@
"_debug-base"
],
"cacheVariables": {
"BEMAN_USE_STD_MODULE": false,
"BEMAN_USE_MODULES": false,
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/appleclang-toolchain.cmake"
}
},
Expand All @@ -90,6 +117,8 @@
"_release-base"
],
"cacheVariables": {
"BEMAN_USE_STD_MODULE": false,
"BEMAN_USE_MODULES": false,
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/appleclang-toolchain.cmake"
}
},
Expand All @@ -102,6 +131,11 @@
],
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/msvc-toolchain.cmake"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
Expand All @@ -113,6 +147,11 @@
],
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/msvc-toolchain.cmake"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
}
],
Expand Down
149 changes: 149 additions & 0 deletions cmake/cxx-modules-rules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# A CMake language file to be included as the last step of all project() command calls.
# This file must be included/used as CMAKE_PROJECT_INCLUDE -> after project()
#

# ---- The include guard applies within the current directory and below ----
include_guard(DIRECTORY)

if(NOT PROJECT_NAME)
message(
FATAL_ERROR
"This CMake file has to be included as the last step of all project() command calls!"
)
endif()

# Use modules? default NO!
if(NOT DEFINED CMAKE_CXX_SCAN_FOR_MODULES)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
endif()

# Control whether the test target depends on the all target.
set(CMAKE_SKIP_TEST_ALL_DEPENDENCY OFF)

# gersemi: off
option(CMAKE_EXPORT_COMPILE_COMMANDS "Prepare run-clang-tidy" ${PROJECT_IS_TOP_LEVEL})
if(CMAKE_EXPORT_COMPILE_COMMANDS)
message(
STATUS
"CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES=${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}"
)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
# gersemi: on

# Ensure non-empty default build type for single-config
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT isMultiConfig)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type")
endif()
set(CMAKE_DEBUG_POSTFIX _d)

# ------------------------------------------------------------------------------
# This property setting also needs to be consistent between the installed shared
# library and its consumer, otherwise most toolchains will once again reject the
# consumer's generated BMI.
# ------------------------------------------------------------------------------
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 23)
endif()

# Neither of these two are technically needed, but they make the expectation clear
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# NOTE: only with Ninja generator install of bmi files works yet!
if(CMAKE_GENERATOR MATCHES "Ninja")
if(
CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0
)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)

if(NOT LINUX)
string(APPEND CMAKE_CXX_MODULE_MAP_FLAG " -fmodules-reduced-bmi")
endif()

add_compile_options($ENV{CXXFLAGS})
add_link_options($ENV{CXXFLAGS})
elseif(
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0
)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
else()
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
endif()
endif()

if(CMAKE_CXX_STDLIB_MODULES_JSON)
message(
STATUS
"CMAKE_CXX_STDLIB_MODULES_JSON=${CMAKE_CXX_STDLIB_MODULES_JSON}"
)
endif()

if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
option(BEMAN_USE_MODULES "Build CXX_MODULES" ${CMAKE_CXX_SCAN_FOR_MODULES})
endif()
message(STATUS "BEMAN_USE_MODULES=${BEMAN_USE_MODULES}")

option(
BEMAN_USE_STD_MODULE
"Check if 'import std;' is possible with the toolchain?"
OFF
)
message(STATUS "BEMAN_USE_STD_MODULE=${BEMAN_USE_STD_MODULE}")

if(BEMAN_USE_MODULES AND BEMAN_USE_STD_MODULE)
# -------------------------------------------------------------------------
# Tell CMake that we explicitly want `import std`.
# This will initialize the property on all targets declared after this to 1
# -------------------------------------------------------------------------
message(
STATUS
"CMAKE_CXX_COMPILER_IMPORT_STD=${CMAKE_CXX_COMPILER_IMPORT_STD}"
)
if(${CMAKE_CXX_STANDARD} IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
option(
BEMAN_HAS_IMPORT_STD
"Build with import std; is possible and used!"
${BEMAN_USE_STD_MODULE}
)
else()
set(BEMAN_HAS_IMPORT_STD OFF)
set(CMAKE_CXX_MODULE_STD OFF)
message(WARNING "CMAKE_CXX_MODULE_STD=${CMAKE_CXX_MODULE_STD}")
endif()
endif()

if(NOT BEMAN_USE_MODULES)
set(BEMAN_HAS_IMPORT_STD OFF)
endif()
message(STATUS "BEMAN_HAS_IMPORT_STD=${BEMAN_HAS_IMPORT_STD}")

# ------------------------------------------------------------------------------
# Avoid creating CMAKE_..._OUTPUT_DIRECTORY as cache variables, they should not
# be under the control of the developer. They should be controlled by the
# project because parts of the project may make assumptions about the relative
# layout of the binaries. More importantly, leaving them as ordinary variables
# also means they can be unset within subdirectories where test executables are
# defined, allowing them to avoid being collected with the other main binaries
# and cluttering up that area.
# ------------------------------------------------------------------------------
set(stageDir ${CMAKE_CURRENT_BINARY_DIR}/stagedir)
include(GNUInstallDirs)

if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_BINDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_LIBDIR})
endif()
Loading