|
1 | | -include(ExternalProject) |
2 | | -cmake_policy(SET CMP0114 NEW) # Added by iterumllc |
| 1 | +include(FetchContent) |
3 | 2 |
|
4 | | -# Edits below are for path length or (in the zip download) correctness |
5 | | - |
6 | | -set(ANTLR4_ROOT ${CMAKE_CURRENT_BINARY_DIR}/a4/src/a4) # Edited by iterumllc |
7 | | -set(ANTLR4_INCLUDE_DIRS ${ANTLR4_ROOT}/runtime/Cpp/runtime/src) |
8 | | -set(ANTLR4_GIT_REPOSITORY https://github.com/antlr/antlr4.git) |
9 | 3 | if(NOT DEFINED ANTLR4_TAG) |
10 | 4 | # Set to branch name to keep library updated at the cost of needing to rebuild after 'clean' |
11 | 5 | # Set to commit hash to keep the build stable and does not need to rebuild after 'clean' |
12 | | - set(ANTLR4_TAG master) |
13 | | -endif() |
14 | | - |
15 | | -if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*") |
16 | | - set(ANTLR4_OUTPUT_DIR ${ANTLR4_ROOT}/runtime/Cpp/runtime/$(Configuration)) |
17 | | -elseif(${CMAKE_GENERATOR} MATCHES "Xcode.*") |
18 | | - set(ANTLR4_OUTPUT_DIR ${ANTLR4_ROOT}/runtime/Cpp/runtime) |
19 | | -else() |
20 | | - set(ANTLR4_OUTPUT_DIR ${ANTLR4_ROOT}/runtime/Cpp/runtime) |
21 | | -endif() |
22 | | - |
23 | | -if(MSVC) |
24 | | - set(ANTLR4_STATIC_LIBRARIES |
25 | | - ${ANTLR4_OUTPUT_DIR}/antlr4-runtime-static.lib) |
26 | | - set(ANTLR4_SHARED_LIBRARIES |
27 | | - ${ANTLR4_OUTPUT_DIR}/antlr4-runtime.lib) |
28 | | - set(ANTLR4_RUNTIME_LIBRARIES |
29 | | - ${ANTLR4_OUTPUT_DIR}/antlr4-runtime.dll) |
30 | | -else() |
31 | | - set(ANTLR4_STATIC_LIBRARIES |
32 | | - ${ANTLR4_OUTPUT_DIR}/libantlr4-runtime.a) |
33 | | - if(MINGW) |
34 | | - set(ANTLR4_SHARED_LIBRARIES |
35 | | - ${ANTLR4_OUTPUT_DIR}/libantlr4-runtime.dll.a) |
36 | | - set(ANTLR4_RUNTIME_LIBRARIES |
37 | | - ${ANTLR4_OUTPUT_DIR}/libantlr4-runtime.dll) |
38 | | - elseif(CYGWIN) |
39 | | - set(ANTLR4_SHARED_LIBRARIES |
40 | | - ${ANTLR4_OUTPUT_DIR}/libantlr4-runtime.dll.a) |
41 | | - set(ANTLR4_RUNTIME_LIBRARIES |
42 | | - ${ANTLR4_OUTPUT_DIR}/cygantlr4-runtime-4.9.2.dll) |
43 | | - elseif(APPLE) |
44 | | - set(ANTLR4_RUNTIME_LIBRARIES |
45 | | - ${ANTLR4_OUTPUT_DIR}/libantlr4-runtime.dylib) |
46 | | - else() |
47 | | - set(ANTLR4_RUNTIME_LIBRARIES |
48 | | - ${ANTLR4_OUTPUT_DIR}/libantlr4-runtime.so) |
49 | | - endif() |
50 | | -endif() |
51 | | - |
52 | | -if(${CMAKE_GENERATOR} MATCHES ".* Makefiles") |
53 | | - # This avoids |
54 | | - # 'warning: jobserver unavailable: using -j1. Add '+' to parent make rule.' |
55 | | - set(ANTLR4_BUILD_COMMAND $(MAKE)) |
56 | | -elseif(${CMAKE_GENERATOR} MATCHES "Visual Studio.*") |
57 | | - set(ANTLR4_BUILD_COMMAND |
58 | | - ${CMAKE_COMMAND} |
59 | | - --build . |
60 | | - --config $(Configuration) |
61 | | - --target) |
62 | | -elseif(${CMAKE_GENERATOR} MATCHES "Xcode.*") |
63 | | - set(ANTLR4_BUILD_COMMAND |
64 | | - ${CMAKE_COMMAND} |
65 | | - --build . |
66 | | - --config $(CONFIGURATION) |
67 | | - --target) |
68 | | -else() |
69 | | - set(ANTLR4_BUILD_COMMAND |
70 | | - ${CMAKE_COMMAND} |
71 | | - --build . |
72 | | - --target) |
73 | | -endif() |
74 | | - |
75 | | -if(NOT DEFINED ANTLR4_WITH_STATIC_CRT) |
76 | | - set(ANTLR4_WITH_STATIC_CRT ON) |
| 6 | + set(ANTLR4_TAG dev) |
77 | 7 | endif() |
78 | 8 |
|
79 | 9 | if(ANTLR4_ZIP_REPOSITORY) |
80 | | - ExternalProject_Add( |
81 | | - antlr4_runtime |
82 | | - PREFIX a4 # Edited by iterumllc |
| 10 | + set(fetch_content_args |
83 | 11 | URL ${ANTLR4_ZIP_REPOSITORY} |
84 | | - DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR} |
85 | | - BUILD_COMMAND "" |
86 | | - BUILD_IN_SOURCE 1 |
87 | | - SOURCE_DIR ${ANTLR4_ROOT}/runtime/Cpp # Edited by iterumllc |
88 | | - # SOURCE_SUBDIR runtime/Cpp # Commented out by iterumllc |
89 | | - CMAKE_CACHE_ARGS |
90 | | - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} |
91 | | - -DWITH_STATIC_CRT:BOOL=${ANTLR4_WITH_STATIC_CRT} |
92 | | - -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES} |
93 | | - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON |
94 | | - -DANTLR_BUILD_CPP_TESTS:BOOL=OFF |
95 | | - # -DCMAKE_CXX_STANDARD:STRING=17 # if desired, compile the runtime with a different C++ standard |
96 | | - # -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} # alternatively, compile the runtime with the same C++ standard as the outer project |
97 | | - INSTALL_COMMAND "" |
98 | | - EXCLUDE_FROM_ALL 1) |
| 12 | + ) |
99 | 13 | else() |
100 | | - ExternalProject_Add( |
101 | | - antlr4_runtime |
102 | | - PREFIX a4 # Edited by iterumllc |
103 | | - GIT_REPOSITORY ${ANTLR4_GIT_REPOSITORY} |
104 | | - GIT_TAG ${ANTLR4_TAG} |
105 | | - DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR} |
106 | | - BUILD_COMMAND "" |
107 | | - BUILD_IN_SOURCE 1 |
108 | | - SOURCE_DIR ${ANTLR4_ROOT} |
109 | | - SOURCE_SUBDIR runtime/Cpp |
110 | | - CMAKE_CACHE_ARGS |
111 | | - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} |
112 | | - -DWITH_STATIC_CRT:BOOL=${ANTLR4_WITH_STATIC_CRT} |
113 | | - -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES} |
114 | | - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON |
115 | | - -DANTLR_BUILD_CPP_TESTS:BOOL=OFF |
116 | | - # -DCMAKE_CXX_STANDARD:STRING=17 # if desired, compile the runtime with a different C++ standard |
117 | | - # -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} # alternatively, compile the runtime with the same C++ standard as the outer project |
118 | | - INSTALL_COMMAND "" |
119 | | - EXCLUDE_FROM_ALL 1) |
| 14 | + set(fetch_content_args |
| 15 | + GIT_REPOSITORY https://github.com/antlr/antlr4.git |
| 16 | + GIT_RAG ${ANTLR4_TAG} |
| 17 | + ) |
120 | 18 | endif() |
121 | | - |
122 | | -# Separate build step as rarely people want both |
123 | | -set(ANTLR4_BUILD_DIR ${ANTLR4_ROOT}) |
124 | | -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14.0") |
125 | | - # CMake 3.14 builds in above's SOURCE_SUBDIR when BUILD_IN_SOURCE is true |
126 | | - set(ANTLR4_BUILD_DIR ${ANTLR4_ROOT}/runtime/Cpp) |
| 19 | +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) |
| 20 | + list(APPEND fetch_content_args FIND_PACKAGE_ARGS CONFIG) |
127 | 21 | endif() |
| 22 | +FetchContent_Declare(antlr4-runtime |
| 23 | + SOURCE_SUBDIR runtime/Cpp |
| 24 | + ${fetch_content_args} |
| 25 | +) |
128 | 26 |
|
129 | | -ExternalProject_Add_Step( |
130 | | - antlr4_runtime |
131 | | - build_static |
132 | | - COMMAND ${ANTLR4_BUILD_COMMAND} antlr4_static |
133 | | - # Depend on target instead of step (a custom command) |
134 | | - # to avoid running dependent steps concurrently |
135 | | - DEPENDS antlr4_runtime |
136 | | - BYPRODUCTS ${ANTLR4_STATIC_LIBRARIES} |
137 | | - EXCLUDE_FROM_MAIN 1 |
138 | | - WORKING_DIRECTORY ${ANTLR4_BUILD_DIR}) |
139 | | -ExternalProject_Add_StepTargets(antlr4_runtime build_static) |
| 27 | +include(CMakeDependentOption) |
| 28 | +option(AFDKO_USE_ANTLR_SHARED_LIB |
| 29 | + "Whether to use the shared library of afdko" OFF) |
140 | 30 |
|
141 | | -add_library(antlr4_static STATIC IMPORTED) |
142 | | -add_dependencies(antlr4_static antlr4_runtime-build_static) |
143 | | -set_target_properties(antlr4_static PROPERTIES |
144 | | - IMPORTED_LOCATION ${ANTLR4_STATIC_LIBRARIES}) |
| 31 | +option(ANTLR_BUILD_CPP_TESTS "Override: afdko" OFF) |
| 32 | +cmake_dependent_option(ANTLR_BUILD_SHARED "Override: afdko" ON AFDKO_USE_ANTLR_SHARED_LIB OFF) |
| 33 | +option(ANTLR_BUILD_STATIC "Override: afdko" ON) |
145 | 34 |
|
146 | | -ExternalProject_Add_Step( |
147 | | - antlr4_runtime |
148 | | - build_shared |
149 | | - COMMAND ${ANTLR4_BUILD_COMMAND} antlr4_shared |
150 | | - # Depend on target instead of step (a custom command) |
151 | | - # to avoid running dependent steps concurrently |
152 | | - DEPENDS antlr4_runtime |
153 | | - BYPRODUCTS ${ANTLR4_SHARED_LIBRARIES} ${ANTLR4_RUNTIME_LIBRARIES} |
154 | | - EXCLUDE_FROM_MAIN 1 |
155 | | - WORKING_DIRECTORY ${ANTLR4_BUILD_DIR}) |
156 | | -ExternalProject_Add_StepTargets(antlr4_runtime build_shared) |
| 35 | +FetchContent_MakeAvailable(antlr4-runtime) |
157 | 36 |
|
158 | | -add_library(antlr4_shared SHARED IMPORTED) |
159 | | -add_dependencies(antlr4_shared antlr4_runtime-build_shared) |
160 | | -set_target_properties(antlr4_shared PROPERTIES |
161 | | - IMPORTED_LOCATION ${ANTLR4_RUNTIME_LIBRARIES}) |
162 | | -if(ANTLR4_SHARED_LIBRARIES) |
163 | | - set_target_properties(antlr4_shared PROPERTIES |
164 | | - IMPORTED_IMPLIB ${ANTLR4_SHARED_LIBRARIES}) |
| 37 | +if(AFDKO_USE_ANTLR_SHARED_LIB) |
| 38 | + add_library(afdko::antlr4 ALIAS antlr4_shared) |
| 39 | +else() |
| 40 | + add_library(afdko::antlr4 ALIAS antlr4_static) |
165 | 41 | endif() |
0 commit comments