forked from bwalex/tc-play
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
153 lines (119 loc) · 5.74 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
cmake_minimum_required (VERSION 2.6)
project (tcplay)
set (VERSION_MAJOR 2)
set (VERSION_MINOR 0)
find_package (PkgConfig)
include (CheckLibraryExists)
set (SRCS_COMMON tcplay.c crc32.c safe_mem.c io.c hdr.c humanize.c crypto.c generic_xts.c)
set (SRCS_LINUX crypto-gcrypt.c)
set (CFLAGS_LINUX "-D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE")
set (CFLAGS_WARN "-Wsystem-headers -Wall -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wold-style-definition -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs")
set (CFLAGS_DEBUG "-O0 -g3 -DDEBUG")
set (CFLAGS_OPT "-O3")
set (CFLAGS_VER "-DMAJ_VER=${VERSION_MAJOR} -DMIN_VER=${VERSION_MINOR}")
set (CFLAGS_COMMON "-std=c99 -fPIE ${CFLAGS_LINUX} ${CFLAGS_WARN} ${CFLAGS_VER}")
if ($ENV{DEBUG})
set (CFLAGS_COMMON "${CFLAGS_COMMON} ${CFLAGS_DEBUG}")
else()
set (CFLAGS_COMMON "${CFLAGS_COMMON} ${CFLAGS_OPT}")
endif()
pkg_check_modules(DEVMAPPER devmapper)
pkg_check_modules(UUID uuid)
find_library(GCRYPT_LIB gcrypt)
if (NOT DEVMAPPER_FOUND)
message(FATAL_ERROR "Could not find the devmapper library")
endif()
if (NOT UUID_FOUND)
message(FATAL_ERROR "Could not find the uuid library")
endif()
if (NOT GCRYPT_LIB)
message(FATAL_ERROR "Could not find the gcrypt library")
else()
set (GCRYPT_LDFLAGS "-lgcrypt -lgpg-error")
set (GCRYPT_CFLAGS "")
endif()
set (CMAKE_REQUIRED_LIBRARIES gpg-error)
# gcrypt>=1.5.0 required
check_library_exists(gcrypt gcry_kdf_derive "" HAVE_GCRYPT_PBKDF)
set (CMAKE_REQUIRED_LIBRARIES "")
if (HAVE_GCRYPT_PBKDF)
set (SRCS_PBKDF pbkdf2-gcrypt.c)
set (LDFLAGS_PBKDF "")
set (CFLAGS_PBKDF "")
set (PBKDF_BACKEND gcrypt)
else()
pkg_check_modules(OPENSSL openssl>=1.0.0a)
if (NOT OPENSSL_FOUND)
message(FATAL_ERROR "Could not find a gcrypt with gcry_kdf_derive() nor OpenSSL >= 1.0.0a")
endif()
set (SRCS_PBKDF pbkdf2-openssl.c)
set (LDFLAGS_PBKDF ${OPENSSL_LDFLAGS})
set (CFLAGS_PBKDF ${OPENSSL_CFLAGS})
set (PBKDF_BACKEND openssl)
endif()
if (NOT LIB_SUFFIX)
message(STATUS "")
message(STATUS "LIB_SUFFIX variable is not defined. It will be autodetected now.")
message(STATUS "You can set it manually with -DLIB_SUFFIX=<value> (e.g. 64).")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "\nSetting LIB_SUFFIX=64\n")
set (LIB_SUFFIX "64")
else()
message(STATUS "\nSetting LIB_SUFFIX=\n")
set (LIB_SUFFIX "")
endif()
endif()
add_executable(tcplay-bin main.c ${SRCS_COMMON} ${SRCS_LINUX} ${SRCS_PBKDF})
set_target_properties(tcplay-bin PROPERTIES OUTPUT_NAME tcplay)
set_target_properties(tcplay-bin PROPERTIES COMPILE_FLAGS "${CFLAGS_COMMON} ${DEVMAPPER_CFLAGS} ${UUID_CFLAGS} ${GCRYPT_CFLAGS}")
target_link_libraries(tcplay-bin ${DEVMAPPER_LDFLAGS} ${UUID_LDFLAGS} ${GCRYPT_LDFLAGS} ${LDFLAGS_PBKDF})
add_library(tcplay-so SHARED tcplay_api.c ${SRCS_COMMON} ${SRCS_LINUX} ${SRCS_PBKDF})
set_target_properties(tcplay-so PROPERTIES OUTPUT_NAME tcplay)
set_target_properties(tcplay-so PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR})
set_target_properties(tcplay-so PROPERTIES COMPILE_FLAGS "${CFLAGS_COMMON} ${DEVMAPPER_CFLAGS} ${UUID_CFLAGS} ${GCRYPT_CFLAGS}")
set_target_properties(tcplay-so PROPERTIES LINK_FLAGS "-Wl,--version-script=${PROJECT_SOURCE_DIR}/tcplay.map")
# XXX: revist linking libraries against so. Seems to be more common practice nowadays
target_link_libraries(tcplay-so ${DEVMAPPER_LDFLAGS} ${UUID_LDFLAGS} ${GCRYPT_LDFLAGS} ${LDFLAGS_PBKDF})
add_library(tcplay-static STATIC tcplay_api.c ${SRCS_COMMON} ${SRCS_LINUX} ${SRCS_PBKDF})
set_target_properties(tcplay-static PROPERTIES OUTPUT_NAME tcplay)
set_target_properties(tcplay-static PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
set_target_properties(tcplay-static PROPERTIES COMPILE_FLAGS "${CFLAGS_COMMON} ${DEVMAPPER_CFLAGS} ${UUID_CFLAGS} ${GCRYPT_CFLAGS}")
# Generate pkg-config file tcplay.pc
file(WRITE ${PROJECT_BINARY_DIR}/tcplay.pc "prefix=${CMAKE_INSTALL_PREFIX}
exec_prefix=${CMAKE_INSTALL_PREFIX}
libdir=${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}
includedir=${CMAKE_INSTALL_PREFIX}/include
Name: libtcplay
Description: tcplay as a library
Version: ${VERSION_MAJOR}.${VERSION_MINOR}
Requires.private: devmapper uuid
Libs: -L\${libdir} -ltcplay
Libs.private: -lgpg-error -lgcrypt
Cflags: -I\${includedir}
")
# Installation targets
install(TARGETS tcplay-bin tcplay-static tcplay-so
RUNTIME DESTINATION sbin COMPONENT bin
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT lib
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT lib-dev
)
install(FILES ${PROJECT_BINARY_DIR}/tcplay.pc DESTINATION lib${LIB_SUFFIX}/pkgconfig COMPONENT lib-dev)
install(FILES tcplay_api.h DESTINATION include COMPONENT lib-dev)
install(FILES tcplay.3 DESTINATION share/man/man3 COMPONENT lib-dev)
install(FILES tcplay.8 DESTINATION share/man/man8 COMPONENT bin)
# Optional CPack magic
set (CPACK_RPM_COMPONENT_INSTALL 1)
set (CPACK_DEB_COMPONENT_INSTALL 1)
set (CPACK_PACKAGE_NAME "tcplay")
set (CPACK_PACKAGE_CONTACT "Alex Hornung <[email protected]>")
set (CPACK_PACKAGE_VENDOR "Alex Hornung <[email protected]>")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "tcplay is a free (BSD-licensed), pretty much fully featured (including multiple keyfiles, cipher cascades, hidden volumes, etc) and stable TrueCrypt implementation.")
set (CPACK_PACAKGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}")
set (CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set (CPACK_PACKAGE_VERSION_PATCH "0")
set (CPACK_PACKAGE_LICENSE "2-clause BSD")
include(CPack)
cpack_add_component(bin DISPLAY_NAME bin REQUIRED INSTALL_TYPES all)
cpack_add_component(lib DISPLAY_NAME lib REQUIRED INSTALL_TYPES all)
cpack_add_component(lib-dev DISPLAY_NAME lib-dev REQUIRED INSTALL_TYPES all DEPENDS lib)