-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
97 lines (76 loc) · 3.03 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
cmake_minimum_required(VERSION 3.17)
project(FileDB VERSION 1.2
DESCRIPTION "File DB"
LANGUAGES CXX;C )
# Basic Includes
# Helps with installig
include(GNUInstallDirs)
# Can run CTest Tests if any
include(CTest)
# Helps with Exporting and Creating XXXConfig.cmake scripts
include(CMakePackageConfigHelpers)
# Set yes/no options
# OFF is default value
option(FileDB_ENABLE_DEBUG_HASHDB "Turn on low level debug verbose messages." OFF)
option(FileDB_ENABLE_TEMPLATE_COMPILE_TEST "Test compile template headers through dumb instantiations." OFF)
# Enable Address address and undefined behaviour sanitizers
option(FileDB_ENABLE_SANITIZERS "Enable Address and Undefined Behaviour Sanitizers" OFF)
# Get Pthread options
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Check for include files -- I am using the set from the filedb_config_internal.h.in file
include(CheckIncludeFile)
check_include_file(inttypes.h HAVE_INTTYPES_H)
check_include_file(memory.h HAVE_MEMORY_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(stdlib.h HAVE_STDLIB_H)
check_include_file(strings.h HAVE_STRINGS_H)
check_include_file(string.h HAVE_STRING_H)
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(unistd.h HAVE_UNISTD_H)
# Set appropriate variables in generated header
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/filedb_config_internal.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/src/filedb_config_internal.h)
# Check endianness
include(TestBigEndian)
TEST_BIG_ENDIAN(FileDB_BIG_ENDIAN)
if( FileDB_BIG_ENDIAN )
message(STATUS "System is big endian")
else()
message(STATUS "System is little endian")
endif()
# Deal with Sanitizer
if( FileDB_ENABLE_SANITIZERS )
include(cmake/CheckSanitizeOpts.cmake)
check_sanitizer_options( "${FileDB_ENABLE_SANITIZERS}" FileDB_SANITIZER_OPTS )
message(STATUS "FileDB: Setting Sanitizer options: ${FileDB_SANITIZER_OPTS}")
endif()
# Configure Filehash
add_subdirectory(filehash)
# Configure src/
add_subdirectory(src)
#install generated header file:
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/src/filedb_config_internal.h DESTINATION include )
#Install the filedb.cmake file which contains the exports for importing
install(EXPORT FileDBTargets NAMESPACE FileDB:: DESTINATION lib/cmake/FileDB )
#Create a packageConfig.cmake file
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/FileDBConfig.cmake"
INSTALL_DESTINATION "lib/cmake/FileDB"
)
# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/FileDBConfigVersion.cmake"
VERSION "${FileDB_VERSION_MAJOR}.${FileDB_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
# install it
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/FileDBConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/FileDBConfigVersion.cmake
DESTINATION lib/cmake/FileDB
)
# export package. Does nothing by default, but
# can have uses in specially set up configurations
export(PACKAGE FileDB)