]> jfr.im git - irc/weechat/weechat-relay.git/blob - CMakeLists.txt
Remove tests on macOS 11
[irc/weechat/weechat-relay.git] / CMakeLists.txt
1 #
2 # Copyright (C) 2019-2024 Sébastien Helleu <flashcode@flashtux.org>
3 #
4 # This file is part of WeeChat Relay.
5 #
6 # WeeChat Relay is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # WeeChat Relay is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with WeeChat Relay. If not, see <https://www.gnu.org/licenses/>.
18 #
19
20 cmake_minimum_required(VERSION 3.0)
21 cmake_policy(VERSION 3.0)
22
23 project(weechat-relay C)
24
25 # CMake options
26 set(CMAKE_VERBOSE_MAKEFILE OFF)
27 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
28 set(CMAKE_SKIP_RPATH ON)
29
30 # compiler options
31 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsigned-char -Wall -Wextra -Werror-implicit-function-declaration")
32 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -Wall -Wextra")
33 if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
34 # extra options specific to gcc/g++
35 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-overflow=2 -Wformat-truncation=2")
36 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-overflow=2 -Wformat-truncation=2")
37 endif()
38
39 # version
40 execute_process(COMMAND ${CMAKE_SOURCE_DIR}/version.sh devel-full OUTPUT_VARIABLE VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
41 execute_process(COMMAND ${CMAKE_SOURCE_DIR}/version.sh devel-major OUTPUT_VARIABLE VERSION_MAJOR OUTPUT_STRIP_TRAILING_WHITESPACE)
42 execute_process(COMMAND ${CMAKE_SOURCE_DIR}/version.sh devel-minor OUTPUT_VARIABLE VERSION_MINOR OUTPUT_STRIP_TRAILING_WHITESPACE)
43 execute_process(COMMAND ${CMAKE_SOURCE_DIR}/version.sh devel-patch OUTPUT_VARIABLE VERSION_PATCH OUTPUT_STRIP_TRAILING_WHITESPACE)
44 execute_process(COMMAND ${CMAKE_SOURCE_DIR}/version.sh devel-number OUTPUT_VARIABLE VERSION_NUMBER OUTPUT_STRIP_TRAILING_WHITESPACE)
45
46 # directories
47 if(NOT DEFINED LIBDIR)
48 set(LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
49 endif()
50 if(NOT DEFINED DATAROOTDIR)
51 set(DATAROOTDIR ${CMAKE_INSTALL_PREFIX}/share)
52 endif()
53 if(NOT DEFINED MANDIR)
54 set(MANDIR ${DATAROOTDIR}/man)
55 endif()
56 if(NOT DEFINED LOCALEDIR)
57 set(LOCALEDIR ${DATAROOTDIR}/locale)
58 endif()
59 if(DEFINED INCLUDEDIR)
60 set(INCLUDEDIR ${INCLUDEDIR}/${PROJECT_NAME})
61 else()
62 set(INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME})
63 endif()
64
65 # build options
66 option(BUILD_CLI "Build the testing CLI program" ON)
67 option(BUILD_DOC "Enable build of documentation" OFF)
68 option(BUILD_MAN "Enable build of man pages" OFF)
69 option(BUILD_TESTS "Build tests" OFF)
70 option(CODE_COVERAGE "Enable code coverage" OFF)
71
72 # definitions
73 add_definitions(-DPACKAGE_NAME="${PROJECT_NAME}")
74
75 set(LINK_LIBS)
76
77 # code coverage
78 add_library(coverage_config INTERFACE)
79 if(CODE_COVERAGE)
80 target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
81 target_link_libraries(coverage_config INTERFACE --coverage)
82 endif()
83
84 # required libs
85 find_package(GnuTLS REQUIRED)
86 include_directories(${GNUTLS_INCLUDE_DIR})
87 list(APPEND LINK_LIBS ${GNUTLS_LIBRARY})
88
89 # build weechat-relay.h
90 configure_file(lib/weechat-relay.h.cmake lib/weechat-relay.h @ONLY)
91
92 # sub-directories
93 add_subdirectory(lib)
94 add_subdirectory(src)
95 add_subdirectory(doc)
96
97 # tests
98 if(BUILD_TESTS)
99 find_package(CppUTest)
100 if(CPPUTEST_FOUND)
101 enable_testing()
102 add_subdirectory(tests)
103 else()
104 message(SEND_ERROR "CppUTest not found")
105 endif()
106 endif()
107
108 # set the git version in "config-git.h"
109 add_custom_target(version_git ALL
110 COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/set_git_version.sh" "${CMAKE_CURRENT_SOURCE_DIR}" "${VERSION}" "config-git.h"
111 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
112
113 # add target "dist"
114 add_custom_target(dist
115 "${CMAKE_CURRENT_SOURCE_DIR}/tools/makedist.sh" "${VERSION}" "HEAD" "${CMAKE_CURRENT_BINARY_DIR}"
116 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
117
118 # pkgconfig file
119 set(prefix "${CMAKE_INSTALL_PREFIX}")
120 set(exec_prefix "\${prefix}")
121 set(libdir "\${exec_prefix}/lib")
122 set(includedir "\${prefix}/include")
123 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/weechat-relay.pc.in ${CMAKE_CURRENT_BINARY_DIR}/weechat-relay.pc @ONLY)
124 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/weechat-relay.pc DESTINATION ${LIBDIR}/pkgconfig)
125
126 # cygport file (used to build Cygwin packages)
127 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/weechat-relay.cygport.in
128 ${CMAKE_CURRENT_BINARY_DIR}/weechat-relay-${VERSION}-1.cygport @ONLY)
129
130 # install some files (only on Cygwin)
131 if(CYGWIN)
132 install(FILES
133 ${CMAKE_CURRENT_SOURCE_DIR}/AUTHORS.md
134 ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md
135 ${CMAKE_CURRENT_SOURCE_DIR}/CONTRIBUTING.md
136 ${CMAKE_CURRENT_SOURCE_DIR}/README.md
137 DESTINATION ${DATAROOTDIR}/doc/${PROJECT_NAME})
138 endif()