Skip to content

Fix compilation of tests with /std:c++17 #2292

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

Closed
Closed
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@ platform:
environment:
matrix:
- PYTHON: 36
CPP: 14
CPP: 17
CONFIG: Debug
- PYTHON: 27
CPP: 14
CPP: 17
CONFIG: Debug
- CONDA: 36
CPP: latest
CPP: 17
CONFIG: Release
matrix:
exclude:
- image: Visual Studio 2015
platform: x86
- image: Visual Studio 2015
CPP: latest
CPP: 17
- image: Visual Studio 2017
CPP: latest
CPP: 17
platform: x86
install:
- ps: |
if ($env:PLATFORM -eq "x64") { $env:CMAKE_ARCH = "x64" }
if ($env:APPVEYOR_JOB_NAME -like "*Visual Studio 2017*") {
$env:CMAKE_GENERATOR = "Visual Studio 15 2017"
$env:CMAKE_INCLUDE_PATH = "C:\Libraries\boost_1_64_0"
$env:CXXFLAGS = "-permissive-"
} else {
$env:CMAKE_GENERATOR = "Visual Studio 14 2015"
}
Expand All @@ -57,14 +56,15 @@ install:
7z x 3.3.3.zip -y > $null
$env:CMAKE_INCLUDE_PATH = "eigen-eigen-67e894c6cd8f;$env:CMAKE_INCLUDE_PATH"
build_script:
- set VERBOSE=1
- cmake --version
- cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%"
-DPYBIND11_CPP_STANDARD=/std:c++%CPP%
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DCMAKE_SUPPRESS_REGENERATION=1
.
- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
- cmake --build . --config %CONFIG% --target pytest -- /m /v:m /logger:%MSBuildLogger%
- cmake --build . --config %CONFIG% --target cpptest -- /m /v:m /logger:%MSBuildLogger%
- if "%CPP%"=="latest" (cmake --build . --config %CONFIG% --target test_cmake_build -- /m /v:m /logger:%MSBuildLogger%)
- cmake --build . --config %CONFIG% --target pytest -- /m /logger:%MSBuildLogger%
- cmake --build . --config %CONFIG% --target cpptest -- /m /logger:%MSBuildLogger%
- if "%CPP%"=="17" (cmake --build . --config %CONFIG% --target test_cmake_build -- /m /logger:%MSBuildLogger%)
on_failure: if exist "tests\test_cmake_build" type tests\test_cmake_build\*.log*
2 changes: 1 addition & 1 deletion tools/pybind11Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if(NOT TARGET ${PN}::pybind11)
set_property(TARGET ${PN}::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
endif()

if(CMAKE_VERSION VERSION_LESS 3.3)
if(CMAKE_VERSION VERSION_LESS 3.3 OR CMAKE_GENERATOR MATCHES "Visual Studio")
set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "${PYBIND11_CPP_STANDARD}")
else()
set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CXX>:${PYBIND11_CPP_STANDARD}>)
Expand Down
10 changes: 7 additions & 3 deletions tools/pybind11Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ include(CMakeParseArguments)

# Use the language standards abstraction if CMake supports it with the current compiler
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
if(NOT CMAKE_CXX_STANDARD)
if(NOT CMAKE_CXX_STANDARD AND NOT PYBIND11_CPP_STANDARD)
if(CMAKE_CXX14_STANDARD_COMPILE_OPTION)
set(CMAKE_CXX_STANDARD 14)
elseif(CMAKE_CXX11_STANDARD_COMPILE_OPTION)
Expand Down Expand Up @@ -56,6 +56,8 @@ if(NOT PYBIND11_CPP_STANDARD AND NOT CMAKE_CXX_STANDARD)
"C++ standard flag, e.g. -std=c++11, -std=c++14, /std:c++14. Defaults to C++14 mode." FORCE)
endif()

message(PYBIND11_CPP_STANDARD = ${PYBIND11_CPP_STANDARD})

# Checks whether the given CXX/linker flags can compile and link a cxx file. cxxflags and
# linkerflags are lists of flags to use. The result variable is a unique variable name for each set
# of flags: the compilation result will be cached base on the result variable. If the flags work,
Expand Down Expand Up @@ -217,9 +219,11 @@ function(pybind11_add_module target_name)

# Make sure C++11/14 are enabled
if(PYBIND11_CPP_STANDARD)
if(CMAKE_VERSION VERSION_LESS 3.3)
if(CMAKE_VERSION VERSION_LESS 3.3 OR CMAKE_GENERATOR MATCHES "Visual Studio")
message("HERE, I hope?")
target_compile_options(${target_name} PUBLIC ${PYBIND11_CPP_STANDARD})
else()
message("NOT HERE, I hope?")
target_compile_options(${target_name} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:${PYBIND11_CPP_STANDARD}>)
endif()
endif()
Expand Down Expand Up @@ -247,7 +251,7 @@ function(pybind11_add_module target_name)
# /MP enables multithreaded builds (relevant when there are many files), /bigobj is
# needed for bigger binding projects due to the limit to 64k addressable sections
target_compile_options(${target_name} PRIVATE /bigobj)
if(CMAKE_VERSION VERSION_LESS 3.11)
if(CMAKE_VERSION VERSION_LESS 3.11 OR CMAKE_GENERATOR MATCHES "Visual Studio")
target_compile_options(${target_name} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/MP>)
else()
# Only set these options for C++ files. This is important so that, for
Expand Down