blob: f994bf13e54153e3eaeefe6d7ac8a32ac0ba53d6 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001# Disable in-source builds to prevent source tree corruption.
Austin Schuh812d0d12021-11-04 20:16:48 -07002if(" ${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL " ${CMAKE_CURRENT_BINARY_DIR}")
Brian Silverman8fce7482020-01-05 13:18:21 -08003 message(FATAL_ERROR "
4FATAL: In-source builds are not allowed.
5 You should create a separate directory for build files.
6")
7endif()
8
Austin Schuh75263e32022-02-22 18:05:32 -08009if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
10 set(CMAKE_SYSTEM_VERSION 10.0.18362.0 CACHE STRING INTERNAL FORCE)
11 set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 10.0.18362.0 CACHE STRING INTERNAL FORCE)
12endif()
Brian Silverman8fce7482020-01-05 13:18:21 -080013
James Kuszmaulb13e13f2023-11-22 20:44:04 -080014cmake_minimum_required(VERSION 3.11)
Brian Silverman8fce7482020-01-05 13:18:21 -080015project(allwpilib)
Austin Schuh812d0d12021-11-04 20:16:48 -070016set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
17
James Kuszmaulb13e13f2023-11-22 20:44:04 -080018# Make timestamps of extracted files from FetchContent the time of extraction
19if (POLICY CMP0135)
20 cmake_policy(SET CMP0135 NEW)
21endif()
22
Austin Schuh75263e32022-02-22 18:05:32 -080023message(STATUS "Platform version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
24
Austin Schuh812d0d12021-11-04 20:16:48 -070025set(WPILIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
Brian Silverman8fce7482020-01-05 13:18:21 -080026
27INCLUDE(CPack)
28
29set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
30set_property(GLOBAL PROPERTY USE_FOLDERS ON)
31
Austin Schuh812d0d12021-11-04 20:16:48 -070032set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib)
33set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib)
34set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/bin)
35set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${WPILIB_BINARY_DIR}/jar)
Brian Silverman8fce7482020-01-05 13:18:21 -080036
37# use, i.e. don't skip the full RPATH for the build tree
38SET(CMAKE_SKIP_BUILD_RPATH FALSE)
39
40# when building, don't use the install RPATH already
41# (but later on when installing)
42SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
43
James Kuszmaulcf324122023-01-14 14:07:17 -080044SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
Brian Silverman8fce7482020-01-05 13:18:21 -080045
46# add the automatically determined parts of the RPATH
47# which point to directories outside the build tree to the install RPATH
48SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
49
50# the RPATH to be used when installing, but only if it's not a system directory
James Kuszmaulcf324122023-01-14 14:07:17 -080051LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
Brian Silverman8fce7482020-01-05 13:18:21 -080052IF("${isSystemDir}" STREQUAL "-1")
James Kuszmaulcf324122023-01-14 14:07:17 -080053 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
Brian Silverman8fce7482020-01-05 13:18:21 -080054ENDIF("${isSystemDir}" STREQUAL "-1")
55
Austin Schuh1e69f942020-11-14 15:06:14 -080056# Options for building certain parts of the repo. Everything is built by default.
57option(BUILD_SHARED_LIBS "Build with shared libs (needed for JNI)" ON)
James Kuszmaulb13e13f2023-11-22 20:44:04 -080058option(WITH_JAVA "Include Java and JNI in the build" ON)
59option(WITH_JAVA_SOURCE "Build Java source jars" ON)
Austin Schuh1e69f942020-11-14 15:06:14 -080060option(WITH_CSCORE "Build cscore (needs OpenCV)" ON)
James Kuszmaulcf324122023-01-14 14:07:17 -080061option(WITH_NTCORE "Build ntcore" ON)
Austin Schuh812d0d12021-11-04 20:16:48 -070062option(WITH_WPIMATH "Build wpimath" ON)
63option(WITH_WPILIB "Build hal, wpilibc/j, and myRobot (needs OpenCV)" ON)
Austin Schuh812d0d12021-11-04 20:16:48 -070064option(WITH_EXAMPLES "Build examples" OFF)
Austin Schuh1e69f942020-11-14 15:06:14 -080065option(WITH_TESTS "Build unit tests (requires internet connection)" ON)
66option(WITH_GUI "Build GUI items" ON)
67option(WITH_SIMULATION_MODULES "Build simulation modules" ON)
68
69# Options for external HAL.
70option(WITH_EXTERNAL_HAL "Use a separately built HAL" OFF)
Brian Silverman8fce7482020-01-05 13:18:21 -080071set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File")
Austin Schuh1e69f942020-11-14 15:06:14 -080072
James Kuszmaulcf324122023-01-14 14:07:17 -080073# Options for using a package manager (e.g., vcpkg) for certain dependencies.
74option(USE_SYSTEM_FMTLIB "Use system fmtlib" OFF)
75option(USE_SYSTEM_LIBUV "Use system libuv" OFF)
76option(USE_SYSTEM_EIGEN "Use system eigen" OFF)
Brian Silverman8fce7482020-01-05 13:18:21 -080077
Austin Schuh1e69f942020-11-14 15:06:14 -080078# Options for installation.
79option(WITH_FLAT_INSTALL "Use a flat install directory" OFF)
80
81# Options for location of OpenCV Java.
82set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file")
83
84# Set default build type to release with debug info (i.e. release mode optimizations
85# are performed, but debug info still exists).
86if (NOT CMAKE_BUILD_TYPE)
87 set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
88endif()
89
Austin Schuh1e69f942020-11-14 15:06:14 -080090if (WITH_JAVA AND NOT BUILD_SHARED_LIBS)
Brian Silverman8fce7482020-01-05 13:18:21 -080091 message(FATAL_ERROR "
92FATAL: Cannot build static libs with Java enabled.
93 Static libs requires both BUILD_SHARED_LIBS=OFF and
Austin Schuh1e69f942020-11-14 15:06:14 -080094 WITH_JAVA=OFF
95")
96endif()
97
98if (WITH_SIMULATION_MODULES AND NOT BUILD_SHARED_LIBS)
99 message(FATAL_ERROR "
100FATAL: Cannot build static libs with simulation modules enabled.
101 Static libs requires both BUILD_SHARED_LIBS=OFF and
102 WITH_SIMULATION_MODULES=OFF
103")
104endif()
105
106if (NOT WITH_JAVA OR NOT WITH_CSCORE)
107 if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "")
108 message(WARNING "
109WARNING: OpenCV Java dir set but java is not enabled!
110It will be ignored.
111")
112 endif()
113endif()
114
115if (NOT WITH_WPILIB AND WITH_SIMULATION_MODULES)
116 message(FATAL_ERROR "
117FATAL: Cannot build simulation modules with wpilib disabled.
118 Enable wpilib by setting WITH_WPILIB=ON
Brian Silverman8fce7482020-01-05 13:18:21 -0800119")
120endif()
121
James Kuszmaulcf324122023-01-14 14:07:17 -0800122if (NOT WITH_NTCORE AND WITH_CSCORE)
123 message(FATAL_ERROR "
124FATAL: Cannot build cameraserver without ntcore.
125 Enable ntcore by setting WITH_NTCORE=ON
126")
127endif()
128
129if (NOT WITH_NTCORE AND WITH_GUI)
130 message(FATAL_ERROR "
131FATAL: Cannot build GUI modules without ntcore.
132 Enable ntcore by setting WITH_NTCORE=ON
133")
134endif()
135
136if (NOT WITH_NTCORE AND WITH_SIMULATION_MODULES)
137 message(FATAL_ERROR "
138FATAL: Cannot build simulation modules without ntcore.
139 Enable ntcore by setting WITH_NTCORE=ON
140")
141endif()
142
143if (NOT WITH_NTCORE AND WITH_WPILIB)
144 message(FATAL_ERROR "
145FATAL: Cannot build wpilib without ntcore.
146 Enable ntcore by setting WITH_NTCORE=ON
147")
148endif()
149
Austin Schuh812d0d12021-11-04 20:16:48 -0700150if (NOT WITH_WPIMATH AND WITH_WPILIB)
151 message(FATAL_ERROR "
152FATAL: Cannot build wpilib without wpimath.
153 Enable wpimath by setting WITH_WPIMATH=ON
154")
155endif()
156
James Kuszmaulcf324122023-01-14 14:07:17 -0800157set( wpilib_dest "")
158set( include_dest include )
James Kuszmaulcf324122023-01-14 14:07:17 -0800159set( java_lib_dest java )
160set( jni_lib_dest jni )
Brian Silverman8fce7482020-01-05 13:18:21 -0800161
Austin Schuh1e69f942020-11-14 15:06:14 -0800162if (WITH_FLAT_INSTALL)
Brian Silverman8fce7482020-01-05 13:18:21 -0800163 set (wpilib_config_dir ${wpilib_dest})
164else()
165 set (wpilib_config_dir share/wpilib)
166endif()
167
James Kuszmaulcf324122023-01-14 14:07:17 -0800168if (USE_SYSTEM_LIBUV)
169set (LIBUV_SYSTEM_REPLACE "
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800170find_dependency(libuv CONFIG)
James Kuszmaulcf324122023-01-14 14:07:17 -0800171")
Brian Silverman8fce7482020-01-05 13:18:21 -0800172endif()
173
James Kuszmaulcf324122023-01-14 14:07:17 -0800174if (USE_SYSTEM_EIGEN)
175set (EIGEN_SYSTEM_REPLACE "find_package(Eigen3 CONFIG)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800176endif()
177
Austin Schuh75263e32022-02-22 18:05:32 -0800178find_package(LIBSSH 0.7.1)
179
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800180find_package(Protobuf REQUIRED)
181find_program(Quickbuf_EXECUTABLE
182 NAMES protoc-gen-quickbuf
183 DOC "The Quickbuf protoc plugin"
184)
185
Austin Schuh1e69f942020-11-14 15:06:14 -0800186if (WITH_FLAT_INSTALL)
Brian Silverman8fce7482020-01-05 13:18:21 -0800187set(WPIUTIL_DEP_REPLACE "include($\{SELF_DIR\}/wpiutil-config.cmake)")
James Kuszmaulcf324122023-01-14 14:07:17 -0800188set(WPINET_DEP_REPLACE "include($\{SELF_DIR\}/wpinet-config.cmake)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800189set(NTCORE_DEP_REPLACE "include($\{SELF_DIR\}/ntcore-config.cmake)")
190set(CSCORE_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cscore-config.cmake)")
191set(CAMERASERVER_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cameraserver-config.cmake)")
192set(HAL_DEP_REPLACE_IMPL "include(\${SELF_DIR}/hal-config.cmake)")
Austin Schuh1e69f942020-11-14 15:06:14 -0800193set(WPIMATH_DEP_REPLACE "include($\{SELF_DIR\}/wpimath-config.cmake)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800194set(WPILIBC_DEP_REPLACE_IMPL "include(\${SELF_DIR}/wpilibc-config.cmake)")
Austin Schuh812d0d12021-11-04 20:16:48 -0700195set(WPILIBNEWCOMMANDS_DEP_REPLACE "include(\${SELF_DIR}/wpilibNewcommands-config.cmake)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800196else()
197set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)")
James Kuszmaulcf324122023-01-14 14:07:17 -0800198set(WPINET_DEP_REPLACE "find_dependency(wpinet)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800199set(NTCORE_DEP_REPLACE "find_dependency(ntcore)")
200set(CSCORE_DEP_REPLACE_IMPL "find_dependency(cscore)")
201set(CAMERASERVER_DEP_REPLACE_IMPL "find_dependency(cameraserver)")
202set(HAL_DEP_REPLACE_IMPL "find_dependency(hal)")
Austin Schuh1e69f942020-11-14 15:06:14 -0800203set(WPIMATH_DEP_REPLACE "find_dependency(wpimath)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800204set(WPILIBC_DEP_REPLACE_IMPL "find_dependency(wpilibc)")
Austin Schuh812d0d12021-11-04 20:16:48 -0700205set(WPILIBNEWCOMMANDS_DEP_REPLACE "find_dependency(wpilibNewCommands)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800206endif()
207
208set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)")
209set(SELF_DIR "$\{SELF_DIR\}")
210
Austin Schuh812d0d12021-11-04 20:16:48 -0700211get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
212
213if(isMultiConfig)
214 if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
215 list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
216 endif()
217 if(NOT "Tsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
218 list(APPEND CMAKE_CONFIGURATION_TYPES Tsan)
219 endif()
220 if(NOT "Ubsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
221 list(APPEND CMAKE_CONFIGURATION_TYPES Ubsan)
222 endif()
223else()
224 set(allowedBuildTypes Asan Tsan Ubsan Debug Release RelWithDebInfo MinSizeRel)
225 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")
226
227 if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
228 message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
229 endif()
230endif()
231
232set(CMAKE_C_FLAGS_ASAN
233 "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING
234 "Flags used by the C compiler for Asan build type or configuration." FORCE)
235
236set(CMAKE_CXX_FLAGS_ASAN
237 "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING
238 "Flags used by the C++ compiler for Asan build type or configuration." FORCE)
239
240set(CMAKE_EXE_LINKER_FLAGS_ASAN
241 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING
242 "Linker flags to be used to create executables for Asan build type." FORCE)
243
244set(CMAKE_SHARED_LINKER_FLAGS_ASAN
245 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING
246 "Linker lags to be used to create shared libraries for Asan build type." FORCE)
247
248set(CMAKE_C_FLAGS_TSAN
249 "${CMAKE_C_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer" CACHE STRING
250 "Flags used by the C compiler for Tsan build type or configuration." FORCE)
251
252set(CMAKE_CXX_FLAGS_TSAN
253 "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer" CACHE STRING
254 "Flags used by the C++ compiler for Tsan build type or configuration." FORCE)
255
256set(CMAKE_EXE_LINKER_FLAGS_TSAN
257 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread" CACHE STRING
258 "Linker flags to be used to create executables for Tsan build type." FORCE)
259
260set(CMAKE_SHARED_LINKER_FLAGS_TSAN
261 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread" CACHE STRING
262 "Linker lags to be used to create shared libraries for Tsan build type." FORCE)
263
264set(CMAKE_C_FLAGS_UBSAN
265 "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" CACHE STRING
266 "Flags used by the C compiler for Ubsan build type or configuration." FORCE)
267
268set(CMAKE_CXX_FLAGS_UBSAN
269 "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer" CACHE STRING
270 "Flags used by the C++ compiler for Ubsan build type or configuration." FORCE)
271
272set(CMAKE_EXE_LINKER_FLAGS_UBSAN
273 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all" CACHE STRING
274 "Linker flags to be used to create executables for Ubsan build type." FORCE)
275
276set(CMAKE_SHARED_LINKER_FLAGS_UBSAN
277 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined" CACHE STRING
278 "Linker lags to be used to create shared libraries for Ubsan build type." FORCE)
279
Brian Silverman8fce7482020-01-05 13:18:21 -0800280if (WITH_TESTS)
281 enable_testing()
282 add_subdirectory(googletest)
283 include(GoogleTest)
284endif()
285
286add_subdirectory(wpiutil)
James Kuszmaulcf324122023-01-14 14:07:17 -0800287
288if (WITH_NTCORE)
289 add_subdirectory(wpinet)
290 add_subdirectory(ntcore)
291endif()
Brian Silverman8fce7482020-01-05 13:18:21 -0800292
Austin Schuh812d0d12021-11-04 20:16:48 -0700293if (WITH_WPIMATH)
294 add_subdirectory(wpimath)
295endif()
296
Austin Schuh1e69f942020-11-14 15:06:14 -0800297if (WITH_GUI)
Austin Schuh75263e32022-02-22 18:05:32 -0800298 add_subdirectory(fieldImages)
Austin Schuh1e69f942020-11-14 15:06:14 -0800299 add_subdirectory(imgui)
300 add_subdirectory(wpigui)
Austin Schuh812d0d12021-11-04 20:16:48 -0700301 add_subdirectory(glass)
302 add_subdirectory(outlineviewer)
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800303 add_subdirectory(sysid)
Austin Schuh75263e32022-02-22 18:05:32 -0800304 if (LIBSSH_FOUND)
305 add_subdirectory(roborioteamnumbersetter)
James Kuszmaulcf324122023-01-14 14:07:17 -0800306 add_subdirectory(datalogtool)
Austin Schuh75263e32022-02-22 18:05:32 -0800307 endif()
Austin Schuh812d0d12021-11-04 20:16:48 -0700308endif()
309
310if (WITH_WPILIB OR WITH_SIMULATION_MODULES)
311 set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL})
312 add_subdirectory(hal)
Austin Schuh1e69f942020-11-14 15:06:14 -0800313endif()
314
315if (WITH_CSCORE)
Brian Silverman8fce7482020-01-05 13:18:21 -0800316 set(CSCORE_DEP_REPLACE ${CSCORE_DEP_REPLACE_IMPL})
317 set(CAMERASERVER_DEP_REPLACE ${CAMERASERVER_DEP_REPLACE_IMPL})
318 add_subdirectory(cscore)
319 add_subdirectory(cameraserver)
Austin Schuh812d0d12021-11-04 20:16:48 -0700320endif()
321
322if (WITH_WPILIB)
323 set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL})
James Kuszmaulcf324122023-01-14 14:07:17 -0800324 add_subdirectory(apriltag)
Austin Schuh812d0d12021-11-04 20:16:48 -0700325 add_subdirectory(wpilibj)
326 add_subdirectory(wpilibc)
327 add_subdirectory(wpilibNewCommands)
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800328 add_subdirectory(romiVendordep)
329 add_subdirectory(xrpVendordep)
Austin Schuh812d0d12021-11-04 20:16:48 -0700330 if (WITH_EXAMPLES)
331 add_subdirectory(wpilibcExamples)
332 endif()
333 add_subdirectory(myRobot)
Brian Silverman8fce7482020-01-05 13:18:21 -0800334endif()
335
Austin Schuh1e69f942020-11-14 15:06:14 -0800336if (WITH_SIMULATION_MODULES AND NOT WITH_EXTERNAL_HAL)
Brian Silverman8fce7482020-01-05 13:18:21 -0800337 add_subdirectory(simulation)
338endif()
339
Austin Schuh812d0d12021-11-04 20:16:48 -0700340configure_file(wpilib-config.cmake.in ${WPILIB_BINARY_DIR}/wpilib-config.cmake )
341install(FILES ${WPILIB_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir})