mirror of
https://github.com/yann64/haikuports.git
synced 2026-04-09 21:30:08 +02:00
* antlr_tool is the grammar compiler * antlr_runtime is the Java runtime (this is also part of antlr_tool) * antlr_cpp is the C++ runtime antlr_tool and antlr_runtime are not built from source, they just repack the downloaded JAR files.
280 lines
9.9 KiB
Plaintext
280 lines
9.9 KiB
Plaintext
From fc126942abe7e507c75f12da2f6d51b70c829736 Mon Sep 17 00:00:00 2001
|
|
From: Robert Adam <dev@robert-adam.de>
|
|
Date: Wed, 30 Nov 2022 19:09:46 +0100
|
|
Subject: Cpp: Add cmake options to selectively disable shared/static build
|
|
|
|
The default behavior is left unchanged (build both) but now users can
|
|
choose to optionally only build one of the two variants.
|
|
Due to macro-magic, both variants had to be compiled separately and
|
|
therefore building both variants really does compile everything twice.
|
|
Therefore, disabling the version that one is not interested in can cut
|
|
down compilation time significantly.
|
|
|
|
Fixes #3993
|
|
|
|
Signed-off-by: Robert Adam <dev@robert-adam.de>
|
|
|
|
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
|
|
index a4e4d1c..5d99d6d 100644
|
|
--- a/runtime/CMakeLists.txt
|
|
+++ b/runtime/CMakeLists.txt
|
|
@@ -1,4 +1,10 @@
|
|
option(ANTLR_BUILD_CPP_TESTS "Build C++ tests." ON)
|
|
+option(ANTLR_BUILD_SHARED "Build the shared library of the ANTLR runtime" ON)
|
|
+option(ANTLR_BUILD_STATIC "Build the static library of the ANTLR runtime" ON)
|
|
+
|
|
+if (NOT ANTLR_BUILD_SHARED AND NOT ANTLR_BUILD_STATIC)
|
|
+ message(FATAL_ERROR "Options ANTLR_BUILD_SHARED and ANTLR_BUILD_STATIC can't both be OFF")
|
|
+endif()
|
|
|
|
include_directories(
|
|
${PROJECT_SOURCE_DIR}/runtime/src
|
|
@@ -25,15 +31,24 @@ file(GLOB libantlrcpp_SRC
|
|
"${PROJECT_SOURCE_DIR}/runtime/src/tree/xpath/*.cpp"
|
|
)
|
|
|
|
-add_library(antlr4_shared SHARED ${libantlrcpp_SRC})
|
|
-add_library(antlr4_static STATIC ${libantlrcpp_SRC})
|
|
+if (ANTLR_BUILD_SHARED)
|
|
+ add_library(antlr4_shared SHARED ${libantlrcpp_SRC})
|
|
+endif()
|
|
+if (ANTLR_BUILD_STATIC)
|
|
+ add_library(antlr4_static STATIC ${libantlrcpp_SRC})
|
|
+endif()
|
|
|
|
# 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)
|
|
-target_link_libraries(antlr4_shared Threads::Threads)
|
|
-target_link_libraries(antlr4_static Threads::Threads)
|
|
+
|
|
+if (TARGET antlr4_shared)
|
|
+ target_link_libraries(antlr4_shared Threads::Threads)
|
|
+endif()
|
|
+if (TARGET antlr4_static)
|
|
+ target_link_libraries(antlr4_static Threads::Threads)
|
|
+endif()
|
|
|
|
if (ANTLR_BUILD_CPP_TESTS)
|
|
include(FetchContent)
|
|
@@ -60,7 +75,7 @@ if (ANTLR_BUILD_CPP_TESTS)
|
|
|
|
target_link_libraries(
|
|
antlr4_tests
|
|
- antlr4_static
|
|
+ $<IF:$<TARGET_EXISTS:antlr4_static>,antlr4_static,antlr4_shared>
|
|
gtest_main
|
|
)
|
|
|
|
@@ -70,8 +85,12 @@ if (ANTLR_BUILD_CPP_TESTS)
|
|
endif()
|
|
|
|
if(APPLE)
|
|
- target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY})
|
|
- target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
|
|
+ if (TARGET antlr4_shared)
|
|
+ target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY})
|
|
+ endif()
|
|
+ if (TARGET antlr4_static)
|
|
+ target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
|
|
+ endif()
|
|
endif()
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
@@ -93,54 +112,70 @@ set(static_lib_suffix "")
|
|
|
|
if (WIN32)
|
|
set(static_lib_suffix "-static")
|
|
- target_compile_definitions(antlr4_shared PUBLIC ANTLR4CPP_EXPORTS)
|
|
- target_compile_definitions(antlr4_static PUBLIC ANTLR4CPP_STATIC)
|
|
+ if (TARGET antlr4_shared)
|
|
+ target_compile_definitions(antlr4_shared PUBLIC ANTLR4CPP_EXPORTS)
|
|
+ endif()
|
|
+ if (TARGET antlr4_static)
|
|
+ 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()
|
|
endif()
|
|
|
|
-set_target_properties(antlr4_shared
|
|
- PROPERTIES VERSION ${ANTLR_VERSION}
|
|
- SOVERSION ${ANTLR_VERSION}
|
|
- OUTPUT_NAME antlr4-runtime
|
|
- COMPILE_FLAGS "${disabled_compile_warnings} ${extra_share_compile_flags}")
|
|
+if (TARGET antlr4_shared)
|
|
+ set_target_properties(antlr4_shared
|
|
+ PROPERTIES VERSION ${ANTLR_VERSION}
|
|
+ SOVERSION ${ANTLR_VERSION}
|
|
+ OUTPUT_NAME antlr4-runtime
|
|
+ COMPILE_FLAGS "${disabled_compile_warnings} ${extra_share_compile_flags}")
|
|
+endif()
|
|
|
|
-set_target_properties(antlr4_static
|
|
- PROPERTIES VERSION ${ANTLR_VERSION}
|
|
- SOVERSION ${ANTLR_VERSION}
|
|
- OUTPUT_NAME "antlr4-runtime${static_lib_suffix}"
|
|
- COMPILE_PDB_NAME "antlr4-runtime${static_lib_suffix}"
|
|
- COMPILE_FLAGS "${disabled_compile_warnings} ${extra_static_compile_flags}")
|
|
+if (TARGET antlr4_static)
|
|
+ set_target_properties(antlr4_static
|
|
+ PROPERTIES VERSION ${ANTLR_VERSION}
|
|
+ SOVERSION ${ANTLR_VERSION}
|
|
+ OUTPUT_NAME "antlr4-runtime${static_lib_suffix}"
|
|
+ COMPILE_PDB_NAME "antlr4-runtime${static_lib_suffix}"
|
|
+ COMPILE_FLAGS "${disabled_compile_warnings} ${extra_static_compile_flags}")
|
|
+endif()
|
|
|
|
if (ANTLR_BUILD_CPP_TESTS)
|
|
# Copy the generated binaries to dist folder (required by test suite)
|
|
+ if (TARGET antlr4_shared)
|
|
add_custom_command(
|
|
- TARGET antlr4_shared
|
|
- POST_BUILD
|
|
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/dist
|
|
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:antlr4_shared> ${CMAKE_HOME_DIRECTORY}/dist
|
|
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_LINKER_FILE:antlr4_shared> ${CMAKE_HOME_DIRECTORY}/dist)
|
|
+ TARGET antlr4_shared
|
|
+ POST_BUILD
|
|
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/dist
|
|
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:antlr4_shared> ${CMAKE_HOME_DIRECTORY}/dist
|
|
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_LINKER_FILE:antlr4_shared> ${CMAKE_HOME_DIRECTORY}/dist)
|
|
+ endif()
|
|
|
|
- add_custom_command(
|
|
- TARGET antlr4_static
|
|
- POST_BUILD
|
|
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/dist
|
|
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:antlr4_static> ${CMAKE_HOME_DIRECTORY}/dist)
|
|
+ if (TARGET antlr4_static)
|
|
+ add_custom_command(
|
|
+ TARGET antlr4_static
|
|
+ POST_BUILD
|
|
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/dist
|
|
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:antlr4_static> ${CMAKE_HOME_DIRECTORY}/dist)
|
|
+ endif()
|
|
+endif()
|
|
+
|
|
+if (TARGET antlr4_shared)
|
|
+ install(TARGETS antlr4_shared
|
|
+ EXPORT antlr4-targets
|
|
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
endif()
|
|
|
|
-install(TARGETS antlr4_shared
|
|
- EXPORT antlr4-targets
|
|
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
-
|
|
-install(TARGETS antlr4_static
|
|
- EXPORT antlr4-targets
|
|
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
+if (TARGET antlr4_static)
|
|
+ install(TARGETS antlr4_static
|
|
+ EXPORT antlr4-targets
|
|
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
+endif()
|
|
|
|
install(DIRECTORY "${PROJECT_SOURCE_DIR}/runtime/src/"
|
|
DESTINATION "include/antlr4-runtime"
|
|
--
|
|
2.37.3
|
|
|
|
|
|
From dbfb727fca76a299914d53e4e99c518842469b00 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Joachim=20Mairb=C3=B6ck?= <j.mairboeck@gmail.com>
|
|
Date: Sun, 5 Feb 2023 20:55:24 +0100
|
|
Subject: fix install paths
|
|
|
|
|
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index df621b1..8bb672c 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -222,14 +222,14 @@ endif(ANTLR4_INSTALL)
|
|
|
|
if(EXISTS LICENSE.txt)
|
|
install(FILES LICENSE.txt
|
|
- DESTINATION "share/doc/libantlr4")
|
|
+ DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
|
elseif(EXISTS ../../LICENSE.txt)
|
|
install(FILES ../../LICENSE.txt
|
|
- DESTINATION "share/doc/libantlr4")
|
|
+ DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
|
endif()
|
|
|
|
install(FILES README.md VERSION
|
|
- DESTINATION "share/doc/libantlr4")
|
|
+ DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
|
|
|
set(CPACK_PACKAGE_CONTACT "antlr-discussion@googlegroups.com")
|
|
set(CPACK_PACKAGE_VERSION ${ANTLR_VERSION})
|
|
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
|
|
index 5d99d6d..2004adb 100644
|
|
--- a/runtime/CMakeLists.txt
|
|
+++ b/runtime/CMakeLists.txt
|
|
@@ -178,7 +178,7 @@ if (TARGET antlr4_static)
|
|
endif()
|
|
|
|
install(DIRECTORY "${PROJECT_SOURCE_DIR}/runtime/src/"
|
|
- DESTINATION "include/antlr4-runtime"
|
|
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/antlr4-runtime"
|
|
COMPONENT dev
|
|
FILES_MATCHING PATTERN "*.h"
|
|
)
|
|
--
|
|
2.37.3
|
|
|
|
|
|
From a8d063068bb433d04de361a8dac2e2650b4c844e Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Joachim=20Mairb=C3=B6ck?= <j.mairboeck@gmail.com>
|
|
Date: Sun, 5 Feb 2023 21:04:31 +0100
|
|
Subject: use packaged gtest
|
|
|
|
|
|
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
|
|
index 2004adb..44d6eb1 100644
|
|
--- a/runtime/CMakeLists.txt
|
|
+++ b/runtime/CMakeLists.txt
|
|
@@ -51,19 +51,6 @@ if (TARGET antlr4_static)
|
|
endif()
|
|
|
|
if (ANTLR_BUILD_CPP_TESTS)
|
|
- include(FetchContent)
|
|
-
|
|
- FetchContent_Declare(
|
|
- googletest
|
|
- URL https://github.com/google/googletest/archive/e2239ee6043f73722e7aa812a459f54a28552929.zip
|
|
- )
|
|
-
|
|
- if(WITH_STATIC_CRT)
|
|
- set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
- endif()
|
|
-
|
|
- FetchContent_MakeAvailable(googletest)
|
|
-
|
|
file(GLOB libantlrcpp_TESTS
|
|
"${PROJECT_SOURCE_DIR}/runtime/tests/*.cpp"
|
|
)
|
|
@@ -77,6 +64,7 @@ if (ANTLR_BUILD_CPP_TESTS)
|
|
antlr4_tests
|
|
$<IF:$<TARGET_EXISTS:antlr4_static>,antlr4_static,antlr4_shared>
|
|
gtest_main
|
|
+ gtest
|
|
)
|
|
|
|
include(GoogleTest)
|
|
--
|
|
2.37.3
|
|
|