-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
196 lines (164 loc) · 6.1 KB
/
CMakeLists.txt
File metadata and controls
196 lines (164 loc) · 6.1 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# -*- mode: cmake; coding: utf-8 -*-
# This file is part of Pathie.
#
# Copyright © 2015, 2017, 2019 Marvin Gülker
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 2.8)
enable_language(CXX)
project(Pathie)
########################################
# Version number
set(PATHIE_VERSION_MAJOR 0)
set(PATHIE_VERSION_MINOR 1)
set(PATHIE_VERSION_PATCH 1)
execute_process(COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${Pathie_SOURCE_DIR}
OUTPUT_VARIABLE PATHIE_VERSION_GIT
OUTPUT_STRIP_TRAILING_WHITESPACE)
# If git was not available, unset empty variable
if (NOT(PATHIE_VERSION_GIT))
unset(PATHIE_VERSION_GIT)
endif()
########################################
# Flags & Options
option(PATHIE_BUILD_STREAM_REPLACEMENTS "Build the std::ifstream and std::ofstream replacements (experimental)." OFF)
option(PATHIE_ASSUME_UTF8_ON_UNIX "Assume file paths under UNIX to be always encoded in UTF-8." OFF)
########################################
# Extra flags
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_EXTENSIONS OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ")
endif()
# We only support Vista upwards. See http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
# for the macro values.
if (WIN32)
add_definitions("-D_WIN32_WINNT=0x0600") # Vista
add_definitions("-D_WIN32_IE=0x0800") # IE 8.0+
add_definitions("-DWINVER=0x0600") # Vista
elseif(APPLE)
add_definitions("-D_DARWIN_C_SOURCE")
add_definitions("-D_PATHIE_UNIX=1")
elseif(UNIX)
add_definitions("-D_PATHIE_UNIX=1")
add_definitions("-D_POSIX_C_SOURCE=200112L")
endif()
add_definitions("-DPATHIE_VERSION_MAJOR=${PATHIE_VERSION_MAJOR}")
add_definitions("-DPATHIE_VERSION_MINOR=${PATHIE_VERSION_MINOR}")
add_definitions("-DPATHIE_VERSION_PATCH=${PATHIE_VERSION_PATCH}")
if (PATHIE_VERSION_GIT)
add_definitions("-DPATHIE_VERSION_GIT=\"${PATHIE_VERSION_GIT}\"")
endif()
if (PATHIE_ASSUME_UTF8_ON_UNIX)
add_definitions("-DPATHIE_ASSUME_UTF8_ON_UNIX=1")
endif()
########################################
# Adjustments to cmake’s defaults
set(CMAKE_BUILD_SHARED_LIBS On CACHE BOOL "Additionally to the static lib, build the shared lib")
########################################
# Source files
list(APPEND pathie_sources
"src/errors.cpp"
"src/entry_iterator.cpp"
"src/path.cpp"
"src/temp.cpp"
"src/pathie.cpp")
if (PATHIE_BUILD_STREAM_REPLACEMENTS)
list(APPEND pathie_sources
"src/pathie_ifstream.cpp"
"src/pathie_ofstream.cpp")
endif()
file(GLOB_RECURSE test_sources
"test/*.cpp")
########################################
# Targets
# Libraries
add_library(pathie STATIC ${pathie_sources})
if(APPLE)
target_link_libraries(pathie iconv)
endif()
if (CMAKE_BUILD_SHARED_LIBS)
add_library(pathie-dynamic SHARED ${pathie_sources})
set_target_properties(pathie-dynamic PROPERTIES OUTPUT_NAME pathie)
if(APPLE)
target_link_libraries(pathie-dynamic iconv)
endif()
endif()
if(WIN32)
target_link_libraries(pathie shlwapi)
if (CMAKE_BUILD_SHARED_LIBS)
target_link_libraries(pathie-dynamic shlwapi)
endif()
endif()
# Tests
# TODO: How to only do not test with crosscompilation?
#if (NOT(WIN32))
# foreach(testfile ${test_sources})
# get_filename_component(testtargetname "${testfile}" NAME_WE)
# set(testtargetname "${testtargetname}.test")
# message(STATUS "TESTFILE: ${testtargetname}")
# #string(REPLACE ".cpp" ".test" testtargetname ${testfile})
# add_executable(${testtargetname} ${testfile} ${Pathie_SOURCE_DIR}/test/testhelpers.hpp)
# endforeach()
#endif()
########################################
# Installation information
install(TARGETS pathie
DESTINATION lib)
if (CMAKE_BUILD_SHARED_LIBS)
install(TARGETS pathie-dynamic
DESTINATION lib)
endif()
install(FILES
"include/pathie/errors.hpp"
"include/pathie/entry_iterator.hpp"
"include/pathie/path.hpp"
"include/pathie/temp.hpp"
"include/pathie/pathie.hpp"
DESTINATION include/pathie)
if (PATHIE_BUILD_STREAM_REPLACEMENTS)
install(FILES
"include/pathie/pathie_ifstream.hpp"
"include/pathie/pathie_ofstream.hpp"
DESTINATION include/pathie)
endif()
########################################
# Status message
message(STATUS "--------------- Build info summary ----------------")
message(STATUS "Pathie version: ${PATHIE_VERSION_MAJOR}.${PATHIE_VERSION_MINOR}.${PATHIE_VERSION_PATCH}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
if (CMAKE_CROSSCOMPILING)
message(STATUS "Crosscompiling: Yes")
else()
message(STATUS "Crosscompiling: No")
endif()
if (UNIX)
message(STATUS "Assume UTF-8: ${PATHIE_ASSUME_UTF8_ON_UNIX}")
else()
message(STATUS "Assume UTF-8: option unavailable on this target")
endif()
message(STATUS "Stream replacments: ${PATHIE_BUILD_STREAM_REPLACEMENTS}")
message(STATUS "---------------------------------------------------")