-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
179 lines (149 loc) · 5.5 KB
/
CMakeLists.txt
File metadata and controls
179 lines (149 loc) · 5.5 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#
# Copyright © 2017 Wan Wai Ho <me@nestal.net>
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file COPYING in the main directory of the spaghetti
# distribution for more details.
#
cmake_minimum_required(VERSION 3.6)
project(spaghetti VERSION 0.4)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost COMPONENTS filesystem serialization REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(GTest)
find_package(Doxygen)
find_package(Threads)
# find libclang
find_library(LIBCLANG_LIBRARY NAMES clang libclang HINTS ${LIBCLANG_PREFIX})
find_path(LIBCLANG_HEADER clang-c/Index.h HINTS ${LIBCLANG_PREFIX})
if (NOT LIBCLANG_LIBRARY OR NOT LIBCLANG_HEADER)
message(FATAL_ERROR "Cannot find libclang!")
endif()
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# compiler specific flags
if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Werror")
elseif (MSVC)
# C4530 and C4577 are from STL headers
set(CMAKE_CXX_FLAGS "/W2 /WX /wd4530 /wd4577 /EHsc")
add_definitions(-D_USE_MATH_DEFINES)
endif()
include_directories(${Boost_INCLUDE_DIRS} ${LIBCLANG_HEADER})
# look like mingw doesn't need this either
if (MSVC)
set(GUI_TYPE WIN32)
set(RC_FILE resources/spaghetti.rc)
endif()
# get build date
string(TIMESTAMP BUILD_DATE "%Y-%m-%d")
# get build information from git
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions(-DVERSION="${PROJECT_VERSION}" -DBUILD_DATE="${BUILD_DATE}" -DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
file(GLOB UTIL_FILES util/*.hh util/*.cc)
file(GLOB LIBCLANGXX_FILES libclx/*.hh libclx/*.cc)
file(GLOB CODEBASE_FILES codebase/*.hh codebase/*.cc)
file(GLOB PROJECT_FILES project/*.hh project/*.cc)
add_library(spag ${LIBCLANGXX_FILES} ${CODEBASE_FILES} ${PROJECT_FILES} ${UTIL_FILES})
# the classes in "project" namespace needs QtCore to serialize models to/from JSON files
target_link_libraries(spag ${LIBCLANG_LIBRARY} ${Boost_LIBRARIES} Qt5::Core)
# debug tool to dump the AST of a source file for analysis
add_executable(dumpast libclx/DumpAST.cc)
target_link_libraries(dumpast spag)
file(GLOB GUI_LIB_FILES
gui/classgf/*.cc gui/classgf/*.hh
gui/logicalvw/*.cc gui/logicalvw/*.hh
gui/sourcevw/*.cc gui/sourcevw/*.hh
gui/common/*.cc gui/common/*.hh gui/common/*.cpp gui/common/*.h
)
add_library(spag-gui ${GUI_LIB_FILES})
target_link_libraries(spag-gui spag Qt5::Widgets)
file(GLOB GUI_FILES
gui/*.hh gui/*.cc
gui/spaghetti.qrc
)
add_executable(spaghetti-gui ${GUI_TYPE} ${GUI_FILES} ${RC_FILE})
target_link_libraries(spaghetti-gui spag spag-gui Qt5::Widgets Qt5::Svg ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS spaghetti-gui RUNTIME DESTINATION bin)
if (GTEST_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})
add_definitions(-DSRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB TEST_FILES
codebase/test/*.cc codebase/test/*.hh
project/test/*.cc project/test/*.hh
)
add_executable(unittest ${TEST_FILES})
target_link_libraries(unittest ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} spag)
file(GLOB GUI_TEST_FILES
gui/test/*.cc gui/test/*.hh
)
add_executable(gui_unittest ${GUI_TEST_FILES})
target_link_libraries(gui_unittest spag-gui ${GTEST_LIBRARIES})
endif(GTEST_FOUND)
if(WIN32)
# NSIS specific settings
set(CPACK_GENERATOR "NSIS")
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/resources/fork.ico")
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/resources/fork.ico")
set(CPACK_NSIS_CONTACT "me@nestal.net")
set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
# install dependent libraries
find_file(LIBCLANG_DLL libclang.dll HINTS ${LIBCLANG_PREFIX}/bin)
install(FILES ${LIBCLANG_DLL} DESTINATION bin)
get_target_property(QtCore_location_Release Qt5::Core LOCATION_Release)
get_filename_component(QT_BINARY_DIR "${QtCore_location_Release}" DIRECTORY)
install(FILES
${QT_BINARY_DIR}/Qt5Core.dll
${QT_BINARY_DIR}/Qt5Widgets.dll
${QT_BINARY_DIR}/Qt5Gui.dll
${QT_BINARY_DIR}/Qt5Svg.dll
${QT_BINARY_DIR}/d3dcompiler_47.dll
${QT_BINARY_DIR}/libEGL.dll
${QT_BINARY_DIR}/libGLESV2.dll
${QT_BINARY_DIR}/opengl32sw.dll
DESTINATION bin
)
set(QT_PLUGINS_DIR "${QT_BINARY_DIR}/../plugins")
install(FILES
${QT_PLUGINS_DIR}/iconengines/qsvgicon.dll
DESTINATION bin/iconengines
)
install(FILES
${QT_PLUGINS_DIR}/platforms/qwindows.dll
DESTINATION bin/platforms
)
install(FILES
${QT_PLUGINS_DIR}/imageformats/qdds.dll
${QT_PLUGINS_DIR}/imageformats/qgif.dll
${QT_PLUGINS_DIR}/imageformats/qicns.dll
${QT_PLUGINS_DIR}/imageformats/qico.dll
${QT_PLUGINS_DIR}/imageformats/qjpeg.dll
${QT_PLUGINS_DIR}/imageformats/qsvg.dll
${QT_PLUGINS_DIR}/imageformats/qtga.dll
${QT_PLUGINS_DIR}/imageformats/qtiff.dll
${QT_PLUGINS_DIR}/imageformats/qwbmp.dll
${QT_PLUGINS_DIR}/imageformats/qwebp.dll
DESTINATION bin/imageformats
)
else()
set(CPACK_GENERATOR "RPM")
endif()
set(CPACK_PACKAGE_EXECUTABLES "spaghetti-gui" "Spaghetti: source code analyzer")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Spaghetti: a tool to quickly understand spaghetti code")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_NAME "spaghetti-gui")
set(CPACK_PACKAGE_VENDOR "nestal.net")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "4")
set(CPACK_PACKAGE_VERSION_PATCH "0")
include(CPack)