From 4b39b79ca2c6fbbbdbe80716994b93387c0aa299 Mon Sep 17 00:00:00 2001 From: Christos Tsolakis Date: Mon, 15 Apr 2024 14:16:11 -0700 Subject: [PATCH 1/4] Add test for c++17 and This test fails currently on windows with MSVC --- unittests/data/cpp_standard_17.hpp | 9 +++++++++ unittests/test_cpp_standards.py | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 unittests/data/cpp_standard_17.hpp diff --git a/unittests/data/cpp_standard_17.hpp b/unittests/data/cpp_standard_17.hpp new file mode 100644 index 00000000..b336a9aa --- /dev/null +++ b/unittests/data/cpp_standard_17.hpp @@ -0,0 +1,9 @@ +// Copyright 2014-2017 Insight Software Consortium. +// Copyright 2004-2009 Roman Yakovenko. +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See https://github.com/CastXML/pygccxml/issues/180 +// variant introduced in C++17 +#include +std::variant value; diff --git a/unittests/test_cpp_standards.py b/unittests/test_cpp_standards.py index 1eb5a3fb..711922fa 100644 --- a/unittests/test_cpp_standards.py +++ b/unittests/test_cpp_standards.py @@ -48,6 +48,15 @@ def test(self): RuntimeError, lambda: parser.parse(["cpp_standards.hpp"], self.config)) + def test_cpp17(self): + """ + Test c++17 by setting cflags. + + """ + + self.config.cflags = "-std=c++17" + parser.parse(["cpp_standard_17.hpp"], self.config) + def create_suite(): suite = unittest.TestSuite() From 1d35242b7fc78c0f10bfa364558f2b08b454d94b Mon Sep 17 00:00:00 2001 From: Christos Tsolakis Date: Mon, 15 Apr 2024 15:53:50 -0400 Subject: [PATCH 2/4] fix: Add ccflags and c++ standard in msvc arguments Previously the ccflags and cflags will be ingored if running on Windows --- src/pygccxml/parser/source_reader.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/pygccxml/parser/source_reader.py b/src/pygccxml/parser/source_reader.py index d864554b..7a7db075 100644 --- a/src/pygccxml/parser/source_reader.py +++ b/src/pygccxml/parser/source_reader.py @@ -140,21 +140,21 @@ def __create_command_line_castxml(self, source_file, xmlfile): # On mac or linux, use gcc or clang (the flag is the same) cmd.append('--castxml-cc-gnu ') - if self.__cxx_std.is_implicit: - std_flag = '' - else: - std_flag = ' ' + self.__cxx_std.stdcxx + ' ' + if self.__cxx_std.is_implicit: + std_flag = '' + else: + std_flag = ' ' + self.__cxx_std.stdcxx + ' ' - ccflags = self.__config.ccflags - if std_flag: - ccflags += std_flag + ccflags = self.__config.ccflags + if std_flag: + ccflags += std_flag - if ccflags: - all_cc_opts = self.__config.compiler_path + ' ' + ccflags - cmd.append( - '"(" ' + all_cc_opts + ' ")"') - else: - cmd.append(self.__config.compiler_path) + if ccflags: + all_cc_opts = f'"{self.__config.compiler_path}"' + ' ' + ccflags + cmd.append( + '"(" ' + all_cc_opts + ' ")"') + else: + cmd.append(f'"{self.__config.compiler_path}"') if self.__config.castxml_epic_version is not None: if self.__config.castxml_epic_version != 1: From 67bdfec28d832dc05d61e99bfcf8ef4187c42f0c Mon Sep 17 00:00:00 2001 From: Christos Tsolakis Date: Mon, 15 Apr 2024 15:54:33 -0400 Subject: [PATCH 3/4] source_reader: reorder msvc arguments move '--castxml-cc-msvc' after '-D_HAS_TR1=0' so that the subsequent code logic that builds the parenthesized arguments of '--castxml-cc-msvc' is right after. --- src/pygccxml/parser/source_reader.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pygccxml/parser/source_reader.py b/src/pygccxml/parser/source_reader.py index 7a7db075..f2d1cb9e 100644 --- a/src/pygccxml/parser/source_reader.py +++ b/src/pygccxml/parser/source_reader.py @@ -132,10 +132,9 @@ def __create_command_line_castxml(self, source_file, xmlfile): cmd.append('--castxml-cc-gnu ' + self.__config.compiler_path) else: # We are using msvc - cmd.append('--castxml-cc-msvc ' + - '"%s"' % self.__config.compiler_path) if self.__config.compiler == 'msvc9': cmd.append('"-D_HAS_TR1=0"') + cmd.append('--castxml-cc-msvc ') else: # On mac or linux, use gcc or clang (the flag is the same) cmd.append('--castxml-cc-gnu ') From 8186300c6de05d733ca055a3e6580417be5256ea Mon Sep 17 00:00:00 2001 From: Christos Tsolakis Date: Mon, 15 Apr 2024 16:05:08 -0400 Subject: [PATCH 4/4] source_reader: transform std=c++XX -> std:c++XX when using mscv see https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version --- src/pygccxml/parser/source_reader.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pygccxml/parser/source_reader.py b/src/pygccxml/parser/source_reader.py index f2d1cb9e..f64ae4e1 100644 --- a/src/pygccxml/parser/source_reader.py +++ b/src/pygccxml/parser/source_reader.py @@ -121,6 +121,7 @@ def __create_command_line_castxml(self, source_file, xmlfile): "your xml_generator_configuration_t(), or add it to your " + "pygccxml configuration file.")) + stdcxx_switch = self.__cxx_std.stdcxx # Platform specific options if platform.system() == 'Windows': compilers = ("mingw", "g++", "gcc") @@ -135,6 +136,8 @@ def __create_command_line_castxml(self, source_file, xmlfile): if self.__config.compiler == 'msvc9': cmd.append('"-D_HAS_TR1=0"') cmd.append('--castxml-cc-msvc ') + # msvc uses std:c++XX format instead of std=c++XX + stdcxx_switch = stdcxx_switch.replace('=', ':') else: # On mac or linux, use gcc or clang (the flag is the same) cmd.append('--castxml-cc-gnu ') @@ -142,7 +145,7 @@ def __create_command_line_castxml(self, source_file, xmlfile): if self.__cxx_std.is_implicit: std_flag = '' else: - std_flag = ' ' + self.__cxx_std.stdcxx + ' ' + std_flag = ' ' + stdcxx_switch + ' ' ccflags = self.__config.ccflags if std_flag: