|
| 1 | +cmake_minimum_required(VERSION 3.1.0) |
| 2 | + |
| 3 | +project(direwolf) |
| 4 | + |
| 5 | +# configure version |
| 6 | +set(direwolf_VERSION_MAJOR "1") |
| 7 | +set(direwolf_VERSION_MINOR "6") |
| 8 | +set(direwolf_VERSION_PATCH "0") |
| 9 | +set(direwolf_VERSION_SUFFIX "") |
| 10 | + |
| 11 | +# options |
| 12 | +option(FORCE_SSE "Compile with SSE instruction only" OFF) |
| 13 | +option(FORCE_SSSE3 "Compile with SSSE3 instruction only" OFF) |
| 14 | +option(FORCE_SSE41 "Compile with SSE4.1 instruction only" OFF) |
| 15 | +option(OPTIONAL_TEST "Compile optional test (might be broken)" OFF) |
| 16 | +# UNITTEST option must be after CMAKE_BUILT_TYPE |
| 17 | + |
| 18 | +# where cmake find custom modules |
| 19 | +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) |
| 20 | + |
| 21 | +# fix c standard used on the project |
| 22 | +set(CMAKE_C_STANDARD 99) |
| 23 | + |
| 24 | +# Set additional project information |
| 25 | +set(COMPANY "wb2osz") |
| 26 | +add_definitions("-DCOMPANY=\"${COMPANY}\"") |
| 27 | +set(APPLICATION_NAME "Dire Wolf") |
| 28 | +add_definitions("-DAPPLICATION_NAME=\"${APPLICATION_NAME}\"") |
| 29 | +set(APPLICATION_MAINTAINER="John Langner, WB2OSZ") |
| 30 | +set(COPYRIGHT "Copyright (c) 2019 John Langner, WB2OSZ. All rights reserved.") |
| 31 | +add_definitions("-DCOPYRIGHT=\"${COPYRIGHT}\"") |
| 32 | +set(IDENTIFIER "com.${COMPANY}.${APPLICATION_NAME}") |
| 33 | +add_definitions("-DIDENTIFIER=\"${IDENTIFIER}\"") |
| 34 | +# raspberry as only lxterminal not xterm |
| 35 | +if(NOT (WIN32 OR CYGWIN)) |
| 36 | + find_program(BINARY_TERMINAL_BIN lxterminal) |
| 37 | + if(BINARY_TERMINAL_BIN) |
| 38 | + set(APPLICATION_DESKTOP_EXEC "${BINARY_TERMINAL_BIN} -e ${CMAKE_PROJECT_NAME}") |
| 39 | + else() |
| 40 | + set(APPLICATION_DESKTOP_EXEC "xterm -e ${CMAKE_PROJECT_NAME}") |
| 41 | + endif() |
| 42 | +endif() |
| 43 | + |
| 44 | +find_package(Git) |
| 45 | +if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git/") |
| 46 | + # we can also use `git describe --tags` |
| 47 | + execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD |
| 48 | + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 49 | + RESULT_VARIABLE res |
| 50 | + OUTPUT_VARIABLE out |
| 51 | + ERROR_QUIET |
| 52 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 53 | + if(NOT res) |
| 54 | + string(REGEX REPLACE "^v([0-9]+)\.([0-9]+)\.([0-9]+)-" "" git_commit ${out}) |
| 55 | + set(direwolf_VERSION_SUFFIX "-${git_commit}") |
| 56 | + set(direwolf_VERSION_COMMIT "${git_commit}") |
| 57 | + endif() |
| 58 | +endif() |
| 59 | + |
| 60 | +# set variables |
| 61 | +set(direwolf_VERSION "${direwolf_VERSION_MAJOR}.${direwolf_VERSION_MINOR}.${direwolf_VERSION_PATCH}${direwolf_VERSION_SUFFIX}") |
| 62 | +message(STATUS "${APPLICATION_NAME} Version: ${direwolf_VERSION}") |
| 63 | +add_definitions("-DIREWOLF_VERSION=\"${direwolf_VERSION}\"") |
| 64 | +add_definitions("-DMAJOR_VERSION=${direwolf_VERSION_MAJOR}") |
| 65 | +add_definitions("-DMINOR_VERSION=${direwolf_VERSION_MINOR}") |
| 66 | +if(direwolf_VERSION_COMMIT) |
| 67 | + add_definitions("-DEXTRA_VERSION=${direwolf_VERSION_COMMIT}") |
| 68 | +endif() |
| 69 | + |
| 70 | +set(CUSTOM_SRC_DIR "${CMAKE_SOURCE_DIR}/src") |
| 71 | +set(CUSTOM_EXTERNAL_DIR "${CMAKE_SOURCE_DIR}/external") |
| 72 | +set(CUSTOM_MISC_DIR "${CUSTOM_EXTERNAL_DIR}/misc") |
| 73 | +set(CUSTOM_REGEX_DIR "${CUSTOM_EXTERNAL_DIR}/regex") |
| 74 | +set(CUSTOM_GEOTRANZ_DIR "${CUSTOM_EXTERNAL_DIR}/geotranz") |
| 75 | +set(CUSTOM_DATA_DIR "${CMAKE_SOURCE_DIR}/data") |
| 76 | +set(CUSTOM_SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/scripts") |
| 77 | +set(CUSTOM_TELEMETRY_DIR "${CUSTOM_SCRIPTS_DIR}/telemetry-toolkit") |
| 78 | +set(CUSTOM_CONF_DIR "${CMAKE_SOURCE_DIR}/conf") |
| 79 | +set(CUSTOM_DOC_DIR "${CMAKE_SOURCE_DIR}/doc") |
| 80 | +set(CUSTOM_MAN_DIR "${CMAKE_SOURCE_DIR}/man") |
| 81 | +set(CUSTOM_TEST_DIR "${CMAKE_SOURCE_DIR}/test") |
| 82 | +set(CUSTOM_TEST_SCRIPTS_DIR "${CUSTOM_TEST_DIR}/scripts") |
| 83 | +set(CUSTOM_SHELL_SHABANG "#!/bin/sh -e") |
| 84 | + |
| 85 | +# cpack variables |
| 86 | +set(CPACK_GENERATOR "ZIP") |
| 87 | +set(CPACK_STRIP_FILES true) |
| 88 | +set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") |
| 89 | +set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${direwolf_VERSION}_${CMAKE_SYSTEM_PROCESSOR}") |
| 90 | +set(CPACK_PACKAGE_CONTACT "https://github.com/wb2osz/direwolf") |
| 91 | +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Dire Wolf is a software soundcard AX.25 packet modem/TNC and APRS encoder/decoder") |
| 92 | +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") |
| 93 | +set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") |
| 94 | +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE") |
| 95 | +set(CPACK_SOURCE_IGNORE_FILES "${PROJECT_BINARY_DIR};/.git/;.gitignore;menu.yml;.travis.yml;.appveyor.yml;default.nix;.envrc;TODOs.org;/.scripts/") |
| 96 | + |
| 97 | +# if we don't set build_type |
| 98 | +if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "") |
| 99 | + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) |
| 100 | +endif() |
| 101 | +message(STATUS "Build type set to: ${CMAKE_BUILD_TYPE}") |
| 102 | +message("CMake system: ${CMAKE_SYSTEM_NAME}") |
| 103 | + |
| 104 | +# Unittest should be on for dev builds and off for releases. |
| 105 | +if(CMAKE_BUILD_TYPE MATCHES "Release") |
| 106 | + option(UNITTEST "Build unittest binaries." OFF) |
| 107 | +else() |
| 108 | + option(UNITTEST "Build unittest binaries." ON) |
| 109 | +endif() |
| 110 | + |
| 111 | +# set compiler |
| 112 | +include(FindCompiler) |
| 113 | + |
| 114 | +# find cpu flags (and set compiler) |
| 115 | +include(FindCPUflags) |
| 116 | + |
| 117 | +# auto include current directory |
| 118 | +set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 119 | + |
| 120 | +# set OS dependant variables |
| 121 | +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") |
| 122 | + set(LINUX TRUE) |
| 123 | + |
| 124 | + configure_file("${CMAKE_SOURCE_DIR}/cmake/cpack/${CMAKE_PROJECT_NAME}.desktop.in" |
| 125 | + "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop" @ONLY) |
| 126 | + |
| 127 | +elseif(APPLE) |
| 128 | + if("${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "") |
| 129 | + message(STATUS "Build for macOS target: local version") |
| 130 | + else() |
| 131 | + message(STATUS "Build for macOS target: ${CMAKE_OSX_DEPLOYMENT_TARGET}") |
| 132 | + endif() |
| 133 | + |
| 134 | + # prepend path to find_*() |
| 135 | + set(CMAKE_FIND_ROOT_PATH "/opt/local") |
| 136 | + |
| 137 | + set(CMAKE_MACOSX_RPATH ON) |
| 138 | + message(STATUS "RPATH support: ${CMAKE_MACOSX_RPATH}") |
| 139 | + |
| 140 | +elseif (WIN32) |
| 141 | + if(NOT VS2015 AND NOT VS2017) |
| 142 | + message(FATAL_ERROR "You must use Microsoft Visual Studio 2015 or 2017 as compiler") |
| 143 | + endif() |
| 144 | + |
| 145 | + # compile with full multicore |
| 146 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") |
| 147 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") |
| 148 | + |
| 149 | + set(CUSTOM_SHELL_BIN "") |
| 150 | +endif() |
| 151 | + |
| 152 | +if (C_CLANG OR C_GCC) |
| 153 | + # _BSD_SOURCE is deprecated we need to use _DEFAULT_SOURCE |
| 154 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wvla -ffast-math -ftree-vectorize -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE ${EXTRA_FLAGS}") |
| 155 | + # for math.h |
| 156 | + link_libraries("-lm") |
| 157 | +elseif (C_MSVC) |
| 158 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W3 -MP ${EXTRA_FLAGS}") |
| 159 | +endif() |
| 160 | + |
| 161 | +if (C_CLANG) |
| 162 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ferror-limit=1") |
| 163 | +elseif (C_GCC) |
| 164 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmax-errors=1") |
| 165 | +endif() |
| 166 | + |
| 167 | +# set installation directories |
| 168 | +if (WIN32 OR CYGWIN) |
| 169 | + set(INSTALL_BIN_DIR ".") |
| 170 | + set(INSTALL_DOC_DIR "doc") |
| 171 | + set(INSTALL_CONF_DIR ".") |
| 172 | + set(INSTALL_SCRIPTS_DIR "scripts") |
| 173 | + set(INSTALL_MAN_DIR "man") |
| 174 | + set(INSTALL_DATA_DIR "data") |
| 175 | +else() |
| 176 | + set(INSTALL_BIN_DIR "bin") |
| 177 | + set(INSTALL_DOC_DIR "share/doc/${CMAKE_PROJECT_NAME}") |
| 178 | + set(INSTALL_CONF_DIR "${INSTALL_DOC_DIR}/conf") |
| 179 | + set(INSTALL_SCRIPTS_DIR "${INSTALL_DOC_DIR}/scripts") |
| 180 | + set(INSTALL_MAN_DIR "share/man/man1") |
| 181 | + set(INSTALL_DATA_DIR "share/${PROJECT_NAME}") |
| 182 | +endif(WIN32 OR CYGWIN) |
| 183 | + |
| 184 | +# requirements |
| 185 | +set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 186 | +find_package(Threads REQUIRED) |
| 187 | + |
| 188 | +find_package(GPSD) |
| 189 | +if(GPSD_FOUND) |
| 190 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_GPSD") |
| 191 | +else() |
| 192 | + set(GPSD_INCLUDE_DIRS "") |
| 193 | + set(GPSD_LIBRARIES "") |
| 194 | +endif() |
| 195 | + |
| 196 | +find_package(hamlib) |
| 197 | +if(HAMLIB_FOUND) |
| 198 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_HAMLIB") |
| 199 | +else() |
| 200 | + set(HAMLIB_INCLUDE_DIRS "") |
| 201 | + set(HAMLIB_LIBRARIES "") |
| 202 | +endif() |
| 203 | + |
| 204 | +if(LINUX) |
| 205 | + find_package(ALSA REQUIRED) |
| 206 | + if(ALSA_FOUND) |
| 207 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_ALSA") |
| 208 | + endif() |
| 209 | + |
| 210 | + find_package(udev) |
| 211 | + if(UDEV_FOUND) |
| 212 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CM108") |
| 213 | + endif() |
| 214 | + |
| 215 | +elseif (NOT WIN32 AND NOT CYGWIN) |
| 216 | + find_package(Portaudio REQUIRED) |
| 217 | + if(PORTAUDIO_FOUND) |
| 218 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_PORTAUDIO") |
| 219 | + endif() |
| 220 | + |
| 221 | +else() |
| 222 | + set(ALSA_INCLUDE_DIRS "") |
| 223 | + set(ALSA_LIBRARIES "") |
| 224 | + set(UDEV_INCLUDE_DIRS "") |
| 225 | + set(UDEV_LIBRARIES "") |
| 226 | + set(PORTAUDIO_INCLUDE_DIRS "") |
| 227 | + set(PORTAUDIO_LIBRARIES "") |
| 228 | +endif() |
| 229 | + |
| 230 | +# manage and fetch new data |
| 231 | +add_subdirectory(data) |
| 232 | + |
| 233 | +# external libraries |
| 234 | +add_subdirectory(${CUSTOM_GEOTRANZ_DIR}) |
| 235 | +add_subdirectory(${CUSTOM_REGEX_DIR}) |
| 236 | +add_subdirectory(${CUSTOM_MISC_DIR}) |
| 237 | + |
| 238 | +# direwolf source code and utilities |
| 239 | +add_subdirectory(src) |
| 240 | + |
| 241 | +# ctest |
| 242 | +if(UNITTEST) |
| 243 | + message(STATUS "Build unit test binaries") |
| 244 | + include(CTest) |
| 245 | + enable_testing() |
| 246 | + add_subdirectory(test) |
| 247 | +endif(UNITTEST) |
| 248 | + |
| 249 | +# manage scripts |
| 250 | +add_subdirectory(scripts) |
| 251 | + |
| 252 | +# manage config |
| 253 | +add_subdirectory(conf) |
| 254 | + |
| 255 | +# install basic docs |
| 256 | +install(FILES ${CMAKE_SOURCE_DIR}/CHANGES.md DESTINATION ${INSTALL_DOC_DIR}) |
| 257 | +install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${INSTALL_DOC_DIR}) |
| 258 | +install(FILES ${CMAKE_SOURCE_DIR}/external/LICENSE DESTINATION ${INSTALL_DOC_DIR}/external) |
| 259 | +add_subdirectory(doc) |
| 260 | +add_subdirectory(man) |
| 261 | + |
| 262 | +# install desktop link |
| 263 | +if (LINUX) |
| 264 | + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop DESTINATION share/applications) |
| 265 | + install(FILES ${CMAKE_SOURCE_DIR}/cmake/cpack/${CMAKE_PROJECT_NAME}_icon.png DESTINATION share/pixmaps) |
| 266 | +endif() |
| 267 | + |
| 268 | +############ uninstall target ################ |
| 269 | +configure_file( |
| 270 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/include/uninstall.cmake.in" |
| 271 | + "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake" |
| 272 | + IMMEDIATE @ONLY) |
| 273 | + |
| 274 | +add_custom_target(uninstall |
| 275 | + COMMAND ${CMAKE_COMMAND} -P |
| 276 | + ${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake) |
| 277 | + |
| 278 | +############ packaging ################ |
| 279 | +add_subdirectory(cmake/cpack) |
0 commit comments