Skip to content

Commit baeec69

Browse files
committed
CMakeLists
1 parent 3d589c9 commit baeec69

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed

CMakeLists.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
project("PHPCoder")
4+
5+
# antlr cpp runtime install dir
6+
set(ANTLR_CPP_RUNTIME_DST ~/antlr/runtime)
7+
8+
# CMake commands copied by the CMake file for CImg
9+
10+
# To use PKG_CHECK_MODULES to find some optional packages
11+
find_package(PkgConfig)
12+
13+
14+
# ### Search Additional Libraries ##########
15+
16+
17+
18+
19+
# #### End of additional libraries search ##########
20+
21+
22+
### Configure Paths according to detected packages
23+
24+
25+
if(NOT APPLE)
26+
if(NOT WIN32)
27+
if(X11_FOUND)
28+
SET(CIMG_CFLAGS "${CIMG_CFLAGS} ${CIMG_XSHM_CCFLAGS} ${CIMG_XRANDR_CCFLAGS}")
29+
SET(SYSTEM_LIBS ${SYSTEM_LIBS})
30+
endif()
31+
endif(NOT WIN32)
32+
endif(NOT APPLE)
33+
34+
if(X11_FOUND)
35+
link_directories(${X11_LIB_DIRS})
36+
include_directories(${X11_INCLUDE_DIR})
37+
SET( SYSTEM_LIBS ${SYSTEM_LIBS} ${X11_LIBRARIES} )
38+
endif()
39+
40+
if (NOT WIN32)
41+
SET( SYSTEM_LIBS ${SYSTEM_LIBS} ${CMAKE_THREAD_LIBS_INIT} )
42+
endif()
43+
44+
if( WIN32)
45+
SET( SYSTEM_LIBS ${SYSTEM_LIBS} gdi32 )
46+
endif()
47+
48+
49+
if(LAPACK_FOUND)
50+
SET(CIMG_CFLAGS "${CIMG_CFLAGS} ${CIMG_LAPACK_CCFLAGS}")
51+
link_directories( ${LAPACK_LIBRARY_DIRS} )
52+
include_directories( ${LAPACK_INCLUDE_DIRS} )
53+
SET( SYSTEM_LIBS ${SYSTEM_LIBS} ${LAPACK_LIBRARIES} )
54+
endif()
55+
56+
if(BLAS_FOUND)
57+
SET(CIMG_CFLAGS "${CIMG_CFLAGS} ${CIMG_BLAS_CCFLAGS}")
58+
link_directories( ${BLAS_LIBRARY_DIRS} )
59+
include_directories( ${BLAS_INCLUDE_DIRS} )
60+
SET( SYSTEM_LIBS ${SYSTEM_LIBS} ${BLAS_LIBRARIES} )
61+
endif()
62+
63+
# Add CIMG Flags to Compilation Flags
64+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CIMG_CFLAGS}")
65+
66+
# CMake commands for this specific project start here
67+
68+
# to disable some warnings for CImg
69+
if (NOT WIN32)
70+
set(CMAKE_CXX_FLAGS "-Wdeprecated -Wno-attributes" )
71+
endif()
72+
73+
if (APPLE)
74+
set(CMAKE_CXX_FLAGS "-Wdeprecated -Wwritable-strings -std=c++11" )
75+
endif()
76+
77+
if (MSVC)
78+
set(CMAKE_CXX_FLAGS "/EHsc /wd4127 /wd4311 /wd4312 /wd4512 /wd4571 /wd4640 /wd4706 /wd4710 /wd4800 /wd4804 /wd4820 /wd4996")
79+
endif()
80+
81+
82+
set(phpcoder-GENERATED_SRC
83+
#${PROJECT_SOURCE_DIR}/phpsrc/PhpLexer.cpp
84+
#${PROJECT_SOURCE_DIR}/phpsrc/PhpParser.cpp
85+
#${PROJECT_SOURCE_DIR}/phpsrc/PhpParserBaseListener.cpp
86+
#{PROJECT_SOURCE_DIR}/phpsrc/PhpParserListener.cpp
87+
88+
89+
${PROJECT_SOURCE_DIR}/phpg/PHPLexer.cpp
90+
${PROJECT_SOURCE_DIR}/phpg/PHPParser.cpp
91+
${PROJECT_SOURCE_DIR}/phpg/PHPParserBaseListener.cpp
92+
${PROJECT_SOURCE_DIR}/phpg/PHPParserBaseVisitor.cpp
93+
${PROJECT_SOURCE_DIR}/phpg/PHPParserListener.cpp
94+
${PROJECT_SOURCE_DIR}/phpg/PHPParserVisitor.cpp
95+
)
96+
97+
foreach( src_file ${phpcoder-GENERATED_SRC} )
98+
set_source_files_properties(
99+
${src_file}
100+
PROPERTIES
101+
GENERATED TRUE
102+
)
103+
endforeach( src_file ${phpcoder-GENERATED_SRC} )
104+
105+
MESSAGE(STATUS "HOME dir: ${ANTLR_CPP_RUNTIME_DST}/usr/local/")
106+
107+
include_directories(
108+
${ANTLR_CPP_RUNTIME_DST}/usr/local/include/antlr4-runtime/
109+
${ANTLR_CPP_RUNTIME_DST}/usr/local/include/misc
110+
${ANTLR_CPP_RUNTIME_DST}/usr/local/include/atn
111+
${ANTLR_CPP_RUNTIME_DST}/usr/local/include/dfa
112+
${ANTLR_CPP_RUNTIME_DST}/usr/local/include/tree
113+
${ANTLR_CPP_RUNTIME_DST}/usr/local/include/support
114+
${ANTLR_CPP_RUNTIME_DST}/usr/local/include/
115+
${PROJECT_SOURCE_DIR}/
116+
${PROJECT_SOURCE_DIR}/phpg/
117+
${PROJECT_SOURCE_DIR}/src/
118+
${PROJECT_SOURCE_DIR}/libs/
119+
)
120+
121+
set(phpcoder-SRC
122+
${PROJECT_SOURCE_DIR}/src/main.cpp
123+
${PROJECT_SOURCE_DIR}/src/PHPVisitor.cpp
124+
${phpcoder-GENERATED_SRC}
125+
)
126+
127+
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
128+
set (flags_1 "-Wno-overloaded-virtual")
129+
else()
130+
set (flags_1 "-MP /wd4251")
131+
endif()
132+
133+
foreach( src_file ${phpcoder-SRC} )
134+
set_source_files_properties(
135+
${src_file}
136+
PROPERTIES
137+
COMPILE_FLAGS "${COMPILE_FLAGS} ${flags_1}"
138+
)
139+
endforeach( src_file ${phpcoder-SRC} )
140+
141+
add_executable(phpbot
142+
${phpcoder-SRC}
143+
)
144+
145+
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
146+
# see https://github.com/antlr/antlr4/issues/1874
147+
target_compile_options(phpbot PUBLIC "$<$<CONFIG:DEBUG>:/MT>")
148+
endif()
149+
150+
if(WIN32)
151+
target_link_libraries(phpbot "${ANTLR_CPP_RUNTIME_DST}/usr/local/lib/antlr4-runtime.lib")
152+
endif()
153+
154+
if(APPLE)
155+
target_link_libraries(phpbot "${ANTLR_CPP_RUNTIME_DST}/usr/local/lib/libantlr4-runtime.dylib")
156+
elseif(UNIX)
157+
target_link_libraries(phpbot "${ANTLR_CPP_RUNTIME_DST}/usr/local/lib/libantlr4-runtime.so")
158+
endif()
159+
160+
target_link_libraries(phpbot ${SYSTEM_LIBS})
161+
162+
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
163+
add_custom_command(TARGET phpbot POST_BUILD
164+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
165+
"${ANTLR_CPP_RUNTIME_DST}/usr/local/lib/libantlr4-runtime.so"
166+
$<TARGET_FILE_DIR:phpbot>)
167+
endif()
168+
169+
if(WIN32)
170+
add_custom_command(TARGET phpbot POST_BUILD
171+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
172+
"${ANTLR_CPP_RUNTIME_DST}/usr/local/lib/antlr4-runtime.dll"
173+
$<TARGET_FILE_DIR:phpbot>)
174+
endif()
175+
176+
# 拷贝文件,暂时不操作
177+
if(APPLE)
178+
add_custom_command(TARGET phpbot POST_BUILD
179+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
180+
"${ANTLR_CPP_RUNTIME_DST}/usr/local/lib/libantlr4-runtime.4.8.dylib"
181+
$<TARGET_FILE_DIR:phpbot>)
182+
endif()
183+
184+
# copy the input file next to the generated executable
185+
add_custom_command(TARGET phpbot POST_BUILD
186+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
187+
"${PROJECT_SOURCE_DIR}/test.php"
188+
$<TARGET_FILE_DIR:phpbot>)
189+
190+
# necessary because the default working directory of Visual Studio
191+
# is not the same as the one in which the binary is created
192+
# so we copy the input file twice:
193+
# one for when you launch the executale in Visual Studio (CTRL+F5)
194+
# one for when you launch it normally
195+
if (WIN32)
196+
add_custom_command(TARGET phpbot POST_BUILD
197+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
198+
"${PROJECT_SOURCE_DIR}/test.php"
199+
$<TARGET_FILE_DIR:phpbot>/../)
200+
endif()

0 commit comments

Comments
 (0)