forked from paolostivanin/OTPClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
134 lines (110 loc) · 4.63 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
cmake_minimum_required(VERSION 3.16)
project(OTPClient VERSION "3.6.0" LANGUAGES "C")
include(GNUInstallDirs)
configure_file("src/common/version.h.in" "version.h")
set (GETTEXT_PACKAGE ${CMAKE_PROJECT_NAME})
include_directories(${PROJECT_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
option(IS_FLATPAK "Use flatpak app's config folder to store the database" OFF)
option(BUILD_GUI "Build the GTK UI" ON)
option(BUILD_CLI "Build the CLI" ON)
set(CMAKE_C_STANDARD 11)
set(COMMON_C_FLAGS
"-Wall -Wextra -O3 -Wformat=2 -Wmissing-format-attribute -fstack-protector-strong"
"-Wundef -Wmissing-format-attribute -fdiagnostics-color=always"
"-Wstrict-prototypes -Wunreachable-code -Wchar-subscripts"
"-Wwrite-strings -Wpointer-arith -Wbad-function-cast -Wcast-align"
"-Werror=format-security -Werror=implicit-function-declaration -Wno-sign-compare"
"-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
)
if(CMAKE_COMPILER_IS_GNUCC)
list(APPEND COMMON_C_FLAGS "-pie -fPIE")
endif()
if(IS_FLATPAK)
list(APPEND COMMON_C_FLAGS "-DIS_FLATPAK")
endif()
string(REPLACE ";" " " COMMON_C_FLAGS "${COMMON_C_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_C_FLAGS}")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(COMMON_LINKER_FLAGS
"-Wl,--no-add-needed -Wl,--as-needed -Wl,--no-undefined"
"-Wl,-z,relro,-z,now"
)
string(REPLACE ";" " " COMMON_LINKER_FLAGS "${COMMON_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COMMON_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${COMMON_LINKER_FLAGS}")
endif()
add_definitions(-DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-add-needed -Wl,--as-needed -Wl,--no-undefined")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-add-needed -Wl,--as-needed")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,relro,-z,now")
endif()
find_package(PkgConfig REQUIRED)
find_package(Protobuf 3.6.0 REQUIRED)
find_package(Gcrypt 1.10.1 REQUIRED)
pkg_check_modules(COTP REQUIRED cotp>=3.0.0)
pkg_check_modules(PNG REQUIRED libpng>=1.6.30)
pkg_check_modules(JANSSON REQUIRED jansson>=2.12)
pkg_check_modules(ZBAR REQUIRED zbar>=0.20)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0>=3.24.0)
pkg_check_modules(GLIB2 REQUIRED glib-2.0>=2.68.0)
pkg_check_modules(GIO REQUIRED gio-2.0>=2.68.0)
pkg_check_modules(UUID REQUIRED uuid>=2.34.0)
pkg_check_modules(PROTOC REQUIRED libprotobuf-c>=1.3.0)
pkg_check_modules(LIBSECRET REQUIRED libsecret-1>=0.20.0)
pkg_check_modules(LIBQRENCODE REQUIRED libqrencode>=4.0.2)
set(COMMON_INCDIRS
${GCRYPT_INCLUDE_DIRS}
${COTP_INCLUDE_DIRS}
${JANSSON_INCLUDE_DIRS}
${UUID_INCLUDE_DIRS}
${PROTOC_INCLUDE_DIRS}
${LIBSECRET_INCLUDE_DIRS}
${LIBQRENCODE_INCLUDE_DIRS}
)
set(COMMON_LIBS
${GCRYPT_LIBRARIES}
${COTP_LIBRARIES}
${JANSSON_LIBRARIES}
${UUID_LIBRARIES}
${PROTOC_LIBRARIES}
${LIBSECRET_LIBRARIES}
${LIBQRENCODE_LIBRARIES}
)
if(BUILD_GUI)
add_subdirectory(src/gui)
target_link_libraries(${PROJECT_NAME}
${GTK3_LIBRARIES}
${PNG_LIBRARIES}
${ZBAR_LIBRARIES}
${COMMON_LIBS}
)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "otpclient")
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES data/com.github.paolostivanin.OTPClient.desktop DESTINATION share/applications)
install(FILES man/otpclient.1.gz DESTINATION share/man/man1)
set(GUI_UI_FILES
src/gui/ui/otpclient.ui
src/gui/ui/add_popover.ui
src/gui/ui/settings_popover.ui
src/gui/ui/shortcuts.ui
)
install(FILES ${GUI_UI_FILES} DESTINATION share/otpclient)
set(GUI_ICON_FILES
data/icons/com.github.paolostivanin.OTPClient.svg
data/icons/com.github.paolostivanin.OTPClient-symbolic.svg
)
install(FILES ${GUI_ICON_FILES} DESTINATION share/icons/hicolor/scalable/apps)
endif ()
if(BUILD_CLI)
add_subdirectory(src/cli)
target_link_libraries(${PROJECT_NAME}-cli
${COMMON_LIBS}
)
set_target_properties(${PROJECT_NAME}-cli PROPERTIES OUTPUT_NAME "otpclient-cli")
install(TARGETS ${PROJECT_NAME}-cli DESTINATION bin)
install(FILES man/otpclient-cli.1.gz DESTINATION share/man/man1)
endif()
install(FILES data/com.github.paolostivanin.OTPClient.appdata.xml DESTINATION share/metainfo)