Skip to content

Commit

Permalink
1. Move target_compile_options() into loop over test targets, in ca…
Browse files Browse the repository at this point in the history
…se the `"exo_planet_c_api"` target does not exist. 2. Add `-fno-exceptions` option also for `NVHPC`. 3. Also check for `__cpp_exceptions` in exo_planet_c_api.cpp.
  • Loading branch information
rwgk committed Sep 16, 2024
1 parent 75871ef commit 1b28837
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 8 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 8 additions & 3 deletions tests/exo_planet_c_api.cpp
Original file line number Diff line number Diff line change
@@ -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!
Expand Down

0 comments on commit 1b28837

Please sign in to comment.