-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
153 lines (131 loc) · 4.47 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
# Project settings
cmake_minimum_required( VERSION 3.15 )
project( osmanip-build
VERSION 1.0
DESCRIPTION "Build system for osmanip."
LANGUAGES CXX
)
# Error if building out of a build directory
file( TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH )
if( EXISTS "${LOC_PATH}" )
message( FATAL_ERROR "You cannot build in a source directory (or any directory with "
"CMakeLists.txt file). Please make a build subdirectory. Feel free to "
"remove CMakeCache.txt and CMakeFiles." )
endif()
# Info about the build type
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
message( STATUS "Build type: DEBUG" )
add_compile_definitions( DEBUG_OSMANIP )
else()
message( STATUS "Build type: RELEASE" )
endif()
# Set compiler options
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( CMAKE_CXX_EXTENSIONS OFF )
# Include directories
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include )
# Fetching deps
add_subdirectory( deps )
# Adding specific compiler flags
if( CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
set( COMPILE_FLAGS "/Wall /Yd /Oy /Gw" )
else()
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
set( COMPILE_FLAGS "-Wall -Wextra -pedantic -Wno-reorder -fno-omit-frame-pointer -fdata-sections -g" )
else()
set( COMPILE_FLAGS "-Wall -Wextra -pedantic -Wno-reorder -fdata-sections" )
endif()
endif()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}" )
# Creating the static library
file( GLOB_RECURSE SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/manipulators/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/utility/*.cpp
)
add_library( osmanip STATIC ${SRC_FILES} )
add_library( osmanip::osmanip ALIAS osmanip )
# Adding cppcheck properties
find_program( CPPCHECK_FOUND cppcheck )
if ( CPPCHECK_FOUND AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
set( cppcheck_options "--enable=warning" "--inconclusive" "--force" "--inline-suppr" )
set_target_properties( osmanip PROPERTIES CXX_CPPCHECK "${CPPCHECK_FOUND}" )
endif()
# Format the code
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
option( FORMAT "Format the code using clang-format" ON )
if( FORMAT )
find_program( CLANG_FORMAT_EXECUTABLE clang-format )
if( CLANG_FORMAT_EXECUTABLE )
message( STATUS "clang-format found: ${CLANG_FORMAT_EXECUTABLE}" )
file( GLOB_RECURSE SOURCE_FILES
${CMAKE_SOURCE_DIR}/src/**/*.cpp
${CMAKE_SOURCE_DIR}/include/osmanip/**/*.hpp
${CMAKE_SOURCE_DIR}/test/unit_tests/**/*.cpp
${CMAKE_SOURCE_DIR}/examples/**/*.cpp
)
add_custom_target(format
COMMAND ${CLANG_FORMAT_EXECUTABLE}
-i
${SOURCE_FILES}
)
add_dependencies( osmanip format )
else()
message(STATUS "clang-format not found. Skipping code formatting.")
endif()
endif()
endif()
# Compiling unit tests
option( OSMANIP_TESTS "Enable / disable tests." ON )
if( CMAKE_BUILD_TYPE STREQUAL "Debug" AND OSMANIP_TESTS )
add_subdirectory( test/unit_tests )
else()
message( STATUS "Skipping tests." )
endif()
# Compiling examples
add_subdirectory( examples )
# Setting installation paths
target_include_directories( osmanip INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
# Installing headers
INSTALL(
DIRECTORY include/osmanip
DESTINATION include
)
# Creating the package files
install(
TARGETS osmanip
EXPORT osmanipTargets
DESTINATION lib
)
install(
EXPORT osmanipTargets
FILE osmanipTargets.cmake
NAMESPACE osmanip::
DESTINATION lib/cmake/osmanip
)
# Configure package files
include( CMakePackageConfigHelpers )
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/osmanipConfig.cmake"
INSTALL_DESTINATION "lib/cmake/osmanip"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/osmanipConfigVersion.cmake"
VERSION "${Tutorial_VERSION_MAJOR}.${Tutorial_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
install( FILES
${CMAKE_CURRENT_BINARY_DIR}/osmanipConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/osmanipConfigVersion.cmake
DESTINATION lib/cmake/osmanip
)
export( EXPORT osmanipTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/osmanipTargets.cmake"
)