blob: 399421f7b3fc8088593294ca02c92fa5b1e6b351 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001# Disable in-source builds to prevent source tree corruption.
2if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
3 message(FATAL_ERROR "
4FATAL: In-source builds are not allowed.
5 You should create a separate directory for build files.
6")
7endif()
8
9
10project(allwpilib)
11cmake_minimum_required(VERSION 3.3.0)
12set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
13
14INCLUDE(CPack)
15
16set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
17set_property(GLOBAL PROPERTY USE_FOLDERS ON)
18
Brian Silverman8fce7482020-01-05 13:18:21 -080019set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
20set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
21set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
22set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${CMAKE_BINARY_DIR}/jar)
23
24# use, i.e. don't skip the full RPATH for the build tree
25SET(CMAKE_SKIP_BUILD_RPATH FALSE)
26
27# when building, don't use the install RPATH already
28# (but later on when installing)
29SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
30
31SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib")
32
33# add the automatically determined parts of the RPATH
34# which point to directories outside the build tree to the install RPATH
35SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
36
37# the RPATH to be used when installing, but only if it's not a system directory
38LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/wpilib/lib" isSystemDir)
39IF("${isSystemDir}" STREQUAL "-1")
40 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib")
41ENDIF("${isSystemDir}" STREQUAL "-1")
42
Austin Schuh1e69f942020-11-14 15:06:14 -080043# Options for building certain parts of the repo. Everything is built by default.
44option(BUILD_SHARED_LIBS "Build with shared libs (needed for JNI)" ON)
45option(WITH_JAVA "Include java and JNI in the build" ON)
46option(WITH_CSCORE "Build cscore (needs OpenCV)" ON)
47option(WITH_WPILIB "Build hal, wpilibc/j, wpimath, and myRobot (needs OpenCV)" ON)
48option(WITH_TESTS "Build unit tests (requires internet connection)" ON)
49option(WITH_GUI "Build GUI items" ON)
50option(WITH_SIMULATION_MODULES "Build simulation modules" ON)
51
52# Options for external HAL.
53option(WITH_EXTERNAL_HAL "Use a separately built HAL" OFF)
Brian Silverman8fce7482020-01-05 13:18:21 -080054set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File")
Austin Schuh1e69f942020-11-14 15:06:14 -080055
56# Options for using a package manager (vcpkg) for certain dependencies.
Brian Silverman8fce7482020-01-05 13:18:21 -080057option(USE_VCPKG_LIBUV "Use vcpkg libuv" OFF)
58option(USE_VCPKG_EIGEN "Use vcpkg eigen" OFF)
Brian Silverman8fce7482020-01-05 13:18:21 -080059
Austin Schuh1e69f942020-11-14 15:06:14 -080060# Options for installation.
61option(WITH_FLAT_INSTALL "Use a flat install directory" OFF)
62
63# Options for location of OpenCV Java.
64set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file")
65
66# Set default build type to release with debug info (i.e. release mode optimizations
67# are performed, but debug info still exists).
68if (NOT CMAKE_BUILD_TYPE)
69 set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
70endif()
71
72# We always want flat install with MSVC.
73if (MSVC)
74 set(WITH_FLAT_INSTALL ON)
75endif()
76
77if (WITH_JAVA AND NOT BUILD_SHARED_LIBS)
Brian Silverman8fce7482020-01-05 13:18:21 -080078 message(FATAL_ERROR "
79FATAL: Cannot build static libs with Java enabled.
80 Static libs requires both BUILD_SHARED_LIBS=OFF and
Austin Schuh1e69f942020-11-14 15:06:14 -080081 WITH_JAVA=OFF
82")
83endif()
84
85if (WITH_SIMULATION_MODULES AND NOT BUILD_SHARED_LIBS)
86 message(FATAL_ERROR "
87FATAL: Cannot build static libs with simulation modules enabled.
88 Static libs requires both BUILD_SHARED_LIBS=OFF and
89 WITH_SIMULATION_MODULES=OFF
90")
91endif()
92
93if (NOT WITH_JAVA OR NOT WITH_CSCORE)
94 if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "")
95 message(WARNING "
96WARNING: OpenCV Java dir set but java is not enabled!
97It will be ignored.
98")
99 endif()
100endif()
101
102if (NOT WITH_WPILIB AND WITH_SIMULATION_MODULES)
103 message(FATAL_ERROR "
104FATAL: Cannot build simulation modules with wpilib disabled.
105 Enable wpilib by setting WITH_WPILIB=ON
Brian Silverman8fce7482020-01-05 13:18:21 -0800106")
107endif()
108
109set( wpilib_dest wpilib)
110set( include_dest wpilib/include )
111set( main_lib_dest wpilib/lib )
112set( java_lib_dest wpilib/java )
113set( jni_lib_dest wpilib/jni )
114
Austin Schuh1e69f942020-11-14 15:06:14 -0800115if (WITH_FLAT_INSTALL)
Brian Silverman8fce7482020-01-05 13:18:21 -0800116 set (wpilib_config_dir ${wpilib_dest})
117else()
118 set (wpilib_config_dir share/wpilib)
119endif()
120
121if (USE_VCPKG_LIBUV)
122set (LIBUV_VCPKG_REPLACE "find_package(unofficial-libuv CONFIG)")
123endif()
124
125if (USE_VCPKG_EIGEN)
126set (EIGEN_VCPKG_REPLACE "find_package(Eigen3 CONFIG)")
127endif()
128
Austin Schuh1e69f942020-11-14 15:06:14 -0800129if (WITH_FLAT_INSTALL)
Brian Silverman8fce7482020-01-05 13:18:21 -0800130set(WPIUTIL_DEP_REPLACE "include($\{SELF_DIR\}/wpiutil-config.cmake)")
131set(NTCORE_DEP_REPLACE "include($\{SELF_DIR\}/ntcore-config.cmake)")
132set(CSCORE_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cscore-config.cmake)")
133set(CAMERASERVER_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cameraserver-config.cmake)")
134set(HAL_DEP_REPLACE_IMPL "include(\${SELF_DIR}/hal-config.cmake)")
Austin Schuh1e69f942020-11-14 15:06:14 -0800135set(WPIMATH_DEP_REPLACE "include($\{SELF_DIR\}/wpimath-config.cmake)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800136set(WPILIBC_DEP_REPLACE_IMPL "include(\${SELF_DIR}/wpilibc-config.cmake)")
137else()
138set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)")
139set(NTCORE_DEP_REPLACE "find_dependency(ntcore)")
140set(CSCORE_DEP_REPLACE_IMPL "find_dependency(cscore)")
141set(CAMERASERVER_DEP_REPLACE_IMPL "find_dependency(cameraserver)")
142set(HAL_DEP_REPLACE_IMPL "find_dependency(hal)")
Austin Schuh1e69f942020-11-14 15:06:14 -0800143set(WPIMATH_DEP_REPLACE "find_dependency(wpimath)")
Brian Silverman8fce7482020-01-05 13:18:21 -0800144set(WPILIBC_DEP_REPLACE_IMPL "find_dependency(wpilibc)")
145endif()
146
147set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)")
148set(SELF_DIR "$\{SELF_DIR\}")
149
150if (WITH_TESTS)
151 enable_testing()
152 add_subdirectory(googletest)
153 include(GoogleTest)
154endif()
155
156add_subdirectory(wpiutil)
157add_subdirectory(ntcore)
158
Austin Schuh1e69f942020-11-14 15:06:14 -0800159if (WITH_GUI)
160 add_subdirectory(imgui)
161 add_subdirectory(wpigui)
162endif()
163
164if (WITH_CSCORE)
Brian Silverman8fce7482020-01-05 13:18:21 -0800165 set(CSCORE_DEP_REPLACE ${CSCORE_DEP_REPLACE_IMPL})
166 set(CAMERASERVER_DEP_REPLACE ${CAMERASERVER_DEP_REPLACE_IMPL})
167 add_subdirectory(cscore)
168 add_subdirectory(cameraserver)
Austin Schuh1e69f942020-11-14 15:06:14 -0800169 if (WITH_WPILIB)
Brian Silverman8fce7482020-01-05 13:18:21 -0800170 set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL})
171 set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL})
172 add_subdirectory(hal)
Austin Schuh1e69f942020-11-14 15:06:14 -0800173 add_subdirectory(wpimath)
Brian Silverman8fce7482020-01-05 13:18:21 -0800174 add_subdirectory(wpilibj)
175 add_subdirectory(wpilibc)
176 add_subdirectory(myRobot)
177 endif()
178endif()
179
Austin Schuh1e69f942020-11-14 15:06:14 -0800180if (WITH_SIMULATION_MODULES AND NOT WITH_EXTERNAL_HAL)
Brian Silverman8fce7482020-01-05 13:18:21 -0800181 add_subdirectory(simulation)
182endif()
183
184configure_file(wpilib-config.cmake.in ${CMAKE_BINARY_DIR}/wpilib-config.cmake )
185install(FILES ${CMAKE_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir})