forked from lastpass/lastpass-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
139 lines (113 loc) · 5.82 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
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.1)
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake > 2.8.4 is required
cmake_minimum_required(VERSION 2.8)
ELSE()
cmake_minimum_required(VERSION 3.1)
ENDIF()
project(lpass)
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.4)
# pkg_get_variable is not available until CMake >= 3.4.0
# Debian oldstable still packages CMake 3.0.2
function(pkg_get_variable _output_name _pkg _name)
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=${_name} ${_pkg}
OUTPUT_VARIABLE _pkg_result
OUTPUT_STRIP_TRAILING_WHITESPACE)
set("${_output_name}" "${_pkg_result}" CACHE STRING "pkg-config variable ${_name} of ${_pkg}")
endfunction()
pkg_get_variable(BASH_COMPLETION_PREFIX bash-completion prefix)
if(BASH_COMPLETION_PREFIX)
set(BASH_COMPLETION_FOUND TRUE)
endif()
ELSE()
include(FindPkgConfig)
pkg_search_module(BASH_COMPLETION bash-completion)
ENDIF()
if((APPLE) AND (NOT DEFINED OPENSSL_ROOT_DIR))
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
endif()
if((APPLE))
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/opt/curl/lib/pkgconfig")
endif()
find_package(LibXml2 REQUIRED)
include_directories(${LIBXML2_INCLUDE_DIR})
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})
set(PROJECT_NAME lpass)
file(GLOB PROJECT_HEADERS *.h version.h)
file(GLOB PROJECT_SOURCES *.c)
set(PROJECT_DEFINITIONS "_GNU_SOURCE")
set(PROJECT_FLAGS "-std=gnu99 -pedantic -Wall -Wextra -Wno-language-extension-token")
if(APPLE)
set(PROJECT_FLAGS "${PROJECT_FLAGS} -Wno-deprecated-declarations")
endif()
execute_process(COMMAND ./LASTPASS-VERSION-GEN
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
# Main lpass executable
add_executable(${PROJECT_NAME} ${PROJECT_HEADERS} ${PROJECT_SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES
C_STANDARD 99
COMPILE_FLAGS ${PROJECT_FLAGS}
COMPILE_DEFINITIONS ${PROJECT_DEFINITIONS}
)
target_link_libraries(${PROJECT_NAME} ${LIBXML2_LIBRARIES} ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES})
if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
target_link_libraries(${PROJECT_NAME} "-lkvm")
endif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
add_custom_command(OUTPUT lpass.1 DEPENDS ${CMAKE_SOURCE_DIR}/lpass.1.txt
COMMAND a2x -D ./ --no-xmllint -f manpage ${CMAKE_SOURCE_DIR}/lpass.1.txt)
add_custom_command(OUTPUT lpass.1.html DEPENDS ${CMAKE_SOURCE_DIR}/lpass.1.txt
COMMAND asciidoc -b html5 -a data-uri -a icons -a toc2 -o lpass.1.html ${CMAKE_SOURCE_DIR}/lpass.1.txt)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
if(BASH_COMPLETION_FOUND)
pkg_get_variable(BASH_COMPLETION_COMPLETIONSDIR bash-completion completionsdir)
# Fix GH-478
if(NOT "${BASH_COMPLETION_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
string(REGEX REPLACE "^${BASH_COMPLETION_PREFIX}" "${CMAKE_INSTALL_PREFIX}" COMP_DIR ${BASH_COMPLETION_COMPLETIONSDIR})
set(BASH_COMPLETION_COMPLETIONSDIR ${COMP_DIR})
unset(COMP_DIR)
endif()
install(FILES contrib/lpass_bash_completion DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR} RENAME lpass)
endif()
# Test lpass executable with mock server, link against test versions first
file(GLOB LPTEST_SOURCES test/*.c *.c)
add_executable(lpass-test EXCLUDE_FROM_ALL ${PROJECT_HEADERS} ${LPTEST_SOURCES})
set_target_properties(lpass-test PROPERTIES
C_STANDARD 99
COMPILE_FLAGS "${PROJECT_FLAGS} -DTEST_BUILD"
COMPILE_DEFINITIONS ${PROJECT_DEFINITIONS}
)
target_link_libraries(lpass-test ${LIBXML2_LIBRARIES} ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES})
if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
target_link_libraries(lpass-test "-lkvm")
endif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
enable_testing()
add_test(test_login ${CMAKE_SOURCE_DIR}/test/tests test_login)
add_test(test_login_wrong_pw_should_fail ${CMAKE_SOURCE_DIR}/test/tests test_login_wrong_pw_should_fail)
add_test(test_add_account ${CMAKE_SOURCE_DIR}/test/tests test_add_account)
add_test(test_add_note ${CMAKE_SOURCE_DIR}/test/tests test_add_note)
add_test(test_add_note_with_field ${CMAKE_SOURCE_DIR}/test/tests test_add_note_with_field)
add_test(test_add_site_note ${CMAKE_SOURCE_DIR}/test/tests test_add_site_note)
add_test(test_add_ssn_name ${CMAKE_SOURCE_DIR}/test/tests test_add_ssn_name)
add_test(test_add_ssh_key ${CMAKE_SOURCE_DIR}/test/tests test_add_ssh_key)
add_test(test_edit_ssh_key ${CMAKE_SOURCE_DIR}/test/tests test_edit_ssh_key)
add_test(test_edit_username ${CMAKE_SOURCE_DIR}/test/tests test_edit_username)
add_test(test_edit_field ${CMAKE_SOURCE_DIR}/test/tests test_edit_field)
add_test(test_edit_reprompt ${CMAKE_SOURCE_DIR}/test/tests test_edit_reprompt)
add_test(test_duplicate ${CMAKE_SOURCE_DIR}/test/tests test_duplicate)
add_test(test_generate ${CMAKE_SOURCE_DIR}/test/tests test_generate)
add_test(test_show ${CMAKE_SOURCE_DIR}/test/tests test_show)
add_test(test_show_json ${CMAKE_SOURCE_DIR}/test/tests test_show_json)
add_test(test_show_note ${CMAKE_SOURCE_DIR}/test/tests test_show_note)
add_test(test_show_reprompt ${CMAKE_SOURCE_DIR}/test/tests test_show_reprompt)
add_test(test_ls ${CMAKE_SOURCE_DIR}/test/tests test_ls)
add_test(test_export ${CMAKE_SOURCE_DIR}/test/tests test_export)
add_test(test_export_extended ${CMAKE_SOURCE_DIR}/test/tests test_export_extended)
add_custom_target(doc-man DEPENDS lpass.1)
add_custom_target(doc-html DEPENDS lpass.1.html)
# See https://cmake.org/pipermail/cmake/2009-January/026520.html
add_custom_target(install-doc COMMAND ${CMAKE_COMMAND} -DMANDIR=${CMAKE_INSTALL_FULL_MANDIR} -P ${CMAKE_SOURCE_DIR}/cmake_extras/install_doc.cmake DEPENDS doc-man)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -DPROJECT_NAME=${PROJECT_NAME} -DMANDIR=${CMAKE_INSTALL_FULL_MANDIR} -P ${CMAKE_SOURCE_DIR}/cmake_extras/uninstall.cmake)