-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
180 lines (152 loc) · 6.86 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
# First set Matlab_ROOT_DIR environment variable to your installed matlab path,
# such as 'export Matlab_ROOT_DIR=/usr/local/MATLAB/R2017b'!
# (GNUC: gcc for C file, g++ for CXX files)
# Building makefiles:
# mkdir build
# cd build
# cmake -G "Visual Studio 14 2015 Win64" ..
# cmake --build . --target mksqlite --config Release -j 16
#set(CMAKE_VERBOSE_MAKEFILE ON)
# Superseed options from other modules
macro(SET_OPTION option value)
set(${option} ${value} CACHE INTERNAL "" FORCE)
endmacro()
cmake_minimum_required( VERSION 3.16 )
set( CMAKE_CONFIGURATION_TYPES Release Debug )
project( mksqlite )
option( MKSQLITE_CONFIG_USE_UUID "UUID extension" ON )
option( MKSQLITE_CONFIG_USE_HEAP_CHECK "Internal heap checking" OFF )
option( MKSQLITE_CONFIG_NULL_AS_NAN "Use NaN instead of NULL values by default" OFF )
option( MKSQLITE_CONFIG_COMPRESSION_CHECK "Always check compressed data (slower)" OFF )
option( MKSQLITE_CONFIG_CONVERT_UTF8 "Text interchange with MATLAB in UTF8 char format" ON )
option( MKSQLITE_CONFIG_USE_LOGGING "Enable logging" OFF )
option( SQLITE_ENABLE_MATH_FUNCTIONS "Enable SQLite built-in mathematical SQL functions" ON )
set( MKSQLITE_CONFIG_MAX_NUM_OF_DBS 20 CACHE STRING "Maximum number of databases opened at once" )
set( MKSQLITE_CONFIG_BUSYTIMEOUT 1000 CACHE STRING "Default SQL busy timeout in milliseconds (1000)" )
if( EXISTS ${CMAKE_SOURCE_DIR}/c-blosc )
option( MKSQLITE_CONFIG_USE_BLOSC "Build BLOSC" ON )
SET_OPTION( BUILD_BENCHMARKS OFF )
SET_OPTION( BUILD_SHARED OFF )
SET_OPTION( BUILD_STATIC ON )
SET_OPTION( BUILD_TESTS OFF )
else()
set( MKSQLITE_CONFIG_USE_BLOSC OFF CACHE INTERNAL "" FORCE )
endif()
set( CMAKE_POSITION_INDEPENDENT_CODE ON )
if( MSVC )
# Turn off misguided "secure CRT" warnings in MSVC.
# Microsoft wants people to use the MS-specific <function>_s
# versions of certain C functions but this is difficult to do
# in platform-independent code.
add_definitions( -D_CRT_SECURE_NO_WARNINGS )
endif()
if( UNIX )
set( MATH_LIB m )
endif()
set( MATLAB_FIND_DEBUG 1 )
find_package( Matlab QUIET REQUIRED COMPONENTS MX_LIBRARY )
if( MATLAB_FOUND )
message( STATUS "MATLAB Found, MATLAB MEX will be compiled." )
# message( STATUS ${Matlab_LIBRARIES} )
else()
message( FATAL_ERROR "MATLAB not found...nothing will be built." )
endif()
add_definitions( -DMATLAB_MEX_FILE )
# set up matlab libraries
include_directories( ${Matlab_INCLUDE_DIRS} c-blosc )
# Parse mksqlite version when creating makefiles
if( WIN32 )
# Windows needs an extra prefix!
set( CMD_PREFIX CMD /c )
endif()
execute_process( COMMAND ${CMD_PREFIX} git describe --tags --abbrev=4
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE MKSQLITE_VERSION_STRING
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE )
if( MKSQLITE_VERSION_STRING STREQUAL "" )
message( "Didn't got git revision information, using local information (git_revision.h)!" )
file( READ ${CMAKE_SOURCE_DIR}/git_revision.h MKSQLITE_REVISION_H_CONTENT )
string( REGEX REPLACE ".*#define[ \t\r\n]+MKSQLITE_VERSION_STRING[ \t\r\n]+\"([^\"]*)\".*" "\\1" MKSQLITE_VERSION_STRING ${MKSQLITE_REVISION_H_CONTENT} )
endif()
if( MKSQLITE_VERSION_STRING STREQUAL "" )
message( FATAL_ERROR "No " ${CMAKE_PROJECT_NAME} " revision information available!" )
endif()
string( REGEX REPLACE "([0-9]+)\.([0-9]+).*" "\\1" MKSQLITE_VERSION_MAJOR ${MKSQLITE_VERSION_STRING} )
string( REGEX REPLACE "([0-9]+)\.([0-9]+).*" "\\2" MKSQLITE_VERSION_MINOR ${MKSQLITE_VERSION_STRING} )
configure_file( ${CMAKE_SOURCE_DIR}/git_revision.h.in ${CMAKE_SOURCE_DIR}/git_revision.h )
configure_file( ${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_SOURCE_DIR}/config.h )
message( STATUS ${CMAKE_PROJECT_NAME} " revision is " ${MKSQLITE_VERSION_MAJOR}.${MKSQLITE_VERSION_MINOR} )
# Add dependencies
set( src md5 sqlite )
add_subdirectory( sqlite )
add_subdirectory( md5 )
if( MKSQLITE_CONFIG_USE_BLOSC )
add_subdirectory( c-blosc )
include_directories( c-blosc )
if( MINGW )
# Workaround for compile error with MinGW
# [https://github.com/Blosc/bcolz], issue #405
set_source_files_properties( ${CMAKE_SOURCE_DIR}/c-blosc/blosc/shuffle.c DIRECTORY ${CMAKE_SOURCE_DIR}/c-blosc/blosc PROPERTIES COMPILE_FLAGS -mxsave )
get_source_file_property( test ${CMAKE_SOURCE_DIR}/c-blosc/blosc/shuffle.c DIRECTORY ${CMAKE_SOURCE_DIR}/c-blosc/blosc COMPILE_FLAGS )
message( STATUS ${test} )
#target_compile_options( blosc_static PUBLIC -mxsave )
endif()
set( src ${src} blosc_static )
endif()
if( MKSQLITE_CONFIG_USE_LOGGING )
add_subdirectory( logging )
set( src ${src} logging )
endif()
# C++11
set( CMAKE_CXX_STANDARD 11 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( CMAKE_CXX_EXTENSIONS OFF )
# Main source file and libraries
matlab_add_mex( NAME ${CMAKE_PROJECT_NAME} SRC mksqlite.cpp )
target_link_libraries( ${CMAKE_PROJECT_NAME} ${Matlab_LIBRARIES} ${src} )
get_filename_component( Matlab_MX_LIBRARY_PATH ${Matlab_MX_LIBRARY} DIRECTORY )
get_filename_component( Matlab_MX_LIBRARY_EXT ${Matlab_MX_LIBRARY} EXT )
target_link_libraries( ${CMAKE_PROJECT_NAME} ${Matlab_MX_LIBRARY_PATH}/libut${Matlab_MX_LIBRARY_EXT} )
# install to /bin and /share by default
file( GLOB MKSQLITE_DOC_FILES doxy/chm/* docs/* )
file( GLOB MKSQLITE_TEST_FILES test/*.m )
install( TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION bin )
install( FILES sql.m mksqlite.m mksqlite_en.m DESTINATION bin )
install( FILES LICENSE README.MD DESTINATION share/doc/mksqlite )
install( FILES ${MKSQLITE_DOC_FILES} DESTINATION share/doc/mksqlite )
install( FILES ${MKSQLITE_TEST_FILES} DESTINATION share/doc/mksqlite/examples )
if( MKSQLITE_CONFIG_USE_BLOSC )
install( DIRECTORY c-blosc/LICENSES DESTINATION share/doc/mksqlite/blosc )
endif()
# CPack
include( InstallRequiredSystemLibraries )
set( CPACK_GENERATOR TGZ ZIP )
set( CPACK_SOURCE_GENERATOR TGZ ZIP )
set( CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/package )
set( CPACK_PACKAGE_VERSION_MAJOR ${MKSQLITE_VERSION_MAJOR} )
set( CPACK_PACKAGE_VERSION_MINOR ${MKSQLITE_VERSION_MINOR} )
set( CPACK_PACKAGE_VERSION_PATCH "" )
set( CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR} )
set( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.MD" )
set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "A MATLAB(R) Mex-DLL to SQLite Databases" )
set( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" )
set( CPACK_SOURCE_IGNORE_FILES
# Files specific to version control.
"/\\\\.git/"
"/\\\\.gitattributes$"
"/\\\\.github/"
"/\\\\.gitignore$"
"/\\\\.hooks-config$"
# Package build.
"/\\\\.build/"
# Blosc submodule
"/c-blosc/"
# Temporary files.
"\\\\.#"
"/#"
"~$"
)
set( CPACK_STRIP_FILES TRUE )
set( CPACK_SOURCE_STRIP_FILES TRUE )
include( CPack )