Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of 'std=c++XX' with msvc #181

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
32 changes: 17 additions & 15 deletions src/pygccxml/parser/source_reader.py
Original file line number Diff line number Diff line change
@@ -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")
@@ -132,29 +133,30 @@ 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 ')
# 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 ')

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 = ' ' + stdcxx_switch + ' '

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:
9 changes: 9 additions & 0 deletions unittests/data/cpp_standard_17.hpp
Original file line number Diff line number Diff line change
@@ -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 <variant>
std::variant<int, double, float> value;
9 changes: 9 additions & 0 deletions unittests/test_cpp_standards.py
Original file line number Diff line number Diff line change
@@ -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()