-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
195 lines (165 loc) · 7.25 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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Author: Eugenio Marinetto [[email protected]]
# This is an example file for a Project Configuration
# using CMake.
######################################
# Minimum version of CMake required ##
######################################
cmake_minimum_required(VERSION 3.0.2)
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
#############################
# Creation of the project ##
#############################
set(PROJECT_NAME "BiiGOptitrack" CACHE STRING "")
project(${PROJECT_NAME})
# Version Control of the project
set (${PROJECT_NAME}_VERSION_MAJOR 3)
set (${PROJECT_NAME}_VERSION_MINOR 0)
message("Version: ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}")
###############################
# Options for Configuration ##
###############################
set(${PROJECT_NAME}_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/install" CACHE PATH "InstaLL DIR" FORCE)
# Create an option of the project for documentation option set
option(${PROJECT_NAME}_BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" OFF)
option(${PROJECT_NAME}_CMAKE_DEBUG_FLAG "Create and install the HTML based API documentation (requires Doxygen)" ON)
# Create variable for packing
option(${PROJECT_NAME}_BUILD_PACKAGING "Support for CPack packaging" OFF)
# BiiGOptitrack Options
option(${PROJECT_NAME}_USE_FAKE_NPAPI "Fake Library NPTrackingTools" OFF)
set(${PROJECT_NAME}_ITK_EXTERNAL_DIR "NOT-FOUND" CACHE PATH "ITK DIR")
set(${PROJECT_NAME}_OpenIGTLink_EXTERNAL_DIR "NOT-FOUND" CACHE PATH "OpenIGTLink DIR")
set(${PROJECT_NAME}_tinyxml2_EXTERNAL_DIR "NOT-FOUND" CACHE PATH "timyxml2 DIR")
###############################
# Look for CMakeAll ##
###############################
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake")
find_package(CMakeAll REQUIRED)
###############################
# Configure Projects ##
###############################
file(GLOB ${PROJECT_NAME}_PROJECTS "${PROJECT_SOURCE_DIR}/Projects/*.cmake")
cma_add_projects(${${PROJECT_NAME}_PROJECTS})
cma_print_projects()
message(STATUS "${PROJECT_NAME} ${${PROJECT_NAME}_VERSION}")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND APPLE)
set(CMAKE_CXX_FLAGS "-stdlib=libstdc++ ${CMAKE_CXX_FLAGS}")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo" CACHE STRING "" FORCE)
endif()
cma_configure_projects()
###########################
# Configure Config.cmake ##
###########################
# Include folders
set(CONF_INCLUDE_DIRS "${${PROJECT_NAME}_INSTALL_DIR}/inc")
# Include files
file(GLOB CONF_INCLUDE_FILES ${CONF_INCLUDE_DIRS}/*.h)
# Source folders
set(CONF_SOURCE_DIRS ${PROJECT_SOURCE_DIR})
# Library names
set(CONF_LIBRARY "")
# Library Folders
set(CONF_LIBRARY_DIRS "${${PROJECT_NAME}_INSTALL_DIR}/lib" "${${PROJECT_NAME}_INSTALL_DIR}/bin")
# Binary folder
set(CONF_BINARY_DIR "${PROJECT_BINARY_DIR}")
# Install folder
set(CONF_INSTALL_DIR "${${PROJECT_NAME}_INSTALL_DIR}")
# Flag for libraries
set(CONF_SHARED OFF)
# Definition of the project (options)
set(CONF_DEFINITIONS
-DCMAKE_DEBUG_FLAG:BOOL=${${PROJECT_NAME}_CMAKE_DEBUG_FLAG})
# Executables names
set(CONF_EXECUTABLES "")
set(CONF_EXECUTABLES_DIRS "${${PROJECT_NAME}_INSTALL_DIR}/lib")
if(${PROJECT_NAME}_CMAKE_DEBUG_FLAG)
message(" Creating Config File ${PROJECT_NAME}Config.cmake into ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
endif()
configure_file("${PROJECT_SOURCE_DIR}/CMake/Config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
###############################################
# INSTALLATION TARGET and Configuration Files #
###############################################
set(CMAKE_INSTALL_PREFIX ${${PROJECT_NAME}_INSTALL_DIR})
if(${PROJECT_NAME}_CMAKE_DEBUG_FLAG)
message(" Defining Install configuration into folder: ${${PROJECT_NAME}_INSTALL_DIR}")
endif()
##############################################
# Configure Config.cmake for install folder ##
##############################################
# Include folders
set(CONF_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/install/inc")
# Include files
file(GLOB CONF_INCLUDE_FILES ${CONF_INCLUDE_DIRS}/*.h)
# Source folders
set(CONF_SOURCE_DIRS ${PROJECT_SOURCE_DIR})
# Library names
set(CONF_LIBRARY "")
# Library Folders
set(CONF_LIBRARY_DIRS "${PROJECT_BINARY_DIR}/install/lib" "${PROJECT_BINARY_DIR}/install/bin")
# Binary folder
set(CONF_BINARY_DIR "${PROJECT_BINARY_DIR}")
# Install folder
set(CONF_INSTALL_DIR "${${PROJECT_NAME}_INSTALL_DIR}")
# Flag for libraries
set(CONF_SHARED OFF)
# Definition of the project (options)
set(CONF_DEFINITIONS
-DCMAKE_DEBUG_FLAG:BOOL=${${PROJECT_NAME}_CMAKE_DEBUG_FLAG})
# Executables names
set(CONF_EXECUTABLES "")
set(CONF_EXECUTABLES_DIRS "${PROJECT_BINARY_DIR}/install/lib")
if(${PROJECT_NAME}_CMAKE_DEBUG_FLAG)
message(" Creating Config File ${PROJECT_NAME}Config.cmake into ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
endif()
# Create the file
configure_file("${PROJECT_SOURCE_DIR}/CMake/Config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigInstall.cmake" @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/CMake/ConfigInstall.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigInstallScript.cmake" @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/CMake/FilesToBeCopiedDuringInstall.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigInstallFilesScript.cmake" @ONLY)
# Copy the file to the install folder
install (SCRIPT "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigInstallScript.cmake")
install (SCRIPT "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigInstallFilesScript.cmake")
if(${PROJECT_NAME}_BUILD_PACKAGING)
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "E. Marinetto")
set(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${${PROJECT_NAME}_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${${PROJECT_NAME}_VERSION})
cma_package_projects()
endif()
# Documentation
if(${PROJECT_NAME}_BUILD_DOCUMENTATION AND NOT USE_Doxygen)
message("${PROJECT_NAME}_BUILD_DOCUMENTATION is enabling Doxygen")
set(USE_Doxygen ON CACHE BOOL "" FORCE)
endif()
# configure files
file(WRITE ${PROJECT_BINARY_DIR}/CMake.h "#ifndef __CMake_h\n#define __CMake_h\n\n")
file(WRITE ${PROJECT_BINARY_DIR}/CMake.py "")
file(WRITE ${PROJECT_BINARY_DIR}/CMake.m "")
get_cmake_property(VARIABLES VARIABLES)
foreach (KEY ${VARIABLES})
if(KEY MATCHES "^${PROJECT_NAME}_")
file(TO_NATIVE_PATH "${${KEY}}" VALUE)
if(WIN32)
string(REPLACE "\\" "\\\\" VALUE "${VALUE}")
endif()
file(APPEND ${PROJECT_BINARY_DIR}/CMake.h "#define ${KEY} \"${VALUE}\"\n")
file(APPEND ${PROJECT_BINARY_DIR}/CMake.py "${KEY} = '${VALUE}'\n")
file(APPEND ${PROJECT_BINARY_DIR}/CMake.m "${KEY} = '${VALUE}';\n")
endif()
endforeach()
file(APPEND ${PROJECT_BINARY_DIR}/CMake.h "\n#endif // __CMake_h\n")
# configure launcher
cma_configure_launcher("${PROJECT_SOURCE_DIR}/CMake/Launcher.cmake")
cma_launcher_target(Terminal
NAME run_Terminal)
cma_launcher_shortcut(Terminal
NAME Terminal)