Skip to content

Commit 0a7c231

Browse files
authored
Merge pull request #1 from iris-cpp/initial-x4
Add minimal implementation of config and type_traits
2 parents 157ebf5 + 621e948 commit 0a7c231

9 files changed

Lines changed: 583 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
name: CI
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- 'main'
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
env:
16+
IRIS_BUILD_JOBS: 4
17+
18+
jobs:
19+
changes:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
iris_component: ${{ steps.filter.outputs.changes }}
23+
steps:
24+
- uses: actions/checkout@v5
25+
- uses: dorny/paths-filter@v3
26+
id: filter
27+
with:
28+
filters: |
29+
iris:
30+
- '.github/workflows/*.yml'
31+
- 'CMakeLists.txt'
32+
- 'include/iris/**/*'
33+
- 'test/CMakeLists.txt'
34+
- 'test/**/*'
35+
36+
build:
37+
name: "[${{ matrix.cpp_version.name }}] ${{ matrix.iris_component }} | ${{ matrix.compiler.toolset }}-${{ matrix.compiler.version }} (${{ matrix.build_type.name }}) @ ${{ matrix.os.name }}-${{ matrix.os.version }}"
38+
39+
needs: changes
40+
if: ${{ needs.changes.outputs.iris_component != '[]' && needs.changes.outputs.iris_component != '' }}
41+
42+
runs-on: ${{ matrix.os.name }}-${{ matrix.os.version }}
43+
44+
strategy:
45+
fail-fast: false
46+
47+
matrix:
48+
os:
49+
- name: ubuntu
50+
version: 24.04
51+
- name: windows
52+
version: 2022
53+
build_type:
54+
- name: Debug
55+
lowercase: debug
56+
- name: Release
57+
lowercase: release
58+
cpp_version:
59+
- name: C++23
60+
number: 23
61+
- name: C++26
62+
number: 26
63+
compiler:
64+
- name: GCC
65+
toolset: gcc
66+
version: 14
67+
executable: g++-14
68+
cxxflags: -fdiagnostics-color=always
69+
- name: Clang
70+
toolset: clang
71+
version: 21
72+
executable: clang++-21
73+
cxxflags: -stdlib=libc++ -fcolor-diagnostics
74+
- name: MSVC
75+
toolset: msvc
76+
version: 2022
77+
builder_additional_args: -- "-consoleLoggerParameters:ForceConsoleColor"
78+
executable: cl
79+
80+
iris_component: ${{ fromJSON(needs.changes.outputs.iris_component) }}
81+
82+
exclude:
83+
# Blacklist all invalid combinations of environments
84+
- os:
85+
name: windows
86+
compiler:
87+
name: GCC
88+
- os:
89+
name: windows
90+
compiler:
91+
name: Clang
92+
- os:
93+
name: ubuntu
94+
compiler:
95+
name: MSVC
96+
97+
steps:
98+
- uses: actions/checkout@v5
99+
100+
- name: Initialize Ubuntu
101+
if: matrix.os.name == 'ubuntu'
102+
run: |
103+
sudo echo "set man-db/auto-update false" | sudo debconf-communicate
104+
sudo dpkg-reconfigure man-db
105+
106+
- name: Setup GCC
107+
if: matrix.compiler.toolset == 'gcc'
108+
run: |
109+
sudo apt-get update
110+
sudo apt-get install -y g++-${{ matrix.compiler.version }}
111+
112+
- name: Setup Clang
113+
if: matrix.compiler.toolset == 'clang'
114+
run: |
115+
wget https://apt.llvm.org/llvm.sh
116+
chmod +x ./llvm.sh
117+
sudo ./llvm.sh ${{ matrix.compiler.version }}
118+
sudo apt-get install -y libc++-${{ matrix.compiler.version }}-dev libc++abi-${{ matrix.compiler.version }}-dev libunwind-${{ matrix.compiler.version }}-dev
119+
120+
- uses: TheMrMilchmann/setup-msvc-dev@v3
121+
if: matrix.os.name == 'windows'
122+
with:
123+
arch: x64
124+
125+
- name: Fetch Environment Info
126+
id: env-info
127+
shell: bash
128+
run: |
129+
set -e
130+
case "${{ matrix.compiler.toolset }}" in
131+
"gcc")
132+
COMPILER_FULL_VERSION=$(${{ matrix.compiler.executable }} -dumpfullversion -dumpversion)
133+
;;
134+
"clang")
135+
COMPILER_FULL_VERSION=$(${{ matrix.compiler.executable }} -dumpversion)
136+
;;
137+
"msvc")
138+
COMPILER_FULL_VERSION=$(powershell -NoProfile -Command "(Get-Command ${{ matrix.compiler.executable }}).FileVersionInfo.FileVersion")
139+
;;
140+
esac
141+
echo "COMPILER_FULL_VERSION=$COMPILER_FULL_VERSION"
142+
echo "compiler-full-version=$COMPILER_FULL_VERSION" >> "$GITHUB_OUTPUT"
143+
144+
- name: Cache CMake Dependencies (restore)
145+
id: cache-deps
146+
uses: actions/cache/restore@v4
147+
with:
148+
key: deps-${{ matrix.os.name }}-${{ matrix.os.version }}-${{ matrix.compiler.toolset }}-${{ steps.env-info.outputs.compiler-full-version }}-${{ matrix.cpp_version.name }}-${{ matrix.build_type.name }}
149+
path: ${{ github.workspace }}/build/_deps
150+
151+
# Adapt CMP0168; enable caching in CI
152+
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_FULLY_DISCONNECTED
153+
- name: Setup Cached CMake Dependencies
154+
id: deps-info
155+
shell: bash
156+
run: |
157+
if [ "${{ steps.cache-deps.outputs.cache-hit }}" = "true" ]; then
158+
echo "IRIS_CMAKE_ARGS=-DFETCHCONTENT_FULLY_DISCONNECTED=ON" >> "$GITHUB_OUTPUT"
159+
else
160+
echo "IRIS_CMAKE_ARGS=" >> "$GITHUB_OUTPUT"
161+
fi
162+
163+
- name: Configure
164+
shell: bash
165+
run: |
166+
set -xe
167+
cmake ${{ steps.deps-info.outputs.IRIS_CMAKE_ARGS }} -B build \
168+
-DCMAKE_CXX_COMPILER=${{ matrix.compiler.executable }} \
169+
-DCMAKE_CXX_FLAGS="${{ matrix.compiler.cxxflags }}" \
170+
-DCMAKE_CXX_STANDARD=${{ matrix.cpp_version.number }} \
171+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type.name }} \
172+
-S .
173+
174+
- name: Build Tests
175+
run: |
176+
cmake --build build --config ${{ matrix.build_type.name }} -j${{ env.IRIS_BUILD_JOBS }} ${{ matrix.compiler.builder_additional_args }}
177+
178+
- name: Cache CMake Dependencies (save)
179+
if: steps.cache-deps.outputs.cache-hit != 'true'
180+
uses: actions/cache/save@v4
181+
with:
182+
key: ${{ steps.cache-deps.outputs.cache-primary-key }}
183+
path: ${{ github.workspace }}/build/_deps
184+
185+
- name: Test
186+
env:
187+
CLICOLOR_FORCE: 1
188+
working-directory: ${{ github.workspace }}/build
189+
run: ctest --output-on-failure -C ${{ matrix.build_type.name }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
/build*/
3+

CMakeLists.txt

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
cmake_minimum_required(VERSION 3.30)
4+
5+
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
6+
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
7+
endif()
8+
9+
project(iris VERSION 0.0.1 LANGUAGES CXX)
10+
11+
12+
# -----------------------------------------------------------------
13+
# Global settings
14+
# Handle with care, keep these to the ones that can't be
15+
# accomplished by target-specific settings.
16+
17+
set(CMAKE_COLOR_DIAGNOSTICS ON)
18+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
19+
20+
option(IRIS_REMOVE_MINSIZEREL_CONFIG "Remove rarely used MinSizeRel config" ON)
21+
22+
if(MSVC)
23+
if(IRIS_REMOVE_MINSIZEREL_CONFIG OR PROJECT_IS_TOP_LEVEL)
24+
list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES MinSizeRel)
25+
endif()
26+
endif()
27+
28+
29+
# -----------------------------------------------------------------
30+
# Create common base targets
31+
32+
# Iris-specific common target
33+
add_library(_iris_cxx_common INTERFACE)
34+
set_target_properties(_iris_cxx_common PROPERTIES CXX_EXTENSIONS OFF)
35+
36+
37+
# -----------------------------------------------------------------
38+
# Create the main Iris target
39+
40+
if(MSVC)
41+
# This needs to be `OBJECT` target to set correct `/std:` flags on IDE
42+
add_library(iris OBJECT EXCLUDE_FROM_ALL)
43+
set_target_properties(iris PROPERTIES LINKER_LANGUAGE CXX)
44+
45+
target_sources(
46+
iris
47+
PRIVATE
48+
# "${PROJECT_SOURCE_DIR}/cpp.hint" # TODO
49+
# "${PROJECT_SOURCE_DIR}/iris.natvis" # TODO
50+
)
51+
52+
target_link_libraries(iris PUBLIC _iris_cxx_common)
53+
54+
else()
55+
add_library(iris INTERFACE)
56+
target_link_libraries(iris INTERFACE _iris_cxx_common)
57+
endif()
58+
59+
add_library(Iris::Iris ALIAS iris)
60+
set_target_properties(iris PROPERTIES CXX_EXTENSIONS OFF)
61+
62+
63+
# -----------------------------------------------------------------
64+
# Configure C++ version
65+
#
66+
# Set minimal C++ version to `/std:c++XXpreview` and avoid `/std:c++latest`
67+
# if the user explicitly specifies `-DCMAKE_CXX_STANDARD=XX`.
68+
69+
set(IRIS_CXX_VERSION_BEFORE_LATEST 23)
70+
set(IRIS_CXX_VERSION_LATEST 26)
71+
72+
if(DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS ${IRIS_CXX_VERSION_BEFORE_LATEST})
73+
message(FATAL_ERROR "Too old C++ version `${CMAKE_CXX_STANDARD}`; the minimal version supported by Iris is `${IRIS_CXX_VERSION_BEFORE_LATEST}`.")
74+
endif()
75+
76+
if(MSVC)
77+
if(CMAKE_CXX_STANDARD EQUAL ${IRIS_CXX_VERSION_BEFORE_LATEST})
78+
set(CMAKE_CXX${IRIS_CXX_VERSION_BEFORE_LATEST}_STANDARD_COMPILE_OPTION /std:c++${IRIS_CXX_VERSION_BEFORE_LATEST}preview)
79+
set(CMAKE_CXX${IRIS_CXX_VERSION_BEFORE_LATEST}_EXTENSION_COMPILE_OPTION /std:c++${IRIS_CXX_VERSION_BEFORE_LATEST}preview)
80+
target_compile_options(_iris_cxx_common INTERFACE /std:c++${IRIS_CXX_VERSION_BEFORE_LATEST}preview)
81+
82+
else()
83+
# MSVC's CMake support does not provide the latest `cxx_std_XX`
84+
# feature until the very last stage of the implementation. Instead,
85+
# the feature number that is one version behind the latest usually
86+
# resolves to `/std:c++latest`.
87+
target_compile_features(_iris_cxx_common INTERFACE cxx_std_${IRIS_CXX_VERSION_BEFORE_LATEST})
88+
endif()
89+
90+
else() # Non-MSVC
91+
if(DEFINED CMAKE_CXX_STANDARD)
92+
target_compile_features(_iris_cxx_common INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
93+
else()
94+
target_compile_features(_iris_cxx_common INTERFACE cxx_std_${IRIS_CXX_VERSION_LATEST})
95+
endif()
96+
endif()
97+
98+
unset(IRIS_CXX_VERSION_BEFORE_LATEST)
99+
unset(IRIS_CXX_FEATURE_BEFORE_LATEST)
100+
101+
102+
# -----------------------------------------------------------------
103+
# Advanced compile/link settings
104+
105+
if(MSVC)
106+
# Don't set too strict flags for testing! They must go to `iris_cxx_test`.
107+
# ABI-dependent configurations MUST be set here.
108+
target_compile_definitions(
109+
_iris_cxx_common
110+
INTERFACE UNICODE _UNICODE
111+
)
112+
target_compile_options(
113+
_iris_cxx_common
114+
INTERFACE
115+
/EHsc /MP /utf-8 /Zc:preprocessor /permissive-
116+
# $<$<CONFIG:Debug,RelWithDebInfo>:/fsanitize=address> # TODO
117+
)
118+
target_link_options(
119+
_iris_cxx_common
120+
INTERFACE
121+
# $<$<CONFIG:Debug,RelWithDebInfo>:/INCREMENTAL:NO> # TODO
122+
)
123+
124+
else()
125+
target_compile_options(
126+
_iris_cxx_common
127+
INTERFACE
128+
# $<$<CONFIG:Debug>:-fsanitize=undefined,address> # TODO
129+
)
130+
target_link_options(
131+
_iris_cxx_common
132+
INTERFACE
133+
# $<$<CONFIG:Debug>:-fsanitize=undefined,address> # TODO
134+
)
135+
endif()
136+
137+
138+
# -----------------------------------------------------------------
139+
# Configure Iris main target
140+
141+
file(
142+
GLOB_RECURSE IRIS_HEADERS
143+
${PROJECT_SOURCE_DIR}/include/iris/*.hpp
144+
${PROJECT_SOURCE_DIR}/include/iris/*.ipp
145+
)
146+
147+
target_sources(iris PRIVATE FILE_SET HEADERS TYPE HEADERS FILES ${IRIS_HEADERS})
148+
source_group(TREE ${PROJECT_SOURCE_DIR}/include/iris PREFIX iris FILES ${IRIS_HEADERS})
149+
target_include_directories(iris INTERFACE ${PROJECT_SOURCE_DIR}/include)
150+
151+
152+
# -----------------------------------------------------------------
153+
# Test
154+
155+
if(PROJECT_IS_TOP_LEVEL)
156+
include(CTest)
157+
endif()
158+
159+
if(BUILD_TESTING)
160+
add_subdirectory(test)
161+
162+
if(MSVC AND PROJECT_IS_TOP_LEVEL)
163+
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Iris::Iris)
164+
endif()
165+
endif()

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2026 iris-cpp
3+
Copyright (c) 2026 The Iris Project Contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)