-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
135 lines (101 loc) · 4.28 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
cmake_minimum_required (VERSION 3.11)
project(zuspec-parser)
include(ExternalProject)
set(CMAKE_INSTALL_RPATH $ORIGIN)
if (NOT PACKAGES_DIR)
set(PACKAGES_DIR ${CMAKE_SOURCE_DIR}/packages)
set(ENABLE_TESTS True)
endif()
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message("Set CMAKE_INSTALL_PREFIX")
set (CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
else()
message("CMAKE_INSTALL_PREFIX set to ${CMAKE_INSTALL_PREFIX}")
endif()
message("PSSParser: PACKAGES_DIR=${PACKAGES_DIR}")
list(APPEND CMAKE_MODULE_PATH ${PACKAGES_DIR}/antlr4-cpp-runtime/cmake)
# Some include
include_directories(${CMAKE_BINARY_DIR}/zsp_ast/src/include)
link_directories(
${CMAKE_BINARY_DIR}/antlr4/lib
${CMAKE_BINARY_DIR}/zsp_ast/lib
)
set(ANTLR_EXECUTABLE ${PACKAGES_DIR}/antlr4-tools.jar)
set(ANTLR4_JAR_LOCATION ${PACKAGES_DIR}/antlr4-tools.jar)
if (WIN32)
set(PYTHON ${PACKAGES_DIR}/python/Scripts/python.exe)
else()
set(PYTHON ${PACKAGES_DIR}/python/bin/python)
endif()
find_package(ANTLR REQUIRED)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS True)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(ANTLR_CXXFLAGS "-Wno-attributes -fPIC")
else()
set(ANTLR_CXXFLAGS -DANTLR4CPP_STATIC)
endif()
#add_compile_options(-pg)
#add_link_options(-pg)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
"-fPIC"
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MDd" "/MTd" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
execute_process(COMMAND ${PYTHON} -m ivpm share cmake OUTPUT_VARIABLE IVPM_CMAKE_PATH)
list(APPEND CMAKE_MODULE_PATH ${IVPM_CMAKE_PATH})
message("IVPM_CMAKE_PATH: ${IVPM_CMAKE_PATH} ${CMAKE_MODULE_PATH}")
include(ivpm)
Ivpm_AddPythonExtProject(debug-mgr debug_mgr)
message("Note: CMAKE_INSTALL_PREFIX set to ${CMAKE_INSTALL_PREFIX}")
ExternalProject_Add(libantlr4
PREFIX antlr4
SOURCE_DIR "${PACKAGES_DIR}/antlr4-cpp-runtime"
CMAKE_CACHE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
-DCMAKE_CXX_FLAGS:STRING=${ANTLR_CXXFLAGS}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DBUILD_STATIC_LIBS:BOOL=False
-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
)
# ${PYTHON} ${CMAKE_SOURCE_DIR}/try.py
# ${PYTHON} -m astbuilder gen-cpp -name ast -namespace zsp::ast -astdir ${CMAKE_CURRENT_SOURCE_DIR}/ast -license ${CMAKE_CURRENT_SOURCE_DIR}/etc/copyright.cpp &&
# ${PYTHON} -m astbuilder gen-pyext -name ast -namespace zsp::ast -package zsp_parser.ast -astdir ${CMAKE_CURRENT_SOURCE_DIR}/ast -o ../ext
ExternalProject_Add(AST
PREFIX zsp_ast
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/zsp_ast/src"
DOWNLOAD_COMMAND
${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen_ast.py
CMAKE_CACHE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
)
add_subdirectory(src)
if (ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
#if (NOT DEFINED ENV{EXT_PYTHON})
# set(ENV{EXT_PYTHON} ${PYTHON})
#endif()
#add_custom_target(build_ext ALL
# COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/pssast/ext/pssast_decl.pxd ${CMAKE_CURRENT_SOURCE_DIR}/python/pssparser/pssast_decl.pxd
# COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/pssast/ext/pssast.pxd ${CMAKE_CURRENT_SOURCE_DIR}/python/pssparser/pssast.pxd
# COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/pssast/ext/pssast.pyx ${CMAKE_CURRENT_SOURCE_DIR}/python/pssast.pyx
# COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/pssast/ext/PyBaseVisitor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/python/PyBaseVisitor.cpp
# COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/pssast/ext/PyBaseVisitor.h ${CMAKE_CURRENT_SOURCE_DIR}/python/PyBaseVisitor.h
# COMMAND ${CMAKE_COMMAND} -E env CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR} $ENV{EXT_PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py build_ext --inplace
# COMMAND $ENV{EXT_PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py bdist_wheel
# )