Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | # Disable in-source builds to prevent source tree corruption. |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 2 | if(" ${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL " ${CMAKE_CURRENT_BINARY_DIR}") |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 3 | message( |
| 4 | FATAL_ERROR |
| 5 | " |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 6 | FATAL: In-source builds are not allowed. |
| 7 | You should create a separate directory for build files. |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 8 | " |
| 9 | ) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 10 | endif() |
| 11 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 12 | if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 13 | set(CMAKE_SYSTEM_VERSION 10.0.18362.0 CACHE STRING INTERNAL FORCE) |
| 14 | set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 10.0.18362.0 CACHE STRING INTERNAL FORCE) |
| 15 | endif() |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 16 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 17 | cmake_minimum_required(VERSION 3.11) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 18 | project(allwpilib) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 19 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") |
| 20 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 21 | # Make timestamps of extracted files from FetchContent the time of extraction |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 22 | if(POLICY CMP0135) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 23 | cmake_policy(SET CMP0135 NEW) |
| 24 | endif() |
| 25 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 26 | message(STATUS "Platform version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") |
| 27 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 28 | set(WPILIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 29 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 30 | include(CPack) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 31 | |
| 32 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
| 33 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 34 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 35 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib) |
| 36 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib) |
| 37 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/bin) |
| 38 | set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${WPILIB_BINARY_DIR}/jar) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 39 | |
| 40 | # use, i.e. don't skip the full RPATH for the build tree |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 41 | set(CMAKE_SKIP_BUILD_RPATH FALSE) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 42 | |
| 43 | # when building, don't use the install RPATH already |
| 44 | # (but later on when installing) |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 45 | set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 46 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 47 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 48 | |
| 49 | # add the automatically determined parts of the RPATH |
| 50 | # which point to directories outside the build tree to the install RPATH |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 51 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 52 | |
| 53 | # the RPATH to be used when installing, but only if it's not a system directory |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 54 | list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) |
| 55 | if("${isSystemDir}" STREQUAL "-1") |
| 56 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") |
| 57 | endif() |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 58 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 59 | # Options for building certain parts of the repo. Everything is built by default. |
| 60 | option(BUILD_SHARED_LIBS "Build with shared libs (needed for JNI)" ON) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 61 | option(WITH_JAVA "Include Java and JNI in the build" ON) |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 62 | option(WITH_JAVA_SOURCE "Build Java source jars" ${WITH_JAVA}) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 63 | option(WITH_CSCORE "Build cscore (needs OpenCV)" ON) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 64 | option(WITH_NTCORE "Build ntcore" ON) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 65 | option(WITH_WPIMATH "Build wpimath" ON) |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 66 | option(WITH_WPIUNITS "Build wpiunits" ON) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 67 | option(WITH_WPILIB "Build hal, wpilibc/j, and myRobot (needs OpenCV)" ON) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 68 | option(WITH_EXAMPLES "Build examples" OFF) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 69 | option(WITH_TESTS "Build unit tests (requires internet connection)" ON) |
| 70 | option(WITH_GUI "Build GUI items" ON) |
| 71 | option(WITH_SIMULATION_MODULES "Build simulation modules" ON) |
| 72 | |
| 73 | # Options for external HAL. |
| 74 | option(WITH_EXTERNAL_HAL "Use a separately built HAL" OFF) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 75 | set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File") |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 76 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 77 | # Options for using a package manager (e.g., vcpkg) for certain dependencies. |
| 78 | option(USE_SYSTEM_FMTLIB "Use system fmtlib" OFF) |
| 79 | option(USE_SYSTEM_LIBUV "Use system libuv" OFF) |
| 80 | option(USE_SYSTEM_EIGEN "Use system eigen" OFF) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 81 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 82 | # Options for location of OpenCV Java. |
| 83 | set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file") |
| 84 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 85 | # Options for compilation flags. |
| 86 | option(NO_WERROR "Disable -Werror flag during compilation" OFF) |
| 87 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 88 | # Set default build type to release with debug info (i.e. release mode optimizations |
| 89 | # are performed, but debug info still exists). |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 90 | if(NOT CMAKE_BUILD_TYPE) |
| 91 | set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 92 | endif() |
| 93 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 94 | if(WITH_JAVA AND NOT BUILD_SHARED_LIBS) |
| 95 | message( |
| 96 | FATAL_ERROR |
| 97 | " |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 98 | FATAL: Cannot build static libs with Java enabled. |
| 99 | Static libs requires both BUILD_SHARED_LIBS=OFF and |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 100 | WITH_JAVA=OFF |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 101 | " |
| 102 | ) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 103 | endif() |
| 104 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 105 | if(WITH_SIMULATION_MODULES AND NOT BUILD_SHARED_LIBS) |
| 106 | message( |
| 107 | FATAL_ERROR |
| 108 | " |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 109 | FATAL: Cannot build static libs with simulation modules enabled. |
| 110 | Static libs requires both BUILD_SHARED_LIBS=OFF and |
| 111 | WITH_SIMULATION_MODULES=OFF |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 112 | " |
| 113 | ) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 114 | endif() |
| 115 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 116 | if(NOT WITH_JAVA OR NOT WITH_CSCORE) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 117 | if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "") |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 118 | message( |
| 119 | WARNING |
| 120 | " |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 121 | WARNING: OpenCV Java dir set but java is not enabled! |
| 122 | It will be ignored. |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 123 | " |
| 124 | ) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 125 | endif() |
| 126 | endif() |
| 127 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 128 | if(NOT WITH_WPILIB AND WITH_SIMULATION_MODULES) |
| 129 | message( |
| 130 | FATAL_ERROR |
| 131 | " |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 132 | FATAL: Cannot build simulation modules with wpilib disabled. |
| 133 | Enable wpilib by setting WITH_WPILIB=ON |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 134 | " |
| 135 | ) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 136 | endif() |
| 137 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 138 | if(NOT WITH_NTCORE AND WITH_CSCORE) |
| 139 | message( |
| 140 | FATAL_ERROR |
| 141 | " |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 142 | FATAL: Cannot build cameraserver without ntcore. |
| 143 | Enable ntcore by setting WITH_NTCORE=ON |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 144 | " |
| 145 | ) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 146 | endif() |
| 147 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 148 | if(NOT WITH_NTCORE AND WITH_GUI) |
| 149 | message( |
| 150 | FATAL_ERROR |
| 151 | " |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 152 | FATAL: Cannot build GUI modules without ntcore. |
| 153 | Enable ntcore by setting WITH_NTCORE=ON |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 154 | " |
| 155 | ) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 156 | endif() |
| 157 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 158 | if(NOT WITH_NTCORE AND WITH_SIMULATION_MODULES) |
| 159 | message( |
| 160 | FATAL_ERROR |
| 161 | " |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 162 | FATAL: Cannot build simulation modules without ntcore. |
| 163 | Enable ntcore by setting WITH_NTCORE=ON |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 164 | " |
| 165 | ) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 166 | endif() |
| 167 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 168 | if(NOT WITH_NTCORE AND WITH_WPILIB) |
| 169 | message( |
| 170 | FATAL_ERROR |
| 171 | " |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 172 | FATAL: Cannot build wpilib without ntcore. |
| 173 | Enable ntcore by setting WITH_NTCORE=ON |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 174 | " |
| 175 | ) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 176 | endif() |
| 177 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 178 | if(NOT WITH_WPIMATH AND WITH_WPILIB) |
| 179 | message( |
| 180 | FATAL_ERROR |
| 181 | " |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 182 | FATAL: Cannot build wpilib without wpimath. |
| 183 | Enable wpimath by setting WITH_WPIMATH=ON |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 184 | " |
| 185 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 186 | endif() |
| 187 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 188 | if(NOT WITH_WPIUNITS AND WITH_WPIMATH AND WITH_JAVA) |
| 189 | message( |
| 190 | FATAL_ERROR |
| 191 | " |
| 192 | FATAL: Cannot build Java wpimath without wpiunits. |
| 193 | Enable wpiunits by setting WITH_WPIUNITS=ON or disable the Java build by setting WITH_JAVA=OFF |
| 194 | " |
| 195 | ) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 196 | endif() |
| 197 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 198 | set(include_dest include) |
| 199 | set(java_lib_dest java) |
| 200 | set(jni_lib_dest jni) |
| 201 | |
| 202 | if(USE_SYSTEM_LIBUV) |
| 203 | set(LIBUV_SYSTEM_REPLACE |
| 204 | " |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 205 | find_dependency(libuv CONFIG) |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 206 | " |
| 207 | ) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 208 | endif() |
| 209 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 210 | if(USE_SYSTEM_EIGEN) |
| 211 | set(EIGEN_SYSTEM_REPLACE "find_package(Eigen3 CONFIG)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 212 | endif() |
| 213 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 214 | find_package(LIBSSH 0.7.1) |
| 215 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 216 | find_package(Protobuf REQUIRED) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 217 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 218 | set(APRILTAG_DEP_REPLACE "find_dependency(apriltag)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 219 | set(CAMERASERVER_DEP_REPLACE_IMPL "find_dependency(cameraserver)") |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 220 | set(CSCORE_DEP_REPLACE_IMPL "find_dependency(cscore)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 221 | set(HAL_DEP_REPLACE_IMPL "find_dependency(hal)") |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 222 | set(NTCORE_DEP_REPLACE "find_dependency(ntcore)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 223 | set(WPILIBC_DEP_REPLACE_IMPL "find_dependency(wpilibc)") |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 224 | set(WPILIBJ_DEP_REPLACE "find_dependency(wpilibj)") |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 225 | set(WPILIBNEWCOMMANDS_DEP_REPLACE "find_dependency(wpilibNewCommands)") |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 226 | set(WPIMATH_DEP_REPLACE "find_dependency(wpimath)") |
| 227 | set(WPINET_DEP_REPLACE "find_dependency(wpinet)") |
| 228 | set(WPIUNITS_DEP_REPLACE "find_dependency(wpiunits)") |
| 229 | set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 230 | |
| 231 | set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)") |
| 232 | set(SELF_DIR "$\{SELF_DIR\}") |
| 233 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 234 | get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 235 | |
| 236 | if(isMultiConfig) |
| 237 | if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES) |
| 238 | list(APPEND CMAKE_CONFIGURATION_TYPES Asan) |
| 239 | endif() |
| 240 | if(NOT "Tsan" IN_LIST CMAKE_CONFIGURATION_TYPES) |
| 241 | list(APPEND CMAKE_CONFIGURATION_TYPES Tsan) |
| 242 | endif() |
| 243 | if(NOT "Ubsan" IN_LIST CMAKE_CONFIGURATION_TYPES) |
| 244 | list(APPEND CMAKE_CONFIGURATION_TYPES Ubsan) |
| 245 | endif() |
| 246 | else() |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 247 | set(allowedBuildTypes |
| 248 | Asan |
| 249 | Tsan |
| 250 | Ubsan |
| 251 | Debug |
| 252 | Release |
| 253 | RelWithDebInfo |
| 254 | MinSizeRel |
| 255 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 256 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}") |
| 257 | |
| 258 | if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes) |
| 259 | message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}") |
| 260 | endif() |
| 261 | endif() |
| 262 | |
| 263 | set(CMAKE_C_FLAGS_ASAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 264 | "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" |
| 265 | CACHE STRING |
| 266 | "Flags used by the C compiler for Asan build type or configuration." |
| 267 | FORCE |
| 268 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 269 | |
| 270 | set(CMAKE_CXX_FLAGS_ASAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 271 | "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" |
| 272 | CACHE STRING |
| 273 | "Flags used by the C++ compiler for Asan build type or configuration." |
| 274 | FORCE |
| 275 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 276 | |
| 277 | set(CMAKE_EXE_LINKER_FLAGS_ASAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 278 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" |
| 279 | CACHE STRING |
| 280 | "Linker flags to be used to create executables for Asan build type." |
| 281 | FORCE |
| 282 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 283 | |
| 284 | set(CMAKE_SHARED_LINKER_FLAGS_ASAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 285 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" |
| 286 | CACHE STRING |
| 287 | "Linker lags to be used to create shared libraries for Asan build type." |
| 288 | FORCE |
| 289 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 290 | |
| 291 | set(CMAKE_C_FLAGS_TSAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 292 | "${CMAKE_C_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer" |
| 293 | CACHE STRING |
| 294 | "Flags used by the C compiler for Tsan build type or configuration." |
| 295 | FORCE |
| 296 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 297 | |
| 298 | set(CMAKE_CXX_FLAGS_TSAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 299 | "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer" |
| 300 | CACHE STRING |
| 301 | "Flags used by the C++ compiler for Tsan build type or configuration." |
| 302 | FORCE |
| 303 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 304 | |
| 305 | set(CMAKE_EXE_LINKER_FLAGS_TSAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 306 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread" |
| 307 | CACHE STRING |
| 308 | "Linker flags to be used to create executables for Tsan build type." |
| 309 | FORCE |
| 310 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 311 | |
| 312 | set(CMAKE_SHARED_LINKER_FLAGS_TSAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 313 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread" |
| 314 | CACHE STRING |
| 315 | "Linker lags to be used to create shared libraries for Tsan build type." |
| 316 | FORCE |
| 317 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 318 | |
| 319 | set(CMAKE_C_FLAGS_UBSAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 320 | "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" |
| 321 | CACHE STRING |
| 322 | "Flags used by the C compiler for Ubsan build type or configuration." |
| 323 | FORCE |
| 324 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 325 | |
| 326 | set(CMAKE_CXX_FLAGS_UBSAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 327 | "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" |
| 328 | CACHE STRING |
| 329 | "Flags used by the C++ compiler for Ubsan build type or configuration." |
| 330 | FORCE |
| 331 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 332 | |
| 333 | set(CMAKE_EXE_LINKER_FLAGS_UBSAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 334 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all" |
| 335 | CACHE STRING |
| 336 | "Linker flags to be used to create executables for Ubsan build type." |
| 337 | FORCE |
| 338 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 339 | |
| 340 | set(CMAKE_SHARED_LINKER_FLAGS_UBSAN |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 341 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined" |
| 342 | CACHE STRING |
| 343 | "Linker lags to be used to create shared libraries for Ubsan build type." |
| 344 | FORCE |
| 345 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 346 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 347 | if(WITH_TESTS) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 348 | enable_testing() |
| 349 | add_subdirectory(googletest) |
| 350 | include(GoogleTest) |
| 351 | endif() |
| 352 | |
| 353 | add_subdirectory(wpiutil) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 354 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 355 | if(WITH_NTCORE) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 356 | add_subdirectory(wpinet) |
| 357 | add_subdirectory(ntcore) |
| 358 | endif() |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 359 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 360 | if(WITH_WPIMATH) |
| 361 | if(WITH_JAVA) |
| 362 | add_subdirectory(wpiunits) |
| 363 | endif() |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 364 | add_subdirectory(wpimath) |
| 365 | endif() |
| 366 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 367 | if(WITH_WPIUNITS AND NOT WITH_WPIMATH) |
| 368 | # In case of building wpiunits standalone |
| 369 | add_subdirectory(wpiunits) |
| 370 | endif() |
| 371 | |
| 372 | if(WITH_GUI) |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 373 | add_subdirectory(fieldImages) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 374 | add_subdirectory(imgui) |
| 375 | add_subdirectory(wpigui) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 376 | add_subdirectory(glass) |
| 377 | add_subdirectory(outlineviewer) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 378 | add_subdirectory(sysid) |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 379 | if(LIBSSH_FOUND) |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 380 | add_subdirectory(roborioteamnumbersetter) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 381 | add_subdirectory(datalogtool) |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 382 | endif() |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 383 | endif() |
| 384 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 385 | if(WITH_WPILIB OR WITH_SIMULATION_MODULES) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 386 | set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL}) |
| 387 | add_subdirectory(hal) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 388 | endif() |
| 389 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 390 | if(WITH_CSCORE) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 391 | set(CSCORE_DEP_REPLACE ${CSCORE_DEP_REPLACE_IMPL}) |
| 392 | set(CAMERASERVER_DEP_REPLACE ${CAMERASERVER_DEP_REPLACE_IMPL}) |
| 393 | add_subdirectory(cscore) |
| 394 | add_subdirectory(cameraserver) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 395 | endif() |
| 396 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 397 | if(WITH_WPILIB) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 398 | set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL}) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 399 | add_subdirectory(apriltag) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 400 | add_subdirectory(wpilibj) |
| 401 | add_subdirectory(wpilibc) |
| 402 | add_subdirectory(wpilibNewCommands) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 403 | add_subdirectory(romiVendordep) |
| 404 | add_subdirectory(xrpVendordep) |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 405 | if(WITH_EXAMPLES) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 406 | add_subdirectory(wpilibcExamples) |
| 407 | endif() |
| 408 | add_subdirectory(myRobot) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 409 | endif() |
| 410 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 411 | if(WITH_SIMULATION_MODULES AND NOT WITH_EXTERNAL_HAL) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 412 | add_subdirectory(simulation) |
| 413 | endif() |
| 414 | |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame] | 415 | configure_file(wpilib-config.cmake.in ${WPILIB_BINARY_DIR}/wpilib-config.cmake) |
| 416 | install(FILES ${WPILIB_BINARY_DIR}/wpilib-config.cmake DESTINATION share/wpilib) |