-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
225 lines (190 loc) · 7.83 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
PROJECT(hpmcpp VERSION 0.3.0)
# Build shared/dynamic library option
OPTION(BUILD_SHARED_LIBS "Build package with shared libraries." ON)
OPTION(BUILD_WITH_EXTERNAL_PROJECT "Enable external project build." ON)
OPTION(BUILD_OPT_BUILD_PACKAGES "Set to ON to generate CPack configuration files and packaging targets" ON)
OPTION(BUILD_WITH_INSTALL "" ON )
IF (NOT BUILD_SHARED_LIBS)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
SET(LINK_SEARCH_START_STATIC TRUE)
ENDIF ()
IF(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
SET(HPMCPP_STANDALONE ON CACHE BOOL "")
ELSE()
SET(HPMCPP_STANDALONE OFF CACHE BOOL "")
ENDIF()
# hpmcpp version setup.
SET(VERSION_MAJOR 0)
SET(VERSION_MINOR 4)
SET(VERSION_REVISION 1)
SET(VERSION_STATE b)
SET(VERSION_NUMBER ${VERSION_MAJOR}.${VERSION_MINOR}${VERSION_STATE})
SET(VERSION ${VERSION_NUMBER}${VERSION_REVISION})
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules" )
#
SET(LIBHPMCPP-DEV_COMPONENT "libhpmcpp{VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}-dev")
SET(CPACK_COMPONENTS_ALL ${LIBHPMCPP-DEV_COMPONENT} )
ADD_DEFINITIONS(-DHPMCPP_VERSION="${VERSION}"})
# Compiler options.
MESSAGE(STATUS "Version ${VERSION}")
IF ((CMAKE_COMPILER_IS_GNUCC) AND NOT CMAKE_COMPILER_IS_MINGOW)
IF (BUILD_SHARED_LIBS AND CMAKE_SIZEOF_VOID_P EQUAL 8)
ADD_DEFINITIONS(-fPIC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
ENDIF ()
# Set compile flags.
ADD_DEFINITIONS(-DHC_INTERNAL=1)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
# Check build target.
IF (CMAKE_BUILD_TYPE STREQUAL "Release")
MESSAGE(STATUS "Compile for release.")
ADD_DEFINITIONS(-DNDEBUG -O2)
SET(CMAKE_RELEASE TRUE)
ELSEIF (CMAKE_BUILD_TYPE STREQUAL "Debug")
MESSAGE(STATUS "Compile for debug.")
ADD_DEFINITIONS(-D_DEBUG)
ADD_DEFINITIONS(-g3 -O0)
SET(CMAKE_DEBUG TRUE)
ENDIF ()
ELSEIF (MSVC)
# Enable multi-core complication with MSVC
ADD_DEFINITIONS(/MP)
ENDIF ()
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
FIND_PACKAGE(Git)
IF(GIT_FOUND)
MESSAGE(STATUS "git found: ${GIT_EXECUTABLE} -- ${GIT_VERSION_STRING}")
ENDIF()
IF(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
OPTION(GIT_SUBMODULE "Check submodules during build" OFF)
IF(GIT_SUBMODULE)
MESSAGE(STATUS "Submodule update")
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} submodule update --init
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
IF(NOT GIT_SUBMOD_RESULT EQUAL "0")
MESSAGE(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
ENDIF()
ENDIF()
ELSE()
ENDIF()
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/extern/hpm EXCLUDE_FROM_ALL)
# Source files.
FILE(GLOB headers ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
FILE(GLOB core ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
# Files.
SET(HEADER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include)
SET(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src)
SET(HPM_PUBLIC_HEADERS
${HEADER_PATH}/Ext/HCAABB.hpp
${HEADER_PATH}/Ext/HCBoundingSphere.hpp
${HEADER_PATH}/HCMatrix4x4.hpp
${HEADER_PATH}/HCMatrix3x3.hpp
${HEADER_PATH}/Ext/HCOBB.hpp
${HEADER_PATH}/Ext/HCONB.hpp
${HEADER_PATH}/Ext/HCPlane.hpp
${HEADER_PATH}/HCQuaternion.hpp
${HEADER_PATH}/Ext/HCRay.hpp
${HEADER_PATH}/HCTypes.hpp
${HEADER_PATH}/HCVector2.hpp
${HEADER_PATH}/HCVector3.hpp
${HEADER_PATH}/HCVector4.hpp
${HEADER_PATH}/Hpm.hpp
)
SET(HPMCPP_INCLUDE_SUB_DIR
${CMAKE_CURRENT_SOURCE_DIR}/include/)
SOURCE_GROUP(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Include Files" FILES ${HPM_PUBLIC_HEADERS})
SET(hpmcpp_core_src
${SRC_PATH}/hpmcpp.cpp )
SOURCE_GROUP(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${hpmcpp_core_src})
SET(hpmcpp_src
${hpmcpp_core_src}
${HPM_PUBLIC_HEADERS})
# Main library target for initializing the library.
ADD_LIBRARY(hpmcpp ${hpmcpp_src})
TARGET_LINK_LIBRARIES(hpmcpp hpm)
TARGET_INCLUDE_DIRECTORIES(hpmcpp
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
TARGET_SOURCES(hpmcpp PRIVATE ${hpmcpp_src})
ADD_DEPENDENCIES(hpmcpp hpm)
SET_PROPERTY(TARGET hpmcpp PROPERTY CXX_STANDARD 17)
SET_TARGET_PROPERTIES(hpmcpp PROPERTIES
#PUBLIC_HEADER "${HPM_PUBLIC_HEADERS}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib"
OUTPUT_NAME "${PROJECT_NAME}"
)
IF(BUILD_WITH_INSTALL)
IF(UNIX)
INCLUDE(GNUInstallDirs)
ENDIF()
INSTALL(DIRECTORY ${HPMCPP_INCLUDE_SUB_DIR} # source directory
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hpmcpp # target directory
COMPONENT ${LIBHPMCPP-DEV_COMPONENT}
)
# INSTALL(TARGETS hpmcpp
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
# )
# Create install package.
IF(CMAKE_CPACK_COMMAND AND UNIX AND BUILD_OPT_BUILD_PACKAGES)
# Packing information
SET(CPACK_PACKAGE_NAME "hpmcpp${VERSION_MAJOR}.${VERSION_MINOR}")
SET(CPACK_PACKAGE_CONTACT "Valdemar Lindberg" CACHE STRING "Package maintainer and PGP signer.")
SET(CPACK_PACKAGE_VENDOR "https://github.com/voldien/hpmcpp")
SET(CPACK_PACKAGE_DISPLAY_NAME "HPM-CPP ${VERSION}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY " - ${VERSION}")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Valdemar Lindberg")
SET(CPACK_PACKAGE_VERSION "${VERSION}.${PACKAGE_VERSION}" )
SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "hpmcpp${VERSION_MAJOR}.${VERSION_MINOR}")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
STRING(TOUPPER ${LIBHPMCPP-DEV_COMPONENT} "LIBHPMCPP-DEV_COMPONENT_UPPER")
#
SET(CPACK_COMPOENTT_${LIBHPMCPP-DEV_COMPONENT_UPPER}_DISPLAY_NAME "hpmcpp")
SET(CPACK_COMPONENT_${LIBHPMCPP-DEV_COMPONENT_UPPER}_DEPENDS "" )
SET(CPACK_COMPOENTT_${LIBHPMCPP-DEV_COMPONENT_UPPER}_DISPLAY_NAME "")
SET(CPACK_COMPONENT_${LIBHPMCPP-DEV_COMPONENT_UPPER}_DISPLAY_NAME "common headers and installs")
SET(CPACK_COMPONENT_${LIBHPMCPP-DEV_COMPONENT_UPPER}_DEPENDS "" )
SET(CPACK_DEBIAN_BUILD_DEPENDS debhelper cmake zlib1g-dev pkg-config)
# debian
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
SET(CPACK_DEBIAN_CMAKE_OPTIONS "")
SET(CPACK_DEBIAN_PACKAGE_SECTION "libs" )
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_COMPONENTS_ALL}")
SET(CPACK_DEBIAN_PACKAGE_SUGGESTS "")
SET(cPACK_DEBIAN_PACKAGE_NAME "hpmcpp")
SET(CPACK_DEBIAN_PACKAGE_REMOVE_SOURCE_FILES build doc obj samples packaging utils)
SET(CPACK_DEBIAN_PACKAGE_SOURCE_COPY svn export --force)
SET(CPACK_DEBIAN_CHANGELOG)
execute_process(COMMAND lsb_release -is
OUTPUT_VARIABLE _lsb_distribution OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _lsb_release_failed)
SET(CPACK_DEBIAN_DISTRIBUTION_NAME ${_lsb_distribution} CACHE STRING "Name of the distrubiton")
STRING(TOLOWER ${CPACK_DEBIAN_DISTRIBUTION_NAME} CPACK_DEBIAN_DISTRIBUTION_NAME)
IF( ${CPACK_DEBIAN_DISTRIBUTION_NAME} STREQUAL "ubuntu" )
SET(CPACK_DEBIAN_DISTRIBUTION_RELEASES lucid maverick natty oneiric precise CACHE STRING "Release code-names of the distrubiton release")
ENDIF()
SET(DPUT_HOST "" CACHE STRING "PPA repository to upload the debian sources")
INCLUDE(CPack)
INCLUDE(DebSourcePPA)
ENDIF()
ENDIF()
# Create distribution tarball.
IF( UNIX AND HPMCPP_STANDALONE )
Find_PACKAGE(UnixCommands REQUIRED)
SET(TARGETDIR "${PROJECT_NAME}-${VERSION}")
ADD_CUSTOM_TARGET(TARGET distribution
PROPERTY OUTPUT_NAME ${TARGETDIR}
COMMAND mkdir -p ${TARGETDIR}
COMMAND ${CP} -r src include CMakeLists.txt LICENSE ${TARGETDIR}
COMMAND ${TAR} cf - ${TARGETDIR} | ${GZIP} -c > ${TARGETDIR}.tar.gz
COMMAND ${RM} -r ${TARGETDIR})
ENDIF ()