diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 65e35bb..115a559 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -16,45 +16,62 @@ jobs: fail-fast: false # Set up a matrix to run the following 3 configurations: - # 1. - # 2. - # 3. + # 1. + # 2. + # 3. + # 4. # # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - runner: [ubuntu-26.04, windows-2025-vs2026] + runner: [ubuntu-26.04, windows-2025-vs2026, macos-26-intel] build_type: [Release] - c_compiler: [gcc-15, clang-22, cl] + toolchain: [gnu, llvm, msvc, xcode] include: - - runner: windows-2025-vs2026 - os: Windows - c_compiler: cl - cpp_compiler: cl - runner: ubuntu-26.04 + toolchain: gnu c_compiler: gcc-15 cpp_compiler: g++-15 - runner: ubuntu-26.04 + toolchain: llvm c_compiler: clang-22 cpp_compiler: clang++-22 + - runner: macos-26-intel + toolchain: llvm + c_compiler: /usr/local/opt/llvm@20/bin/clang + cpp_compiler: /usr/local/opt/llvm@20/bin/clang++ + - runner: windows-2025-vs2026 + toolchain: msvc + c_compiler: cl + cpp_compiler: cl exclude: + - runner: ubuntu-26.04 + toolchain: xcode + - runner: ubuntu-26.04 + toolchain: msvc + - runner: macos-26-intel + toolchain: gnu + - runner: macos-26-intel + toolchain: xcode # xcode lacking clang-scan-deps + - runner: macos-26-intel + toolchain: msvc - runner: windows-2025-vs2026 - c_compiler: gcc-15 + toolchain: gnu - runner: windows-2025-vs2026 - c_compiler: clang-22 - - runner: ubuntu-26.04 - c_compiler: cl + toolchain: llvm + - runner: windows-2025-vs2026 + toolchain: xcode steps: - uses: actions/checkout@v5 - - name: Install libc++ for Clang + - name: Install libc++ for Clang-22 if: matrix.c_compiler == 'clang-22' run: | sudo apt-get update sudo apt-get install -y clang-22 clang-tools-22 libc++-22-dev libc++abi-22-dev - uses: ilammy/msvc-dev-cmd@v1 - if: matrix.c_compiler == 'cl' + if: matrix.toolchain == 'msvc' with: arch: x64 @@ -65,31 +82,51 @@ jobs: run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - case "${{ matrix.c_compiler }}" in - gcc*) + # conan_compiler and conan_compiler_version + + case "${{ matrix.toolchain }}" in + gnu) conan_compiler=gcc + conan_compiler_version=$(${{ matrix.c_compiler }} -dumpversion | cut -d. -f1) ;; - clang*) + llvm) conan_compiler=clang + conan_compiler_version=$(${{ matrix.c_compiler }} -dumpversion | cut -d. -f1) + ;; + xcode) + conan_compiler=apple-clang + conan_compiler_version=$(${{ matrix.c_compiler }} -dumpversion | cut -d. -f1) ;; - cl) + msvc) conan_compiler=msvc + conan_compiler_version=195 + ;; + *) + echo "Invalid toolchain: ${{ matrix.toolchain }}" + exit 1 ;; esac echo "conan_compiler=$conan_compiler" >> "$GITHUB_OUTPUT" + echo "conan_compiler_version=$conan_compiler_version" >> "$GITHUB_OUTPUT" - case "${{ matrix.c_compiler }}" in - gcc*) - conan_compiler_version=$(${{ matrix.c_compiler }} -dumpversion | cut -d. -f1) + # conan_os + + case "${RUNNER_OS}" in + Linux) + conan_os=Linux ;; - clang*) - conan_compiler_version=$(${{ matrix.c_compiler }} -dumpversion | cut -d. -f1) + macOS) + conan_os=Macos ;; - cl) - conan_compiler_version=195 + Windows) + conan_os=Windows + ;; + *) + echo "Invalid os: ${RUNNER_OS}" + exit 1 ;; esac - echo "conan_compiler_version=$conan_compiler_version" >> "$GITHUB_OUTPUT" + echo "conan_os=$conan_os" >> "$GITHUB_OUTPUT" - name: Create Conan Dependencies Profile shell: bash @@ -97,12 +134,13 @@ jobs: cat << EOF > profile.txt [settings] arch=x86_64 - os=$RUNNER_OS + os=${{ steps.strings.outputs.conan_os }} compiler=${{ steps.strings.outputs.conan_compiler }} compiler.version=${{ steps.strings.outputs.conan_compiler_version }} compiler.cppstd=23 $([[ "${{ steps.strings.outputs.conan_compiler }}" == "gcc" ]] && echo "compiler.libcxx=libstdc++11") $([[ "${{ steps.strings.outputs.conan_compiler }}" == "clang" ]] && echo "compiler.libcxx=libc++") + $([[ "${{ steps.strings.outputs.conan_compiler }}" == "apple-clang" ]] && echo "compiler.libcxx=libc++") $([[ "${{ steps.strings.outputs.conan_compiler }}" == "msvc" ]] && echo "compiler.runtime=static") [buildenv] @@ -141,7 +179,6 @@ jobs: . - name: Build - # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). run: > cmake --build ${{ steps.strings.outputs.build-output-dir }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 35fd7db..28c912e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,10 +27,17 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # problematic in github CI set(CMAKE_CXX_MODULE_STD OFF) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + # not supported + set(CMAKE_CXX_MODULE_STD OFF) else() set(CMAKE_CXX_MODULE_STD ON) endif() +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + + # Options option(ENABLE_EIGEN "Add Eigen support?" OFF) option(ENABLE_CUDA "Add Cuda support?" OFF) diff --git a/README.md b/README.md index ec85836..10a887b 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Template project for C++20/23 module support in CMake. For more information see ### Tools * cmake>=3.26 +* conan>=2.29.0 * ninja>=1.11.1 ### Compilers @@ -86,7 +87,10 @@ One of: ## Build and Test -### Clang +> [!NOTE] +> This project uses a cononcial conan-driven buildchain for building dependencies. A CMake driven approach using [cmake-conan](https://github.com/conan-io/cmake-conan) is possible with conan>=2. For more information, see: [conan CMake integrations](https://docs.conan.io/2/integrations/cmake.html) and [conan/issues/17361](https://github.com/conan-io/conan/issues/17361) + +### LLVM ```bash export CONAN_PROFILE=profile-clang-.txt @@ -118,9 +122,7 @@ cmake --build build/gcc --config Release -j8 ctest -preset=${CONAN_PROFILE} --no-compress-output --verbose ``` -## Dockerfile - -### Clang +### Docker LLVM ```bash # build @@ -129,7 +131,7 @@ docker build -t cmake-cpp-modules-template-clang -f docker/Dockerfile-clang . docker run --security-opt seccomp=unconfined -it --rm cmake-cpp-modules-template-clang ``` -### GNU +### Docker GNU ```bash # build diff --git a/targets/cpp-deps-modules/libcxx/CMakeLists.txt b/targets/cpp-deps-modules/libcxx/CMakeLists.txt index 0a10811..75ca664 100644 --- a/targets/cpp-deps-modules/libcxx/CMakeLists.txt +++ b/targets/cpp-deps-modules/libcxx/CMakeLists.txt @@ -7,15 +7,12 @@ cmake_minimum_required(VERSION 3.26) set(TARGET_NAME libcxx) add_library(${TARGET_NAME}) -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(${TARGET_NAME} PUBLIC $<$:-stdlib=libc++>) - target_link_options(${TARGET_NAME} PUBLIC $<$:-stdlib=libc++>) +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") target_compile_options(${TARGET_NAME} PUBLIC $<$:-Wmodule-conflict>) endif() target_compile_definitions(${TARGET_NAME} PRIVATE CXX_MODULE_STD=$) target_compile_definitions(${TARGET_NAME} PRIVATE _LIBCPP_USING_IF_EXISTS=) -target_compile_definitions(${TARGET_NAME} PRIVATE _LIBCPP_STD_VER=23) target_compile_definitions(${TARGET_NAME} PRIVATE _LIBCPP_HAS_LOCALIZATION=1) target_compile_definitions(${TARGET_NAME} PRIVATE _LIBCPP_HAS_WIDE_CHARACTERS=1) target_compile_definitions(${TARGET_NAME} PRIVATE _LIBCPP_HAS_THREADS=1) diff --git a/targets/cpp-deps-modules/libcxx/std.cppm b/targets/cpp-deps-modules/libcxx/std.cppm index d47fe1e..31313d9 100644 --- a/targets/cpp-deps-modules/libcxx/std.cppm +++ b/targets/cpp-deps-modules/libcxx/std.cppm @@ -73,7 +73,9 @@ export import std; #include #include #include +#if __has_include() #include +#endif // __has_include() #include #include #include diff --git a/targets/cpp-deps-modules/libcxx/std/algorithm.inc b/targets/cpp-deps-modules/libcxx/std/algorithm.inc index b6821e0..2095a8f 100644 --- a/targets/cpp-deps-modules/libcxx/std/algorithm.inc +++ b/targets/cpp-deps-modules/libcxx/std/algorithm.inc @@ -20,7 +20,7 @@ export namespace std { using std::ranges::in_value_result; #endif using std::ranges::min_max_result; -#if _LIBCPP_STD_VER >= 23 +#if _LIBCPP_STD_VER >= 23 && __cpp_lib_ranges >= 202406L using std::ranges::out_value_result; #endif } // namespace ranges