Skip to content

Commit 7ccf968

Browse files
authored
[orc-rt] Add build options for EH and RTTI, and a config.h header. (#172129)
Clients should be able to build the ORC runtime with or without exceptions/RTTI, and this choice should be able to be made independently of the corresponding settings for LLVM (e.g. it should be fine to build LLVM with exceptions/RTTI disabled, and orc-rt with them enabled). The orc-rt-c/config.h header will provide C defines that can be used by both the ORC runtime and API clients to determine the value of the options. Future patches should build on this work to provide APIs that enable some interoperability between the ORC runtime's error return mechanism (Error/Expected) and C++ exceptions.
1 parent b6c7a27 commit 7ccf968

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

orc-rt/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ option(ORC_RT_INCLUDE_DOCS "Build the ORC-RT documentation." ON)
3030
option(ORC_RT_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
3131
option(ORC_RT_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
3232
option(ORC_RT_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
33+
option(ORC_RT_ENABLE_RTTI "Enable RTTI." ON)
34+
option(ORC_RT_ENABLE_EXCEPTIONS "Enable exceptions." ON)
3335
option(ORC_RT_INCLUDE_TESTS "Build ORC-RT tests." ${LLVM_INCLUDE_TESTS})
3436

3537
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
@@ -40,6 +42,23 @@ set(CMAKE_FOLDER "orc-rt")
4042
set(ORC_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
4143
set(ORC_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
4244

45+
# Configure RTTI and exceptions compile flags
46+
set(ORC_RT_COMPILE_FLAGS)
47+
if(NOT ORC_RT_ENABLE_RTTI)
48+
list(APPEND ORC_RT_COMPILE_FLAGS -fno-rtti)
49+
endif()
50+
51+
if(NOT ORC_RT_ENABLE_EXCEPTIONS)
52+
list(APPEND ORC_RT_COMPILE_FLAGS -fno-exceptions)
53+
endif()
54+
55+
# Generate config header
56+
configure_file(
57+
${CMAKE_CURRENT_SOURCE_DIR}/include/orc-rt-c/config.h.in
58+
${CMAKE_CURRENT_BINARY_DIR}/include/orc-rt-c/config.h
59+
@ONLY
60+
)
61+
4362
#===============================================================================
4463
# Setup Source Code
4564
#===============================================================================

orc-rt/include/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,28 @@ set(ORC_RT_HEADERS
3131
orc-rt/span.h
3232
)
3333

34+
# Add generated config header
35+
set(ORC_RT_GENERATED_HEADERS
36+
${CMAKE_CURRENT_BINARY_DIR}/orc-rt-c/config.h
37+
)
38+
3439
# TODO: Switch to filesets when we move to cmake-3.23.
3540
add_library(orc-rt-headers INTERFACE)
3641
target_include_directories(orc-rt-headers INTERFACE
3742
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
43+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
3844
$<INSTALL_INTERFACE:include>
3945
)
4046
set_property(TARGET orc-rt-headers
41-
PROPERTY PUBLIC_HEADER ${ORC_RT_HEADERS}
47+
PROPERTY PUBLIC_HEADER ${ORC_RT_HEADERS} ${ORC_RT_GENERATED_HEADERS}
4248
)
4349
install(TARGETS orc-rt-headers
4450
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/
4551
COMPONENT OrcRT_Development
4652
)
53+
54+
# Install generated config header
55+
install(FILES ${ORC_RT_GENERATED_HEADERS}
56+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/orc-rt-c/
57+
COMPONENT OrcRT_Development
58+
)

orc-rt/lib/executor/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ add_library(orc-rt-executor STATIC ${files})
1212
target_link_libraries(orc-rt-executor
1313
PUBLIC orc-rt-headers
1414
)
15+
16+
# Apply RTTI and exceptions compile flags
17+
target_compile_options(orc-rt-executor PRIVATE ${ORC_RT_COMPILE_FLAGS})
1518
install(TARGETS orc-rt-executor
1619
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1720
COMPONENT OrcRT_Development

0 commit comments

Comments
 (0)