-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
78 lines (67 loc) · 2.88 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
##
# @file CMakeLists.txt
#
# @copyright Copyright (C) 2020 srcML, LLC. (www.srcML.org)
#
# The srcML Toolkit is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# The srcML Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the srcML Toolkit; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Build ANTLR 2 static library
cmake_minimum_required(VERSION 3.19)
project(srcML-LibAntlr)
# Download cpp library parts of antlr 2.7.7
set(ANTLR2_DIRNAME antlr-2.7.7)
set(ANTLR2_ARCHIVE ${ANTLR2_DIRNAME}.tar.gz)
set(ANTLR2_URL https://www.antlr2.org/download/${ANTLR2_ARCHIVE})
file(DOWNLOAD ${ANTLR2_URL} ${ANTLR2_ARCHIVE})
# Setup Universal architecture for Big Sur default
string(SUBSTRING ${CMAKE_SYSTEM_VERSION} 0 2 OS_VERSION)
if (OS_VERSION GREATER_EQUAL "20")
if(NOT CMAKE_OSX_ARCHITECTURES)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
endif()
message(STATUS "OSX Architectures: ${CMAKE_OSX_ARCHITECTURES}")
endif()
# Extract the include and cpp files
file(ARCHIVE_EXTRACT INPUT ${ANTLR2_ARCHIVE}
PATTERNS ${ANTLR2_DIRNAME}/lib/cpp/src/*.cpp ${ANTLR2_DIRNAME}/lib/cpp/antlr/*.hpp
)
set(ANTLR2_CPP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${ANTLR2_DIRNAME}/lib/cpp)
file(REMOVE ${ANTLR2_CPP_DIR}/src/dll.cpp)
# Include files in the source
include_directories(${ANTLR2_CPP_DIR}/)
# Install include files
install(DIRECTORY ${ANTLR2_CPP_DIR}/antlr DESTINATION /usr/local/include)
# Source files
file(GLOB LIBSRC ${ANTLR2_CPP_DIR}/src/*.cpp)
# ANTLR2 static library
add_library(antlr ${LIBSRC})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libantlr.a DESTINATION /usr/local/lib)
# strip macOS for release
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_custom_command(TARGET antlr POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "-- Stripping $<TARGET_FILE:antlr>"
COMMAND ${CMAKE_COMMAND} -E echo_append "-- Size before: "
COMMAND /usr/bin/stat -f "%z" $<TARGET_FILE:antlr>
COMMAND /usr/bin/strip -x $<TARGET_FILE:antlr>
COMMAND ${CMAKE_COMMAND} -E echo_append "-- Size after: "
COMMAND /usr/bin/stat -f "%z" $<TARGET_FILE:antlr>)
endif()
# Display macOS Big Sur architectures of libantlr
if (OS_VERSION GREATER_EQUAL "20")
add_custom_command(TARGET antlr POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo_append "-- OSX Architectures $<TARGET_FILE:antlr>: "
COMMAND lipo -archs $<TARGET_FILE:antlr>
)
endif()