-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
150 lines (129 loc) · 4.9 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
# Copyright (c) 2020 Timothy Brackett
# Licensed under the MIT license
cmake_minimum_required( VERSION 3.10 )
project( ncpty
VERSION "0.1.0"
DESCRIPTION "An NCurses pseudoterminal library"
HOMEPAGE_URL "https://gitlab.com/bracketttc/ncpty"
LANGUAGES C
)
set( CMAKE_C_STANDARD 11 )
set( CMAKE_C_STANDARD_REQUIRED ON )
set( CMAKE_C_EXTENSIONS OFF )
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
message( STATUS "Defaulting CMAKE_BUILD_TYPE to Release" )
set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release MinSizeRel RelWithDebInfo ..." FORCE )
set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
endif()
option( DOC_ONLY_BUILD "Only build documentation (for readthedocs)" OFF )
if( NOT DOC_ONLY_BUILD )
# Get dependencies
set( CURSES_NEED_NCURSES TRUE )
mark_as_advanced( CURSES_NEED_NCURSES )
find_package( Curses REQUIRED )
find_package( PkgConfig REQUIRED )
pkg_check_modules( panel REQUIRED IMPORTED_TARGET panel )
pkg_check_modules( vterm REQUIRED IMPORTED_TARGET vterm )
mark_as_advanced( pkgcfg_lib_panel_panel pkgcfg_lib_vterm_vterm )
endif()
set( CMAKE_POSITION_INDEPENDENT_CODE ON )
option( USE_INTERNAL_NCURSES_BUILD "" OFF )
if( USE_INTERNAL_NCURSES_BUILD )
include( ExternalProject )
ExternalProject_Add( ncurses
URL https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.2.tar.gz
URL_HASH SHA256=30306e0c76e0f9f1f0de987cf1c82a5c21e1ce6568b9227f7da5b71cbea86c9d
SOURCE_DIR ${CMAKE_SOURCE_DIR}/deps/ncurses
INSTALL_DIR ${CMAKE_BINARY_DIR}/ncurses
CONFIGURE_COMMAND ${CMAKE_SOURCE_DIR}/deps/ncurses/configure --prefix=<INSTALL_DIR> --disable-leaks --with-shared --disable-pc-files --disable-rpath --enable-echo --disable-stripping --enable-const --without-ada --without-tests --without-progs --enable-symlinks --disable-termcap --with-default-terminfo-dir=/etc/terminfo --with-terminfo-dirs=/etc/terminfo:/lib/terminfo:/usr/share/terminfo --with-ticlib=tic --with-termlib-tinfo --with-versioned-syms --disable-wattr-macros --disable-relink --enable-overwrite --with-xterm-kbs=del
)
set( CURSES_CURSES_LIBRARY ${CMAKE_BINARY_DIR}/ncurses/lib/libcurses.so CACHE PATH "" FORCE )
set( CURSES_FORM_LIBRARY ${CMAKE_BINARY_DIR}/ncurses/lib/libform.so CACHE PATH "" FORCE )
set( CURSES_INCLUDE_PATH ${CMAKE_BINARY_DIR}/ncurses/include CACHE PATH "" FORCE )
set( CURSES_NCURSES_LIBRARY ${CMAKE_BINARY_DIR}/ncurses/lib/libncurses.so CACHE PATH "" FORCE )
set( pkgcfg_lib_panel_panel ${CMAKE_BINARY_DIR}/ncurses/lib/libpanel.so CACHE PATH "" FORCE )
endif()
# C flags
add_compile_options(
#"-ansi"
"-Wall"
"-Wextra"
"-pedantic"
"-Werror=implicit-function-declaration"
)
# Security-enhancing flags
add_compile_options(
"--stack-protector-strong"
"-fcf-protection=full"
)
add_link_options(
-zrelro
-znow
)
add_compile_definitions( "_FORTIFY_SOURCE=2" )
string( APPEND CMAKE_EXE_LINKER_FLAGS " -pie" )
# Analysis
find_program( CPPCHECK "cppcheck" )
if( CPPCHECK )
set( CMAKE_C_CPPCHECK ${CPPCHECK} --std=c11 --enable=warning,performance,portability --inline-suppr )
mark_as_advanced( CPPCHECK )
else()
unset( CPPCHECK )
endif()
# options
option( TEST_COVERAGE "Build with gcov instrumentation to evaluate test coverage" OFF )
include( CTest )
enable_testing()
if( TEST_COVERAGE )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs" )
endif()
install( DIRECTORY include/
DESTINATION include
COMPONENT devel
)
if( NOT DOC_ONLY_BUILD )
add_subdirectory( src/bin )
add_subdirectory( src/lib )
add_subdirectory( src/test )
endif()
configure_file( ncpty.pc.in
${CMAKE_BINARY_DIR}/ncpty.pc
@ONLY
)
install( FILES ${CMAKE_BINARY_DIR}/ncpty.pc
DESTINATION share/pkgconfig
COMPONENT devel
)
include( CMakePackageConfigHelpers )
configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/ncptyConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/ncptyConfig.cmake"
INSTALL_DESTINATION lib/cmake/ncpty
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/ncptyConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
install( FILES
${CMAKE_CURRENT_BINARY_DIR}/ncptyConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/ncptyConfigVersion.cmake
DESTINATION lib/cmake/ncpty
)
option( BUILD_DOCUMENTATION "Generate Doxygen documentation" ON )
if( BUILD_DOCUMENTATION)
find_package( Doxygen
REQUIRED dot
)
set( DOXYGEN_GENERATE_HTML YES )
set( DOXYGEN_GENERATE_XML YES )
set( DOXYGEN_GENERATE_MAN YES )
mark_as_advanced( DOXYGEN_GENERATE_MAN )
doxygen_add_docs( doc
include
src
)
endif()
set( CPACK_GENERATOR "TGZ" )
set( CPACK_SOURCE_GENERATOR "TGZ" )
set( CPACK_SOURCE_IGNORE_FILES .git/;build/ )
include( CPack )