mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
fix: C++17 mode on Clang may error
This commit is contained in:
parent
e428a7f6b8
commit
1f53c373e4
@ -152,10 +152,10 @@ function(pybind11_enable_warnings target_name)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0)
|
||||
if(CMAKE_CXX_STANDARD STREQUAL "14")
|
||||
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(${target_name} PUBLIC -Wno-deprecated-register)
|
||||
elseif(NOT CMAKE_CXX_STANDARD VERSION_LESS 17)
|
||||
else()
|
||||
target_compile_options(${target_name} PUBLIC -Wno-register)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -8,8 +8,17 @@ message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
|
||||
add_executable(test_cmake_build ../embed.cpp)
|
||||
target_link_libraries(test_cmake_build PRIVATE 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.
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
|
||||
${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
|
||||
RUNTIME DESTINATION lib)
|
||||
install(EXPORT test_export
|
||||
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
|
||||
|
||||
add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
|
||||
${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()
|
||||
add_dependencies(cpptest external_module)
|
||||
|
||||
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)
|
||||
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)
|
||||
return()
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user