-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
150 lines (122 loc) · 4.27 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# ModelLoader/CMakeLists.txt
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 14)
foreach(p
CMP0071 # 3.10: Let AUTOMOC and AUTOUIC process GENERATED files
)
if(POLICY ${p})
cmake_policy(SET ${p} NEW)
endif()
endforeach()
project(ModelLoader)
set(TEST_PROJECT_NAME Test_ModelLoader)
include_directories( include/
src/
)
# The CMake build process might generate some new files in the current
# directory. This makes sure they can be found.
set( CMAKE_INCLUDE_CURRENT_DIR ON )
# This allows CMake to run one of Qt's build tools called moc
# if it is needed. moc.exe can be found in Qt's bin directory.
# We'll look at what moc does later.
set( CMAKE_AUTOMOC ON )
set( CMAKE_AUTOUIC ON )
# Set all sources manually (except for main.cpp)
set(SOURCES
src/cell.cpp
src/material.cpp
src/matrix.cpp
src/model.cpp
src/vector3d.cpp)
option(TESTING "Testing mode" OFF) #OFF by default
if(TESTING)
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
file(GLOB TEST_SOURCES "tests/*.cpp")
add_executable(${TEST_PROJECT_NAME} ${TEST_SOURCES} ${SOURCES})
target_link_libraries(${TEST_PROJECT_NAME} gtest_main pthread)
# Non-testing mode
else()
# Find the Qt widgets package. This locates the relevant include and
# lib directories, and the necessary static libraries for linking.
find_package( Qt5Widgets )
# Set UI files
set( UIS src/gui/mainwindow.ui src/gui/helpdialog.ui src/gui/clipdialog.ui)
qt5_wrap_ui( UI_Srcs ${UIS} )
# Set icons
set( ICONS src/gui/icons/icons.qrc )
qt5_add_resources( QRC_Srcs ${ICONS} )
# Link to VTK
# find_package( VTK REQUIRED)
find_package(VTK REQUIRED)
if (NOT VTK_FOUND)
message("Skipping ReadSTL: ${VTK_NOT_FOUND_MESSAGE}")
return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
include( ${VTK_USE_FILE} )
# Append sources manually
list(APPEND SOURCES
src/main.cpp
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/gui/helpdialog.cpp
src/gui/helpdialog.h
src/gui/helpdialog.ui
src/gui/clipdialog.cpp
src/gui/clipdialog.h
src/gui/clipdialog.ui
)
# Add sources to the executable
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
${SOURCES}
${UI_Srcs}
${QRC_Srcs}
)
# Link libraries
target_link_libraries(${PROJECT_NAME} Qt5::Widgets ${VTK_LIBRARIES})
# Give installation instructions
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
# Use NSIS to generate installer for Windows, else format it to Zip
if(WIN32)
file(GLOB DLL_FILES ${DLL_DIR}/*.dll)
install(FILES ${DLL_FILES} DESTINATION bin)
set(CPACK_GENERATOR "NSIS")
else()
set(CPACK_GENERATOR "ZIP")
endif()
# Include CPack for packaging
include(CPack)
endif(TESTING)
unset(TESTING CACHE)
# / ModelLoader/CMakeLists.txt