Skip to content

Commit c6bc13b

Browse files
committed
Migrate antlr4 ExternalProject to FetchContent
1 parent 83d5d66 commit c6bc13b

File tree

3 files changed

+27
-151
lines changed

3 files changed

+27
-151
lines changed

c/makeotf/lib/cffread/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ if (${NEED_LIBXML2_DEPEND})
88
add_dependencies(makeotf_cffread ${LIBXML2_TARGET})
99
endif()
1010

11-
target_link_libraries(makeotf_cffread PUBLIC antlr4_static)
11+
target_link_libraries(makeotf_cffread PUBLIC afdko::antlr4)
1212

1313
target_compile_definitions(makeotf_cffread PRIVATE $<$<CONFIG:Debug>:CFF_DEBUG=1> CFF_T13_SUPPORT=0)

c/makeotf/lib/hotconv/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ add_library(hotconv STATIC
7070
set_property(TARGET hotconv PROPERTY C_STANDARD 99)
7171
set_property(TARGET hotconv PROPERTY CXX_STANDARD 17)
7272
target_include_directories(hotconv PRIVATE AFTER $<$<COMPILE_LANGUAGE:CXX>:${ANTLR4_INCLUDE_DIRS}>)
73-
target_link_libraries(hotconv PUBLIC antlr4_static)
73+
target_link_libraries(hotconv PUBLIC afdko::antlr4)
7474

7575
target_link_libraries(hotconv PUBLIC ${CHOSEN_LIBXML2_LIBRARY})
7676

cmake/ExternalAntlr4Cpp.cmake

Lines changed: 25 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,41 @@
1-
include(ExternalProject)
2-
cmake_policy(SET CMP0114 NEW) # Added by iterumllc
1+
include(FetchContent)
32

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)
93
if(NOT DEFINED ANTLR4_TAG)
104
# Set to branch name to keep library updated at the cost of needing to rebuild after 'clean'
115
# 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)
777
endif()
788

799
if(ANTLR4_ZIP_REPOSITORY)
80-
ExternalProject_Add(
81-
antlr4_runtime
82-
PREFIX a4 # Edited by iterumllc
10+
set(fetch_content_args
8311
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+
)
9913
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+
)
12018
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)
12721
endif()
22+
FetchContent_Declare(antlr4-runtime
23+
SOURCE_SUBDIR runtime/Cpp
24+
${fetch_content_args}
25+
)
12826

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)
14030

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)
14534

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)
15736

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)
16541
endif()

0 commit comments

Comments
 (0)