fix: C++17 mode on Clang may error

This commit is contained in:
Henry Schreiner 2020-07-23 22:55:29 -04:00 committed by Henry Schreiner
parent e428a7f6b8
commit 1f53c373e4
7 changed files with 56 additions and 3 deletions

View File

@ -152,10 +152,10 @@ function(pybind11_enable_warnings target_name)
endif() endif()
endif() endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0) if(CMAKE_CXX_STANDARD AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0)
if(CMAKE_CXX_STANDARD STREQUAL "14") if(CMAKE_CXX_STANDARD LESS 17)
target_compile_options(${target_name} PUBLIC -Wno-deprecated-register) target_compile_options(${target_name} PUBLIC -Wno-deprecated-register)
elseif(NOT CMAKE_CXX_STANDARD VERSION_LESS 17) else()
target_compile_options(${target_name} PUBLIC -Wno-register) target_compile_options(${target_name} PUBLIC -Wno-register)
endif() endif()
endif() endif()

View File

@ -8,8 +8,17 @@ message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
add_executable(test_cmake_build ../embed.cpp) add_executable(test_cmake_build ../embed.cpp)
target_link_libraries(test_cmake_build PRIVATE pybind11::embed) target_link_libraries(test_cmake_build PRIVATE pybind11::embed)
# Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::embed). # Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::embed).
# This may be needed to resolve header conflicts, e.g. between Python release and debug headers. # This may be needed to resolve header conflicts, e.g. between Python release and debug headers.
set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON) set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
add_custom_target(check $<TARGET_FILE:test_cmake_build> ${PROJECT_SOURCE_DIR}/../test.py) add_custom_target(check $<TARGET_FILE:test_cmake_build> ${PROJECT_SOURCE_DIR}/../test.py)
if(CMAKE_CXX_STANDARD AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0)
if(CMAKE_CXX_STANDARD LESS 17)
target_compile_options(test_cmake_build PUBLIC -Wno-deprecated-register)
else()
target_compile_options(test_cmake_build PUBLIC -Wno-register)
endif()
endif()

View File

@ -20,3 +20,11 @@ set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build> add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME}) ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME})
if(CMAKE_CXX_STANDARD AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0)
if(CMAKE_CXX_STANDARD LESS 17)
target_compile_options(test_cmake_build PUBLIC -Wno-deprecated-register)
else()
target_compile_options(test_cmake_build PUBLIC -Wno-register)
endif()
endif()

View File

@ -23,3 +23,13 @@ install(TARGETS test_embed_lib
RUNTIME DESTINATION lib) RUNTIME DESTINATION lib)
install(EXPORT test_export install(EXPORT test_export
DESTINATION lib/cmake/test_export/test_export-Targets.cmake) DESTINATION lib/cmake/test_export/test_export-Targets.cmake)
if(CMAKE_CXX_STANDARD AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0)
if(CMAKE_CXX_STANDARD LESS 17)
target_compile_options(test_embed_lib PUBLIC -Wno-deprecated-register)
target_compile_options(test_cmake_build PUBLIC -Wno-deprecated-register)
else()
target_compile_options(test_embed_lib PUBLIC -Wno-register)
target_compile_options(test_cmake_build PUBLIC -Wno-register)
endif()
endif()

View File

@ -13,3 +13,11 @@ set_target_properties(test_cmake_build PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX
add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build> add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME}) ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME})
if(CMAKE_CXX_STANDARD AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0)
if(CMAKE_CXX_STANDARD LESS 17)
target_compile_options(test_cmake_build PUBLIC -Wno-deprecated-register)
else()
target_compile_options(test_cmake_build PUBLIC -Wno-register)
endif()
endif()

View File

@ -43,3 +43,13 @@ endforeach()
add_dependencies(cpptest external_module) add_dependencies(cpptest external_module)
add_dependencies(check cpptest) add_dependencies(check cpptest)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0)
if(CMAKE_CXX_STANDARD LESS 17)
target_compile_options(test_embed PUBLIC -Wno-deprecated-register)
target_compile_options(external_module PUBLIC -Wno-deprecated-register)
else()
target_compile_options(test_embed PUBLIC -Wno-register)
target_compile_options(external_module PUBLIC -Wno-register)
endif()
endif()

View File

@ -224,6 +224,14 @@ function(pybind11_add_module target_name)
endif() endif()
endif() endif()
# Python 2 doesn't really support C++17, Clang warns/errors over it
if(CMAKE_CXX_STANDARD
AND CMAKE_CXX_COMPILER_ID MATCHES "Clang"
AND PYTHON_VERSION VERSION_LESS 3.0
AND NOT CMAKE_CXX_STANDARD LESS 17)
target_compile_options(${target_name} PUBLIC -Wno-register)
endif()
if(ARG_NO_EXTRAS) if(ARG_NO_EXTRAS)
return() return()
endif() endif()