Skip to content

Commit ddf19b0

Browse files
aengelkemarcauberer
andcommitted
[CMake] Add options to enable exceptions and enable RTTI
Co-authored-by: Marc Auberer <marc.auberer@sap.com>
1 parent ad85118 commit ddf19b0

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ else ()
2323
option(TPDE_ENABLE_ASSERTIONS "Enable assertions" ON)
2424
endif ()
2525
option(TPDE_BUILD_DOCS "Build documentation" OFF)
26+
option(TPDE_ENABLE_EH "Build with exception handling" OFF)
2627

2728
# warnings
2829
if (MSVC)
2930
add_compile_options(/W4 /WX)
30-
# disable RTTI and exceptions
31-
add_compile_options(/GR- /EHsc /D_HAS_EXCEPTIONS=0)
31+
32+
# enable/disable exceptions
33+
if (NOT TPDE_ENABLE_EH)
34+
add_compile_options(/GR-)
35+
endif ()
3236
else ()
3337
add_compile_options(-Wall -Wextra -Wpedantic)
34-
# disable RTTI and exceptions
35-
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti;-fno-exceptions>")
38+
if (NOT TPDE_ENABLE_EH)
39+
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>")
40+
endif ()
3641

3742
# this is annoying
3843
add_compile_options(-Wno-missing-field-initializers)

tpde-encodegen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(TPDE_LINK_LLVM_STATIC FALSE CACHE BOOL "Should LLVM be linked statically?")
1414

1515
target_include_directories(tpde_encodegen SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
1616
target_compile_definitions(tpde_encodegen PRIVATE ${LLVM_DEFINITIONS})
17+
target_compile_options(tpde_encodegen PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti;-fno-exceptions>")
1718
if (TPDE_LINK_LLVM_STATIC)
1819
llvm_map_components_to_libnames(TPDE_ENCODEGEN_LLVM_LIBS
1920
core X86 AArch64 CodeGen irreader irprinter passes mc support targetparser asmparser asmprinter bitreader bitstreamreader

tpde-llvm/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ set(TPDE_LINK_LLVM_STATIC FALSE CACHE BOOL "Should LLVM be linked statically?")
3030

3131
target_include_directories(tpde_llvm SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS})
3232
target_compile_definitions(tpde_llvm PUBLIC ${LLVM_DEFINITIONS})
33+
if (NOT LLVM_ENABLE_RTTI)
34+
target_compile_options(tpde_llvm PUBLIC -fno-rtti)
35+
endif ()
3336
if (TPDE_LINK_LLVM_STATIC)
3437
llvm_map_components_to_libnames(TPDE_LLVM_LIBS
3538
analysis core irreader irprinter jitlink orcjit passes support bitreader bitstreamreader targetparser

0 commit comments

Comments
 (0)