diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c99cd4084b..3c9b063f77 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -491,13 +491,15 @@ foreach(target ${test_targets}) if(SKBUILD) install(TARGETS ${target} LIBRARY DESTINATION .) endif() -endforeach() -if(MSVC) - target_compile_options("exo_planet_c_api" PRIVATE /EHs-c-) -elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)") - target_compile_options("exo_planet_c_api" PRIVATE -fno-exceptions) -endif() + if("${target}" STREQUAL "exo_planet_c_api") + if(MSVC) + target_compile_options(${target} PRIVATE /EHs-c-) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang|NVHPC)") + target_compile_options(${target} PRIVATE -fno-exceptions) + endif() + endif() +endforeach() # Provide nice organisation in IDEs source_group( diff --git a/tests/exo_planet_c_api.cpp b/tests/exo_planet_c_api.cpp index 8dc574a22e..cf584c35f6 100644 --- a/tests/exo_planet_c_api.cpp +++ b/tests/exo_planet_c_api.cpp @@ -1,10 +1,15 @@ // Copyright (c) 2024 The pybind Community. -#ifdef __EXCEPTIONS -# error This test is meant to be built with C++ Exception Handling disabled. // In production situations it is totally fine to build with -// C++ Exception Handling enabled. Here we just want to ensure that +// C++ Exception Handling enabled. However, here we want to ensure that // C++ Exception Handling is not required. +#ifdef __cpp_exceptions +// https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations#__cpp_exceptions +# error This test is meant to be built with C++ Exception Handling disabled, but __cpp_exceptions is defined. +#endif +#ifndef __EXCEPTIONS +// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html +# error This test is meant to be built with C++ Exception Handling disabled, but __EXCEPTIONS is defined. #endif // THIS MUST STAY AT THE TOP!