-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
280 lines (238 loc) · 8.66 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#
# libInstPatch
#
# Copyright (C) 1999-2014 Element Green <[email protected]>
#
# See COPYING license file for distribution details
#
cmake_minimum_required ( VERSION 3.6 )
project ( libInstPatch C )
set ( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )
# libInstPatch package name
set ( PACKAGE "libinstpatch" )
# libInstPatch package version
set ( IPATCH_VERSION_MAJOR 1 )
set ( IPATCH_VERSION_MINOR 1 )
set ( IPATCH_VERSION_MICRO 6 )
set ( VERSION "${IPATCH_VERSION_MAJOR}.${IPATCH_VERSION_MINOR}.${IPATCH_VERSION_MICRO}" )
set ( IPATCH_VERSION "\"${VERSION}\"" )
# libinstpatch - Library version
# *** NOTICE ***
# Update library version upon each release (follow these steps in order)
# if any source code changes: REVISION++
# if any interfaces added/removed/changed: REVISION=0
# if any interfaces removed/changed (compatibility broken): CURRENT++
# if any interfaces have been added: AGE++
# if any interfaces have been removed/changed (compatibility broken): AGE=0
# This is not exactly the same algorithm as the libtool one, but the results are the same.
set ( LIB_VERSION_CURRENT 2 )
set ( LIB_VERSION_AGE 2 )
set ( LIB_VERSION_REVISION 0 )
set ( LIB_VERSION_INFO
"${LIB_VERSION_CURRENT}.${LIB_VERSION_AGE}.${LIB_VERSION_REVISION}" )
# Options disabled by default
option ( enable-debug "enable debugging (default=no)" off )
option ( GTKDOC_ENABLED "Create Gtk-Doc API reference (default=no)" off )
option ( INTROSPECTION_ENABLED "Create GObject Introspection typelib" off )
# Options enabled by default
option ( BUILD_SHARED_LIBS "Build a shared object or DLL" on )
# Initialize the library directory name suffix.
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( _init_lib_suffix "64" )
else ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( _init_lib_suffix "" )
endif ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
# Sane defaults for CMAKE_INSTALL_*
include ( GNUInstallDirs )
# Default install directory names
include ( DefaultDirs )
# Basic C library checks
include ( CheckSTDC )
include ( CheckIncludeFile )
check_include_file ( string.h HAVE_STRING_H )
check_include_file ( stdlib.h HAVE_STDLIB_H )
check_include_file ( stdio.h HAVE_STDIO_H )
check_include_file ( math.h HAVE_MATH_H )
check_include_file ( errno.h HAVE_ERRNO_H )
check_include_file ( stdarg.h HAVE_STDARG_H )
check_include_file ( unistd.h HAVE_UNISTD_H )
check_include_file ( locale.h HAVE_LOCALE_H )
check_include_file ( xlocale.h HAVE_XLOCALE_H )
if ( WIN32 )
# Check presence of MS include files
check_include_file ( io.h HAVE_IO_H )
endif( WIN32 )
unset ( IPATCH_CPPFLAGS CACHE )
unset ( IPATCH_LIBS CACHE )
# Options for the GNU C compiler only
if ( CMAKE_COMPILER_IS_GNUCC )
if ( NOT APPLE )
set ( CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed" )
set ( CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
endif ( NOT APPLE )
set ( GNUCC_WARNING_FLAGS "-Wall")
set ( CMAKE_C_FLAGS "-pedantic ${CMAKE_C_FLAGS}" )
set ( CMAKE_C_FLAGS_DEBUG "-g -DDEBUG -fsanitize=undefined ${GNUCC_WARNING_FLAGS} ${CMAKE_C_FLAGS_DEBUG}" )
set ( CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG ${GNUCC_WARNING_FLAGS} ${CMAKE_C_FLAGS_RELEASE}" )
set ( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${GNUCC_WARNING_FLAGS} ${CMAKE_C_FLAGS_RELWITHDEBINFO}" )
endif ( CMAKE_COMPILER_IS_GNUCC )
if ( MSVC )
# statically link in the CRT library to avoid a bunch of runtime DLL dependencies and allow
# the CI windows builds to be run under WinXP
foreach ( flag_var
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if ( ${flag_var} MATCHES "/MD" )
string ( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
endif ( ${flag_var} MATCHES "/MD" )
endforeach ( flag_var )
endif ( MSVC )
if ( enable-debug )
set ( CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Choose the build type, options: Debug Release RelWithDebInfo" FORCE )
set ( IPATCH_DEBUG 1 )
endif ( enable-debug )
unset ( MINGW32 CACHE )
if ( WIN32 )
# MinGW compiler (a Windows GCC port)
if ( MINGW )
set ( MINGW32 1 )
add_definitions ( -mms-bitfields )
endif ( MINGW )
else ( WIN32 )
set ( IPATCH_LIBS "m" )
endif ( WIN32 )
unset ( ENABLE_DEBUG CACHE )
unset ( DEBUG CACHE )
if ( CMAKE_BUILD_TYPE MATCHES "Debug" )
set ( ENABLE_DEBUG 1 )
set ( DEBUG 1 )
endif ( CMAKE_BUILD_TYPE MATCHES "Debug" )
# Mandatory tool: pkg-config
find_package ( PkgConfig REQUIRED )
# Mandatory libraries: gobject, glib and gthread
pkg_check_modules ( GOBJECT REQUIRED gobject-2.0>=2.12 glib-2.0>=2.12 gthread-2.0>=2.12 )
# Disable deprecation warnings for now (fixed in master)
add_definitions ( -DGLIB_DISABLE_DEPRECATION_WARNINGS )
include ( UnsetPkgConfig )
# Check for libsndfile
find_package ( SndFile 1.2.1 )
if ( NOT SNDFILE_FOUND )
pkg_check_modules ( SNDFILE REQUIRED sndfile>=1.2.1 )
endif()
# Check for GObjectIntrospection binding
if (INTROSPECTION_ENABLED)
include (FindGObjectIntrospection)
endif ()
# Check for Gtk-Doc
if (GTKDOC_ENABLED)
find_package(GtkDoc)
endif ()
# General configuration file
configure_file ( ${CMAKE_SOURCE_DIR}/config.h.cmake
${CMAKE_BINARY_DIR}/config.h )
add_definitions ( -DHAVE_CONFIG_H )
# Version and master libinstpatch.h file
configure_file ( ${CMAKE_SOURCE_DIR}/libinstpatch/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/libinstpatch/version.h )
configure_file ( ${CMAKE_SOURCE_DIR}/libinstpatch/libinstpatch.h.in
${CMAKE_CURRENT_BINARY_DIR}/libinstpatch/libinstpatch.h )
set (INSTPATCH_INSTALL_TARGET "libinstpatch-${LIB_VERSION_CURRENT}")
# pkg-config support
if ( UNIX OR MINGW OR WIN32)
# stamp library name with version current value (for Windows only)
if(MINGW OR WIN32)
set ( lib_version_suffix ${LIB_VERSION_CURRENT} )
else(MINGW OR WIN32)
set ( lib_version_suffix 1.0 )
endif(MINGW OR WIN32)
configure_file ( libinstpatch-1.0.pc.in
${CMAKE_BINARY_DIR}/libinstpatch-1.0.pc IMMEDIATE @ONLY )
install ( FILES ${CMAKE_BINARY_DIR}/libinstpatch-1.0.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
endif ( UNIX OR MINGW OR WIN32)
# Extra targets for Unix build environments
if ( UNIX )
# uninstall custom target
configure_file ( "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target ( uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
endif ( UNIX )
# Process subdirectories
add_subdirectory ( libinstpatch )
add_subdirectory ( utils )
add_subdirectory ( docs )
# CPack support
set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "libInstPatch instrument editing library" )
set ( CPACK_PACKAGE_VENDOR "swami.sourceforge.net" )
set ( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md" )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING" )
set ( CPACK_PACKAGE_VERSION_MAJOR ${IPATCH_VERSION_MAJOR} )
set ( CPACK_PACKAGE_VERSION_MINOR ${IPATCH_VERSION_MINOR} )
set ( CPACK_PACKAGE_VERSION_PATCH ${IPATCH_VERSION_MICRO} )
# source packages
set ( CPACK_SOURCE_GENERATOR TGZ;TBZ2;ZIP )
set ( CPACK_SOURCE_IGNORE_FILES "/.svn/;~$;.cproject;.project;/.settings/;${CPACK_SOURCE_IGNORE_FILES}" )
set ( CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE}-${VERSION}" )
set ( CPACK_SOURCE_STRIP_FILES OFF )
# binary packages
include ( InstallRequiredSystemLibraries )
set ( CPACK_GENERATOR STGZ;TGZ;TBZ2;ZIP )
set ( CPACK_PACKAGE_NAME ${PACKAGE} )
set ( CPACK_STRIP_FILES ON )
include ( CPack )
message ( "Build options:" )
if ( ENABLE_DEBUG )
message ( "Debug: yes" )
else ( ENABLE_DEBUG )
message ( "Debug: no" )
endif ( ENABLE_DEBUG )
if (INTROSPECTION_FOUND)
message ( "GObjectIntrospection: yes" )
else (INTROSPECTION_FOUND)
message ( "GObjectIntrospection: no" )
endif(INTROSPECTION_FOUND)
if (GTKDOC_FOUND)
message ( "Gtk-Doc API reference: yes" )
else (GTKDOC_FOUND)
message ( "Gtk-Doc API reference: no" )
endif(GTKDOC_FOUND)
file(GLOB_RECURSE
ALL_SOURCE_FILES
LIST_DIRECTORIES false
${CMAKE_SOURCE_DIR}/*.[chi]
${CMAKE_SOURCE_DIR}/*.[chi]pp
${CMAKE_SOURCE_DIR}/*.[chi]xx
${CMAKE_SOURCE_DIR}/*.cc
${CMAKE_SOURCE_DIR}/*.hh
${CMAKE_SOURCE_DIR}/*.ii
${CMAKE_SOURCE_DIR}/*.[CHI]
)
find_program ( ASTYLE "astyle" )
if ( ASTYLE )
add_custom_target(
format
COMMAND ${ASTYLE}
-A1
-xb
-j
-k3
-p
-f
-n
-U
${ALL_SOURCE_FILES}
)
endif ( ASTYLE)