2022-11-17 05:37:32 +08:00
|
|
|
diff --git a/runtime/Cpp/runtime/CMakeLists.txt b/runtime/Cpp/runtime/CMakeLists.txt
|
|
|
|
index a4e4d1c..19cc21c 100644
|
|
|
|
--- a/runtime/Cpp/runtime/CMakeLists.txt
|
|
|
|
+++ b/runtime/Cpp/runtime/CMakeLists.txt
|
|
|
|
@@ -25,15 +25,21 @@ file(GLOB libantlrcpp_SRC
|
2022-04-19 07:44:47 +08:00
|
|
|
"${PROJECT_SOURCE_DIR}/runtime/src/tree/xpath/*.cpp"
|
|
|
|
)
|
|
|
|
|
|
|
|
+if(BUILD_SHARED_LIBS)
|
2019-03-09 14:09:33 +08:00
|
|
|
add_library(antlr4_shared SHARED ${libantlrcpp_SRC})
|
2022-04-19 07:44:47 +08:00
|
|
|
+else()
|
2019-03-09 14:09:33 +08:00
|
|
|
add_library(antlr4_static STATIC ${libantlrcpp_SRC})
|
2022-04-19 07:44:47 +08:00
|
|
|
+endif()
|
|
|
|
|
2022-11-17 05:37:32 +08:00
|
|
|
# Make sure to link against threads (pthreads) library in order to be able to
|
|
|
|
# make use of std::call_once in the code without producing runtime errors
|
|
|
|
# (see also https://github.com/antlr/antlr4/issues/3708 and/or https://stackoverflow.com/q/51584960).
|
|
|
|
find_package(Threads REQUIRED)
|
2022-04-19 07:44:47 +08:00
|
|
|
+if(BUILD_SHARED_LIBS)
|
2022-11-17 05:37:32 +08:00
|
|
|
target_link_libraries(antlr4_shared Threads::Threads)
|
2022-04-19 07:44:47 +08:00
|
|
|
+else()
|
2022-11-17 05:37:32 +08:00
|
|
|
target_link_libraries(antlr4_static Threads::Threads)
|
2022-04-19 07:44:47 +08:00
|
|
|
+endif()
|
|
|
|
|
2022-06-25 06:11:33 +08:00
|
|
|
if (ANTLR_BUILD_CPP_TESTS)
|
|
|
|
include(FetchContent)
|
2022-11-17 05:37:32 +08:00
|
|
|
@@ -70,8 +76,11 @@ if (ANTLR_BUILD_CPP_TESTS)
|
2022-04-19 07:44:47 +08:00
|
|
|
endif()
|
|
|
|
|
2022-11-17 05:37:32 +08:00
|
|
|
if(APPLE)
|
2022-04-19 07:44:47 +08:00
|
|
|
+ if(BUILD_SHARED_LIBS)
|
|
|
|
target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY})
|
|
|
|
+ else()
|
|
|
|
target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
|
|
|
|
+ endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
2022-11-17 05:37:32 +08:00
|
|
|
@@ -93,26 +102,32 @@ set(static_lib_suffix "")
|
|
|
|
|
|
|
|
if (WIN32)
|
|
|
|
set(static_lib_suffix "-static")
|
|
|
|
+ if(BUILD_SHARED_LIBS)
|
|
|
|
target_compile_definitions(antlr4_shared PUBLIC ANTLR4CPP_EXPORTS)
|
|
|
|
+ else()
|
|
|
|
target_compile_definitions(antlr4_static PUBLIC ANTLR4CPP_STATIC)
|
|
|
|
+ endif()
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
set(extra_share_compile_flags "-MP /wd4251")
|
|
|
|
set(extra_static_compile_flags "-MP")
|
|
|
|
endif()
|
2022-04-19 07:44:47 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
+if(BUILD_SHARED_LIBS)
|
|
|
|
set_target_properties(antlr4_shared
|
|
|
|
PROPERTIES VERSION ${ANTLR_VERSION}
|
|
|
|
SOVERSION ${ANTLR_VERSION}
|
2022-11-17 05:37:32 +08:00
|
|
|
OUTPUT_NAME antlr4-runtime
|
2022-04-19 07:44:47 +08:00
|
|
|
COMPILE_FLAGS "${disabled_compile_warnings} ${extra_share_compile_flags}")
|
2022-11-17 05:37:32 +08:00
|
|
|
|
2022-04-19 07:44:47 +08:00
|
|
|
+else()
|
|
|
|
set_target_properties(antlr4_static
|
|
|
|
PROPERTIES VERSION ${ANTLR_VERSION}
|
|
|
|
SOVERSION ${ANTLR_VERSION}
|
|
|
|
OUTPUT_NAME "antlr4-runtime${static_lib_suffix}"
|
2022-11-17 05:37:32 +08:00
|
|
|
COMPILE_PDB_NAME "antlr4-runtime${static_lib_suffix}"
|
2022-04-19 07:44:47 +08:00
|
|
|
COMPILE_FLAGS "${disabled_compile_warnings} ${extra_static_compile_flags}")
|
|
|
|
+endif()
|
2022-11-17 05:37:32 +08:00
|
|
|
|
|
|
|
if (ANTLR_BUILD_CPP_TESTS)
|
|
|
|
# Copy the generated binaries to dist folder (required by test suite)
|
|
|
|
@@ -130,18 +145,21 @@ if (ANTLR_BUILD_CPP_TESTS)
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:antlr4_static> ${CMAKE_HOME_DIRECTORY}/dist)
|
|
|
|
endif()
|
|
|
|
|
2022-04-19 07:44:47 +08:00
|
|
|
+if(BUILD_SHARED_LIBS)
|
2022-06-25 06:11:33 +08:00
|
|
|
install(TARGETS antlr4_shared
|
|
|
|
EXPORT antlr4-targets
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2022-11-17 05:37:32 +08:00
|
|
|
|
2022-04-19 07:44:47 +08:00
|
|
|
+else()
|
|
|
|
install(TARGETS antlr4_static
|
2022-06-25 06:11:33 +08:00
|
|
|
EXPORT antlr4-targets
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2022-04-19 07:44:47 +08:00
|
|
|
|
2022-11-17 05:37:32 +08:00
|
|
|
+endif()
|
2022-04-19 07:44:47 +08:00
|
|
|
install(DIRECTORY "${PROJECT_SOURCE_DIR}/runtime/src/"
|
|
|
|
DESTINATION "include/antlr4-runtime"
|
2022-11-17 05:37:32 +08:00
|
|
|
COMPONENT dev
|