From 86817db488c547816e21e20d678db318bb286384 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 4 Feb 2022 00:23:01 -0500 Subject: [PATCH] fix: add option for _ check, only define on pybind11 --- .github/workflows/ci.yml | 2 +- tests/CMakeLists.txt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b52c30618..6e03d9279 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: python: '3.6' args: > -DPYBIND11_FINDPYTHON=ON - -DCMAKE_CXX_FLAGS="-D_=1" + -DPYBIND11_DEFINE_UNDERSCORE=ON - runs-on: windows-latest python: '3.6' args: > diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9040cf8c0..77ff66385 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -81,6 +81,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../tools") option(PYBIND11_WERROR "Report all warnings as errors" OFF) option(DOWNLOAD_EIGEN "Download EIGEN (requires CMake 3.11+)" OFF) option(PYBIND11_CUDA_TESTS "Enable building CUDA tests (requires CMake 3.12+)" OFF) +option(PYBIND11_DEFINE_UNDERSCORE "Define the underscore to make sure it is safe" OFF) + set(PYBIND11_TEST_OVERRIDE "" CACHE STRING "Tests from ;-separated list of *.cpp files will be built instead of all tests") @@ -435,6 +437,9 @@ foreach(target ${test_targets}) # Create the binding library pybind11_add_module(${target} THIN_LTO ${target}.cpp ${test_files} ${PYBIND11_HEADERS}) pybind11_enable_warnings(${target}) + if(PYBIND11_DEFINE_UNDERSCORE) + target_compile_definitions(${target} PUBLIC -D_=1) + endif() if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) get_property(