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}") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 3 | message(FATAL_ERROR " |
| 4 | FATAL: In-source builds are not allowed. |
| 5 | You should create a separate directory for build files. |
| 6 | ") |
| 7 | endif() |
| 8 | |
| 9 | |
| 10 | project(allwpilib) |
| 11 | cmake_minimum_required(VERSION 3.3.0) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 12 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") |
| 13 | |
| 14 | set(WPILIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 15 | |
| 16 | INCLUDE(CPack) |
| 17 | |
| 18 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
| 19 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 20 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 21 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib) |
| 22 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib) |
| 23 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/bin) |
| 24 | set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${WPILIB_BINARY_DIR}/jar) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 25 | |
| 26 | # use, i.e. don't skip the full RPATH for the build tree |
| 27 | SET(CMAKE_SKIP_BUILD_RPATH FALSE) |
| 28 | |
| 29 | # when building, don't use the install RPATH already |
| 30 | # (but later on when installing) |
| 31 | SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
| 32 | |
| 33 | SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib") |
| 34 | |
| 35 | # add the automatically determined parts of the RPATH |
| 36 | # which point to directories outside the build tree to the install RPATH |
| 37 | SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
| 38 | |
| 39 | # the RPATH to be used when installing, but only if it's not a system directory |
| 40 | LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/wpilib/lib" isSystemDir) |
| 41 | IF("${isSystemDir}" STREQUAL "-1") |
| 42 | SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib") |
| 43 | ENDIF("${isSystemDir}" STREQUAL "-1") |
| 44 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 45 | # Options for building certain parts of the repo. Everything is built by default. |
| 46 | option(BUILD_SHARED_LIBS "Build with shared libs (needed for JNI)" ON) |
| 47 | option(WITH_JAVA "Include java and JNI in the build" ON) |
| 48 | option(WITH_CSCORE "Build cscore (needs OpenCV)" ON) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 49 | option(WITH_WPIMATH "Build wpimath" ON) |
| 50 | option(WITH_WPILIB "Build hal, wpilibc/j, and myRobot (needs OpenCV)" ON) |
| 51 | option(WITH_OLD_COMMANDS "Build old commands" OFF) |
| 52 | option(WITH_EXAMPLES "Build examples" OFF) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 53 | option(WITH_TESTS "Build unit tests (requires internet connection)" ON) |
| 54 | option(WITH_GUI "Build GUI items" ON) |
| 55 | option(WITH_SIMULATION_MODULES "Build simulation modules" ON) |
| 56 | |
| 57 | # Options for external HAL. |
| 58 | option(WITH_EXTERNAL_HAL "Use a separately built HAL" OFF) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 59 | 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] | 60 | |
| 61 | # Options for using a package manager (vcpkg) for certain dependencies. |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 62 | option(USE_VCPKG_FMTLIB "Use vcpkg fmtlib" OFF) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 63 | option(USE_VCPKG_LIBUV "Use vcpkg libuv" OFF) |
| 64 | option(USE_VCPKG_EIGEN "Use vcpkg eigen" OFF) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 65 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 66 | # Options for installation. |
| 67 | option(WITH_FLAT_INSTALL "Use a flat install directory" OFF) |
| 68 | |
| 69 | # Options for location of OpenCV Java. |
| 70 | set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file") |
| 71 | |
| 72 | # Set default build type to release with debug info (i.e. release mode optimizations |
| 73 | # are performed, but debug info still exists). |
| 74 | if (NOT CMAKE_BUILD_TYPE) |
| 75 | set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE) |
| 76 | endif() |
| 77 | |
| 78 | # We always want flat install with MSVC. |
| 79 | if (MSVC) |
| 80 | set(WITH_FLAT_INSTALL ON) |
| 81 | endif() |
| 82 | |
| 83 | if (WITH_JAVA AND NOT BUILD_SHARED_LIBS) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 84 | message(FATAL_ERROR " |
| 85 | FATAL: Cannot build static libs with Java enabled. |
| 86 | Static libs requires both BUILD_SHARED_LIBS=OFF and |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 87 | WITH_JAVA=OFF |
| 88 | ") |
| 89 | endif() |
| 90 | |
| 91 | if (WITH_SIMULATION_MODULES AND NOT BUILD_SHARED_LIBS) |
| 92 | message(FATAL_ERROR " |
| 93 | FATAL: Cannot build static libs with simulation modules enabled. |
| 94 | Static libs requires both BUILD_SHARED_LIBS=OFF and |
| 95 | WITH_SIMULATION_MODULES=OFF |
| 96 | ") |
| 97 | endif() |
| 98 | |
| 99 | if (NOT WITH_JAVA OR NOT WITH_CSCORE) |
| 100 | if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "") |
| 101 | message(WARNING " |
| 102 | WARNING: OpenCV Java dir set but java is not enabled! |
| 103 | It will be ignored. |
| 104 | ") |
| 105 | endif() |
| 106 | endif() |
| 107 | |
| 108 | if (NOT WITH_WPILIB AND WITH_SIMULATION_MODULES) |
| 109 | message(FATAL_ERROR " |
| 110 | FATAL: Cannot build simulation modules with wpilib disabled. |
| 111 | Enable wpilib by setting WITH_WPILIB=ON |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 112 | ") |
| 113 | endif() |
| 114 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 115 | if (NOT WITH_WPIMATH AND WITH_WPILIB) |
| 116 | message(FATAL_ERROR " |
| 117 | FATAL: Cannot build wpilib without wpimath. |
| 118 | Enable wpimath by setting WITH_WPIMATH=ON |
| 119 | ") |
| 120 | endif() |
| 121 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 122 | set( wpilib_dest wpilib) |
| 123 | set( include_dest wpilib/include ) |
| 124 | set( main_lib_dest wpilib/lib ) |
| 125 | set( java_lib_dest wpilib/java ) |
| 126 | set( jni_lib_dest wpilib/jni ) |
| 127 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 128 | if (WITH_FLAT_INSTALL) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 129 | set (wpilib_config_dir ${wpilib_dest}) |
| 130 | else() |
| 131 | set (wpilib_config_dir share/wpilib) |
| 132 | endif() |
| 133 | |
| 134 | if (USE_VCPKG_LIBUV) |
| 135 | set (LIBUV_VCPKG_REPLACE "find_package(unofficial-libuv CONFIG)") |
| 136 | endif() |
| 137 | |
| 138 | if (USE_VCPKG_EIGEN) |
| 139 | set (EIGEN_VCPKG_REPLACE "find_package(Eigen3 CONFIG)") |
| 140 | endif() |
| 141 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 142 | if (WITH_FLAT_INSTALL) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 143 | set(WPIUTIL_DEP_REPLACE "include($\{SELF_DIR\}/wpiutil-config.cmake)") |
| 144 | set(NTCORE_DEP_REPLACE "include($\{SELF_DIR\}/ntcore-config.cmake)") |
| 145 | set(CSCORE_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cscore-config.cmake)") |
| 146 | set(CAMERASERVER_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cameraserver-config.cmake)") |
| 147 | set(HAL_DEP_REPLACE_IMPL "include(\${SELF_DIR}/hal-config.cmake)") |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 148 | set(WPIMATH_DEP_REPLACE "include($\{SELF_DIR\}/wpimath-config.cmake)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 149 | set(WPILIBC_DEP_REPLACE_IMPL "include(\${SELF_DIR}/wpilibc-config.cmake)") |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 150 | set(WPILIBNEWCOMMANDS_DEP_REPLACE "include(\${SELF_DIR}/wpilibNewcommands-config.cmake)") |
| 151 | set(WPILIBOLDCOMMANDS_DEP_REPLACE "include(\${SELF_DIR}/wpilibOldcommands-config.cmake)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 152 | else() |
| 153 | set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)") |
| 154 | set(NTCORE_DEP_REPLACE "find_dependency(ntcore)") |
| 155 | set(CSCORE_DEP_REPLACE_IMPL "find_dependency(cscore)") |
| 156 | set(CAMERASERVER_DEP_REPLACE_IMPL "find_dependency(cameraserver)") |
| 157 | set(HAL_DEP_REPLACE_IMPL "find_dependency(hal)") |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 158 | set(WPIMATH_DEP_REPLACE "find_dependency(wpimath)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 159 | set(WPILIBC_DEP_REPLACE_IMPL "find_dependency(wpilibc)") |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 160 | set(WPILIBNEWCOMMANDS_DEP_REPLACE "find_dependency(wpilibNewCommands)") |
| 161 | set(WPILIBOLDCOMMANDS_DEP_REPLACE "find_dependency(wpilibOldCommands)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 162 | endif() |
| 163 | |
| 164 | set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)") |
| 165 | set(SELF_DIR "$\{SELF_DIR\}") |
| 166 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 167 | get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 168 | |
| 169 | if(isMultiConfig) |
| 170 | if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES) |
| 171 | list(APPEND CMAKE_CONFIGURATION_TYPES Asan) |
| 172 | endif() |
| 173 | if(NOT "Tsan" IN_LIST CMAKE_CONFIGURATION_TYPES) |
| 174 | list(APPEND CMAKE_CONFIGURATION_TYPES Tsan) |
| 175 | endif() |
| 176 | if(NOT "Ubsan" IN_LIST CMAKE_CONFIGURATION_TYPES) |
| 177 | list(APPEND CMAKE_CONFIGURATION_TYPES Ubsan) |
| 178 | endif() |
| 179 | else() |
| 180 | set(allowedBuildTypes Asan Tsan Ubsan Debug Release RelWithDebInfo MinSizeRel) |
| 181 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}") |
| 182 | |
| 183 | if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes) |
| 184 | message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}") |
| 185 | endif() |
| 186 | endif() |
| 187 | |
| 188 | set(CMAKE_C_FLAGS_ASAN |
| 189 | "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING |
| 190 | "Flags used by the C compiler for Asan build type or configuration." FORCE) |
| 191 | |
| 192 | set(CMAKE_CXX_FLAGS_ASAN |
| 193 | "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING |
| 194 | "Flags used by the C++ compiler for Asan build type or configuration." FORCE) |
| 195 | |
| 196 | set(CMAKE_EXE_LINKER_FLAGS_ASAN |
| 197 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING |
| 198 | "Linker flags to be used to create executables for Asan build type." FORCE) |
| 199 | |
| 200 | set(CMAKE_SHARED_LINKER_FLAGS_ASAN |
| 201 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING |
| 202 | "Linker lags to be used to create shared libraries for Asan build type." FORCE) |
| 203 | |
| 204 | set(CMAKE_C_FLAGS_TSAN |
| 205 | "${CMAKE_C_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer" CACHE STRING |
| 206 | "Flags used by the C compiler for Tsan build type or configuration." FORCE) |
| 207 | |
| 208 | set(CMAKE_CXX_FLAGS_TSAN |
| 209 | "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer" CACHE STRING |
| 210 | "Flags used by the C++ compiler for Tsan build type or configuration." FORCE) |
| 211 | |
| 212 | set(CMAKE_EXE_LINKER_FLAGS_TSAN |
| 213 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread" CACHE STRING |
| 214 | "Linker flags to be used to create executables for Tsan build type." FORCE) |
| 215 | |
| 216 | set(CMAKE_SHARED_LINKER_FLAGS_TSAN |
| 217 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread" CACHE STRING |
| 218 | "Linker lags to be used to create shared libraries for Tsan build type." FORCE) |
| 219 | |
| 220 | set(CMAKE_C_FLAGS_UBSAN |
| 221 | "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" CACHE STRING |
| 222 | "Flags used by the C compiler for Ubsan build type or configuration." FORCE) |
| 223 | |
| 224 | set(CMAKE_CXX_FLAGS_UBSAN |
| 225 | "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" CACHE STRING |
| 226 | "Flags used by the C++ compiler for Ubsan build type or configuration." FORCE) |
| 227 | |
| 228 | set(CMAKE_EXE_LINKER_FLAGS_UBSAN |
| 229 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all" CACHE STRING |
| 230 | "Linker flags to be used to create executables for Ubsan build type." FORCE) |
| 231 | |
| 232 | set(CMAKE_SHARED_LINKER_FLAGS_UBSAN |
| 233 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined" CACHE STRING |
| 234 | "Linker lags to be used to create shared libraries for Ubsan build type." FORCE) |
| 235 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 236 | if (WITH_TESTS) |
| 237 | enable_testing() |
| 238 | add_subdirectory(googletest) |
| 239 | include(GoogleTest) |
| 240 | endif() |
| 241 | |
| 242 | add_subdirectory(wpiutil) |
| 243 | add_subdirectory(ntcore) |
| 244 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 245 | if (WITH_WPIMATH) |
| 246 | add_subdirectory(wpimath) |
| 247 | endif() |
| 248 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 249 | if (WITH_GUI) |
| 250 | add_subdirectory(imgui) |
| 251 | add_subdirectory(wpigui) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 252 | add_subdirectory(glass) |
| 253 | add_subdirectory(outlineviewer) |
| 254 | endif() |
| 255 | |
| 256 | if (WITH_WPILIB OR WITH_SIMULATION_MODULES) |
| 257 | set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL}) |
| 258 | add_subdirectory(hal) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 259 | endif() |
| 260 | |
| 261 | if (WITH_CSCORE) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 262 | set(CSCORE_DEP_REPLACE ${CSCORE_DEP_REPLACE_IMPL}) |
| 263 | set(CAMERASERVER_DEP_REPLACE ${CAMERASERVER_DEP_REPLACE_IMPL}) |
| 264 | add_subdirectory(cscore) |
| 265 | add_subdirectory(cameraserver) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 266 | endif() |
| 267 | |
| 268 | if (WITH_WPILIB) |
| 269 | set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL}) |
| 270 | add_subdirectory(wpilibj) |
| 271 | add_subdirectory(wpilibc) |
| 272 | add_subdirectory(wpilibNewCommands) |
| 273 | if (WITH_OLD_COMMANDS) |
| 274 | add_subdirectory(wpilibOldCommands) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 275 | endif() |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 276 | if (WITH_EXAMPLES) |
| 277 | add_subdirectory(wpilibcExamples) |
| 278 | endif() |
| 279 | add_subdirectory(myRobot) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 280 | endif() |
| 281 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 282 | if (WITH_SIMULATION_MODULES AND NOT WITH_EXTERNAL_HAL) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 283 | add_subdirectory(simulation) |
| 284 | endif() |
| 285 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 286 | configure_file(wpilib-config.cmake.in ${WPILIB_BINARY_DIR}/wpilib-config.cmake ) |
| 287 | install(FILES ${WPILIB_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir}) |