Commit 1f53c373 by Henry Schreiner Committed by Henry Schreiner

fix: C++17 mode on Clang may error

parent e428a7f6
...@@ -152,10 +152,10 @@ function(pybind11_enable_warnings target_name) ...@@ -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()
......
...@@ -8,8 +8,17 @@ message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") ...@@ -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()
...@@ -20,3 +20,11 @@ set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON) ...@@ -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()
...@@ -23,3 +23,13 @@ install(TARGETS test_embed_lib ...@@ -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()
...@@ -13,3 +13,11 @@ set_target_properties(test_cmake_build PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX ...@@ -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()
...@@ -43,3 +43,13 @@ endforeach() ...@@ -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()
...@@ -224,6 +224,14 @@ function(pybind11_add_module target_name) ...@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment