|
| 1 | +# TODO: |
| 2 | +# - check which MSVC are compatible |
| 3 | +# - cpack |
| 4 | +# - ctest |
| 5 | + |
| 6 | +cmake_minimum_required(VERSION 3.1.0) |
| 7 | + |
| 8 | +project(direwolf) |
| 9 | + |
| 10 | +# configure version |
| 11 | +set(direwolf_VERSION_MAJOR "1") |
| 12 | +set(direwolf_VERSION_MINOR "6") |
| 13 | +set(direwolf_VERSION_PATCH "0") |
| 14 | +set(direwolf_VERSION_SUFFIX "") |
| 15 | + |
| 16 | +# options |
| 17 | +option(FORCE_SSE "Compile with SSE instruction only" OFF) |
| 18 | +option(FORCE_SSSE3 "Compile with SSSE3 instruction only" OFF) |
| 19 | +option(FORCE_SSE41 "Compile with SSE4.1 instruction only" OFF) |
| 20 | + |
| 21 | +# where cmake find custom modules |
| 22 | +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) |
| 23 | + |
| 24 | +# fix c standard used on the project |
| 25 | +set(CMAKE_C_STANDARD 99) |
| 26 | + |
| 27 | +# Set additional project information |
| 28 | +set(COMPANY "wb2osz") |
| 29 | +add_definitions("-DCOMPANY=\"${COMPANY}\"") |
| 30 | +set(APPLICATION_NAME "Dire Wolf") |
| 31 | +add_definitions("-DAPPLICATION_NAME=\"${APPLICATION_NAME}\"") |
| 32 | +set(APPLICATION_MAINTAINER="John Langner, WB2OSZ") |
| 33 | +set(COPYRIGHT "Copyright (c) 2019 John Langner, WB2OSZ. All rights reserved.") |
| 34 | +add_definitions("-DCOPYRIGHT=\"${COPYRIGHT}\"") |
| 35 | +set(IDENTIFIER "com.${COMPANY}.${APPLICATION_NAME}") |
| 36 | +add_definitions("-DIDENTIFIER=\"${IDENTIFIER}\"") |
| 37 | +set(APPLICATION_DESKTOP_EXEC "xterm -e ${CMAKE_PROJECT_NAME}") |
| 38 | + |
| 39 | +find_package(Git) |
| 40 | +if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git/") |
| 41 | + # we can also use `git describe --tags` |
| 42 | + execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD |
| 43 | + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 44 | + RESULT_VARIABLE res |
| 45 | + OUTPUT_VARIABLE out |
| 46 | + ERROR_QUIET |
| 47 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 48 | + if(NOT res) |
| 49 | + string(REGEX REPLACE "^v([0-9]+)\.([0-9]+)\.([0-9]+)-" "" git_commit ${out}) |
| 50 | + set(direwolf_VERSION_SUFFIX "-${git_commit}") |
| 51 | + set(direwolf_VERSION_COMMIT "${git_commit}") |
| 52 | + endif() |
| 53 | +endif() |
| 54 | + |
| 55 | +# set variables |
| 56 | +set(direwolf_VERSION "${direwolf_VERSION_MAJOR}.${direwolf_VERSION_MINOR}.${direwolf_VERSION_PATCH}${direwolf_VERSION_SUFFIX}") |
| 57 | +message(STATUS "${APPLICATION_NAME} Version: ${direwolf_VERSION}") |
| 58 | +add_definitions("-DIREWOLF_VERSION=\"${direwolf_VERSION}\"") |
| 59 | +add_definitions("-DMAJOR_VERSION=${direwolf_VERSION_MAJOR}") |
| 60 | +add_definitions("-DMINOR_VERSION=${direwolf_VERSION_MINOR}") |
| 61 | +if(direwolf_VERSION_COMMIT) |
| 62 | + add_definitions("-DEXTRA_VERSION=${direwolf_VERSION_COMMIT}") |
| 63 | +endif() |
| 64 | + |
| 65 | +set(CUSTOM_EXTERNAL_DIR "${CMAKE_SOURCE_DIR}/external") |
| 66 | +set(CUSTOM_MISC_DIR "${CUSTOM_EXTERNAL_DIR}/misc") |
| 67 | +set(CUSTOM_REGEX_DIR "${CUSTOM_EXTERNAL_DIR}/regex") |
| 68 | +set(CUSTOM_GEOTRANZ_DIR "${CUSTOM_EXTERNAL_DIR}/geotranz") |
| 69 | +set(CUSTOM_DATA_DIR "${CMAKE_SOURCE_DIR}/data") |
| 70 | +set(CUSTOM_SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/scripts") |
| 71 | +set(CUSTOM_TELEMETRY_DIR "${CUSTOM_SCRIPTS_DIR}/telemetry-toolkit") |
| 72 | +set(CUSTOM_CONF_DIR "${CMAKE_SOURCE_DIR}/conf") |
| 73 | +set(CUSTOM_DOC_DIR "${CMAKE_SOURCE_DIR}/doc") |
| 74 | +set(CUSTOM_MAN_DIR "${CMAKE_SOURCE_DIR}/man") |
| 75 | + |
| 76 | +# if we don't set build_type |
| 77 | +if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "") |
| 78 | + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) |
| 79 | +endif() |
| 80 | +message(STATUS "Build type set to: ${CMAKE_BUILD_TYPE}") |
| 81 | + |
| 82 | +# set compiler |
| 83 | +include(FindCompiler) |
| 84 | + |
| 85 | +# find cpu flags (and set compiler) |
| 86 | +include(FindCPUflags) |
| 87 | + |
| 88 | +# auto include current directory |
| 89 | +set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 90 | + |
| 91 | +# set OS dependant variables |
| 92 | +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") |
| 93 | + set(LINUX TRUE) |
| 94 | + |
| 95 | + configure_file("${CMAKE_SOURCE_DIR}/cmake/cpack/${CMAKE_PROJECT_NAME}.desktop.in" |
| 96 | + "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop" @ONLY) |
| 97 | + |
| 98 | +elseif(APPLE) |
| 99 | + if("${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "") |
| 100 | + message(STATUS "Build for macOS target: local version") |
| 101 | + else() |
| 102 | + message(STATUS "Build for macOS target: ${CMAKE_OSX_DEPLOYMENT_TARGET}") |
| 103 | + endif() |
| 104 | + |
| 105 | + # prepend path to find_*() |
| 106 | + set(CMAKE_FIND_ROOT_PATH "/opt/local") |
| 107 | + |
| 108 | + set(CMAKE_MACOSX_RPATH ON) |
| 109 | + message(STATUS "RPATH support: ${CMAKE_MACOSX_RPATH}") |
| 110 | + |
| 111 | +elseif (WIN32) |
| 112 | + if(NOT VS2015 AND NOT VS2017) |
| 113 | + message(FATAL_ERROR "You must use Microsoft Visual Studio 2015 or 2017 as compiler") |
| 114 | + endif() |
| 115 | + |
| 116 | + # compile with full multicore |
| 117 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") |
| 118 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") |
| 119 | +endif() |
| 120 | + |
| 121 | +if (C_CLANG OR C_GCC) |
| 122 | + # _BSD_SOURCE is deprecated we need to use _DEFAULT_SOURCE |
| 123 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wvla -ffast-math -ftree-vectorize -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE ${EXTRA_FLAGS}") |
| 124 | + # for math.h |
| 125 | + link_libraries("-lm") |
| 126 | +elseif (C_MSVC) |
| 127 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W3 -MP ${EXTRA_FLAGS}") |
| 128 | +endif() |
| 129 | + |
| 130 | +if (C_CLANG) |
| 131 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ferror-limit=1") |
| 132 | +elseif (C_GCC) |
| 133 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmax-errors=1") |
| 134 | +endif() |
| 135 | + |
| 136 | +# requirements |
| 137 | +set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 138 | +find_package(Threads REQUIRED) |
| 139 | + |
| 140 | +find_package(GPSD) |
| 141 | +if(GPSD_FOUND) |
| 142 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_GPSD") |
| 143 | +else() |
| 144 | + set(GPSD_INCLUDE_DIRS "") |
| 145 | + set(GPSD_LIBRARIES "") |
| 146 | +endif() |
| 147 | + |
| 148 | +find_package(hamlib) |
| 149 | +if(HAMLIB_FOUND) |
| 150 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_HAMLIB") |
| 151 | +else() |
| 152 | + set(HAMLIB_INCLUDE_DIRS "") |
| 153 | + set(HAMLIB_LIBRARIES "") |
| 154 | +endif() |
| 155 | + |
| 156 | +if(LINUX) |
| 157 | + find_package(ALSA REQUIRED) |
| 158 | + if(ALSA_FOUND) |
| 159 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_ALSA") |
| 160 | + endif() |
| 161 | + |
| 162 | + find_package(udev) |
| 163 | + if(UDEV_FOUND) |
| 164 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CM108") |
| 165 | + endif() |
| 166 | + |
| 167 | +elseif (NOT WIN32) |
| 168 | + find_package(portaudio REQUIRED) |
| 169 | + if(PORTAUDIO_FOUND) |
| 170 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_PORTAUDIO") |
| 171 | + endif() |
| 172 | + |
| 173 | +endif() |
| 174 | + |
| 175 | +# manage and fetch new data |
| 176 | +add_subdirectory(data) |
| 177 | + |
| 178 | +# external libraries |
| 179 | +add_subdirectory(${CUSTOM_GEOTRANZ_DIR}) |
| 180 | +add_subdirectory(${CUSTOM_REGEX_DIR}) |
| 181 | +add_subdirectory(${CUSTOM_MISC_DIR}) |
| 182 | + |
| 183 | +# direwolf source code and utilities |
| 184 | +add_subdirectory(src) |
| 185 | + |
| 186 | +# manage scripts |
| 187 | +add_subdirectory(scripts) |
| 188 | + |
| 189 | +# manage config |
| 190 | +add_subdirectory(conf) |
| 191 | + |
| 192 | +# install basic docs |
| 193 | +install(FILES ${CMAKE_SOURCE_DIR}/CHANGES.md DESTINATION share/doc/${CMAKE_PROJECT_NAME}) |
| 194 | +install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION share/doc/${CMAKE_PROJECT_NAME}) |
| 195 | +install(FILES ${CMAKE_SOURCE_DIR}/external/LICENSE DESTINATION share/doc/${CMAKE_PROJECT_NAME}/external) |
| 196 | +add_subdirectory(doc) |
| 197 | +add_subdirectory(man) |
| 198 | + |
| 199 | +# install desktop link |
| 200 | +if (LINUX) |
| 201 | + install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.desktop DESTINATION share/applications) |
| 202 | + install(FILES ${CMAKE_SOURCE_DIR}/cmake/cpack/${CMAKE_PROJECT_NAME}_icon.png DESTINATION share/pixmaps) |
| 203 | +endif() |
| 204 | + |
| 205 | +############ uninstall target ################ |
| 206 | +configure_file( |
| 207 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/include/uninstall.cmake.in" |
| 208 | + "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake" |
| 209 | + IMMEDIATE @ONLY) |
| 210 | + |
| 211 | +add_custom_target(uninstall |
| 212 | + COMMAND ${CMAKE_COMMAND} -P |
| 213 | + ${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake) |
| 214 | + |
| 215 | +############ packaging ################ |
| 216 | +add_subdirectory(cmake/cpack) |
0 commit comments