From b768df6fe2a21780f453bf7f822192011739e076 Mon Sep 17 00:00:00 2001 From: jatin Date: Mon, 10 Jul 2023 13:58:36 -0700 Subject: [PATCH 1/4] Adding compile test for version macros --- CMakeLists.txt | 4 ++++ src/main.cc | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c386acf0..8773c35f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,10 @@ if (${CLAP_BUILD_TESTS}) add_test(NAME test-clap-compile-${SUFFIX} COMMAND clap-compile-${SUFFIX}) add_dependencies(clap-tests clap-compile-${SUFFIX}) + if (${EXT} STREQUAL "cc") + target_compile_definitions(clap-compile-${SUFFIX} PRIVATE CLAP_COMPILE_TEST_CXX_VERSION=${STDCPP}) + endif() + if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang") target_compile_options(clap-compile-${SUFFIX} PRIVATE -Wall -Wextra -pedantic) endif() diff --git a/src/main.cc b/src/main.cc index 949d0bb8..80febfba 100644 --- a/src/main.cc +++ b/src/main.cc @@ -48,6 +48,18 @@ #error CLAP_VERSION_LT is inconsistent (REVISION) #endif +#if (CLAP_COMPILE_TEST_CXX_VERSION >= 11) && ! defined(CLAP_HAS_CXX11) +#error CLAP_HAS_CXX11 is not defined correctly +#endif + +#if (CLAP_COMPILE_TEST_CXX_VERSION >= 17) && ! defined(CLAP_HAS_CXX17) +#error CLAP_HAS_CXX17 is not defined correctly +#endif + +#if (CLAP_COMPILE_TEST_CXX_VERSION >= 20) && ! defined(CLAP_HAS_CXX20) +#error CLAP_HAS_CXX20 is not defined correctly +#endif + static const CLAP_CONSTEXPR clap_version m = CLAP_VERSION; int main(int, char **) { From 5c8b26d06ff67f580c9d0449bf697cba50d87a43 Mon Sep 17 00:00:00 2001 From: jatin Date: Mon, 10 Jul 2023 14:05:22 -0700 Subject: [PATCH 2/4] Trying to get msvc build happening on CI --- .github/workflows/cmake.yml | 11 ++++++++++- CMakePresets.json | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 88040a96..7b9ccd9a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -39,8 +39,17 @@ jobs: - name: Run CMake+Ninja+CTest to generate/build/test. uses: lukka/run-cmake@v10 - id: runcmake + id: runcmake-ninja with: configurePreset: 'ninja' buildPreset: 'ninja-release' testPreset: 'ninja-release' + + - name: Run CMake+MSVC+CTest to generate/build/test. + uses: lukka/run-cmake@v10 + if: startsWith(matrix.os, 'win') + id: runcmake-msvc + with: + configurePreset: 'msvc' + buildPreset: 'msvc-release' + testPreset: 'msvc-release' diff --git a/CMakePresets.json b/CMakePresets.json index d707bfb9..bd0b1c51 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -22,6 +22,23 @@ "value": true } } + }, + { + "name": "msvc", + "displayName": "MSVC", + "description": "Configure and generate MSVC project files for all configurations", + "binaryDir": "${sourceDir}/builds/${presetName}", + "generator": "Visual Studio 17 2022", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": { + "type": "boolean", + "value": true + }, + "CLAP_BUILD_TESTS": { + "type": "boolean", + "value": true + } + } } ], "buildPresets": [ @@ -32,6 +49,14 @@ "description": "Build ninja Release configuration", "configuration": "RelWithDebInfo", "targets": ["clap-tests"] + }, + { + "name": "msvc-release", + "configurePreset": "msvc", + "displayName": "Build msvc-release", + "description": "Build msvc Release configuration", + "configuration": "RelWithDebInfo", + "targets": ["clap-tests"] } ], "testPresets": [ @@ -39,6 +64,11 @@ "name": "ninja-release", "configurePreset": "ninja", "configuration": "RelWithDebInfo" + }, + { + "name": "msvc-release", + "configurePreset": "msvc", + "configuration": "RelWithDebInfo" } ] } \ No newline at end of file From d23d576a9d96f23c58b529d803053333ac127918 Mon Sep 17 00:00:00 2001 From: jatin Date: Mon, 10 Jul 2023 14:12:37 -0700 Subject: [PATCH 3/4] Add MSVC bypass for getting C++ version macro --- include/clap/private/macros.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/clap/private/macros.h b/include/clap/private/macros.h index 15b6b1b3..0281de23 100644 --- a/include/clap/private/macros.h +++ b/include/clap/private/macros.h @@ -25,20 +25,28 @@ # endif #endif -#if defined(__cplusplus) && __cplusplus >= 201103L +#if defined(__cplusplus) +# if MSVC +# define CLAP_CPLUSPLUS _MSVC_LANG +# else +# define CLAP_CPLUSPLUS __cplusplus +# endif +#endif + +#if defined(CLAP_CPLUSPLUS) && CLAP_CPLUSPLUS >= 201103L # define CLAP_HAS_CXX11 # define CLAP_CONSTEXPR constexpr #else # define CLAP_CONSTEXPR #endif -#if defined(__cplusplus) && __cplusplus >= 201703L +#if defined(CLAP_CPLUSPLUS) && CLAP_CPLUSPLUS >= 201703L # define CLAP_HAS_CXX17 # define CLAP_NODISCARD [[nodiscard]] #else # define CLAP_NODISCARD #endif -#if defined(__cplusplus) && __cplusplus >= 202002L +#if defined(CLAP_CPLUSPLUS) && CLAP_CPLUSPLUS >= 202002L # define CLAP_HAS_CXX20 #endif From e661d1caa56deac3dc207af2445738b93e84e5a0 Mon Sep 17 00:00:00 2001 From: Jatin Chowdhury Date: Mon, 10 Jul 2023 14:32:43 -0700 Subject: [PATCH 4/4] Different strategy for definitions check --- include/clap/private/macros.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/clap/private/macros.h b/include/clap/private/macros.h index 0281de23..ba1d6656 100644 --- a/include/clap/private/macros.h +++ b/include/clap/private/macros.h @@ -25,12 +25,10 @@ # endif #endif -#if defined(__cplusplus) -# if MSVC -# define CLAP_CPLUSPLUS _MSVC_LANG -# else -# define CLAP_CPLUSPLUS __cplusplus -# endif +#if defined(_MSVC_LANG) +# define CLAP_CPLUSPLUS _MSVC_LANG +#elif defined(__cplusplus) +# define CLAP_CPLUSPLUS __cplusplus #endif #if defined(CLAP_CPLUSPLUS) && CLAP_CPLUSPLUS >= 201103L