File: exception-flags.cmake

package info (click to toggle)
simdjson 4.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,936 kB
  • sloc: cpp: 171,612; ansic: 19,122; sh: 1,126; python: 842; makefile: 47; ruby: 25; javascript: 13
file content (29 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
option(SIMDJSON_EXCEPTIONS "Enable simdjson's exception-throwing interface" ON)
if(NOT SIMDJSON_EXCEPTIONS)
  message(STATUS "simdjson exception interface turned off. \
Code that does not check error codes will not compile.")
  simdjson_add_props(target_compile_definitions PUBLIC SIMDJSON_EXCEPTIONS=0)
  if(MSVC)
    if(NOT is_top_project)
      message(AUTHOR_WARNING "Turning SIMDJSON_EXCEPTIONS off requires \
editing CMAKE_CXX_FLAGS")
    endif()

    # CMake currently /EHsc as a default flag in CMAKE_CXX_FLAGS on MSVC.
    # Replacing this with a more general abstraction is a WIP
    # (see https://gitlab.kitware.com/cmake/cmake/-/issues/20610)
    # /EHs enables standard C++ stack unwinding when catching exceptions
    # (non-structured exception handling)
    # /EHc used in conjection with /EHs indicates that extern "C" functions
    # never throw (terminate-on-throw)
    # Here, we disable both with the - argument negation operator
    if(CMAKE_CXX_FLAGS)
        string(REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
    endif()
    # Because we cannot change the flag above on an individual target (yet), the
    # definition below must similarly be added globally
    add_definitions(-D_HAS_EXCEPTIONS=0)
  elseif(CMAKE_COMPILER_IS_GNUCC)
    simdjson_add_props(target_link_libraries PRIVATE -fno-exceptions)
  endif()
endif()