Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | # Disable in-source builds to prevent source tree corruption. |
| 2 | if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}") |
| 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) |
| 12 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules") |
| 13 | |
| 14 | INCLUDE(CPack) |
| 15 | |
| 16 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
| 17 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 18 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 19 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 20 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 21 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 22 | set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${CMAKE_BINARY_DIR}/jar) |
| 23 | |
| 24 | # use, i.e. don't skip the full RPATH for the build tree |
| 25 | SET(CMAKE_SKIP_BUILD_RPATH FALSE) |
| 26 | |
| 27 | # when building, don't use the install RPATH already |
| 28 | # (but later on when installing) |
| 29 | SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
| 30 | |
| 31 | SET(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 |
| 35 | SET(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 |
| 38 | LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/wpilib/lib" isSystemDir) |
| 39 | IF("${isSystemDir}" STREQUAL "-1") |
| 40 | SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib") |
| 41 | ENDIF("${isSystemDir}" STREQUAL "-1") |
| 42 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 43 | # Options for building certain parts of the repo. Everything is built by default. |
| 44 | option(BUILD_SHARED_LIBS "Build with shared libs (needed for JNI)" ON) |
| 45 | option(WITH_JAVA "Include java and JNI in the build" ON) |
| 46 | option(WITH_CSCORE "Build cscore (needs OpenCV)" ON) |
| 47 | option(WITH_WPILIB "Build hal, wpilibc/j, wpimath, and myRobot (needs OpenCV)" ON) |
| 48 | option(WITH_TESTS "Build unit tests (requires internet connection)" ON) |
| 49 | option(WITH_GUI "Build GUI items" ON) |
| 50 | option(WITH_SIMULATION_MODULES "Build simulation modules" ON) |
| 51 | |
| 52 | # Options for external HAL. |
| 53 | option(WITH_EXTERNAL_HAL "Use a separately built HAL" OFF) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 54 | 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^] | 55 | |
| 56 | # Options for using a package manager (vcpkg) for certain dependencies. |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 57 | option(USE_VCPKG_LIBUV "Use vcpkg libuv" OFF) |
| 58 | option(USE_VCPKG_EIGEN "Use vcpkg eigen" OFF) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 59 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 60 | # Options for installation. |
| 61 | option(WITH_FLAT_INSTALL "Use a flat install directory" OFF) |
| 62 | |
| 63 | # Options for location of OpenCV Java. |
| 64 | set(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). |
| 68 | if (NOT CMAKE_BUILD_TYPE) |
| 69 | set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE) |
| 70 | endif() |
| 71 | |
| 72 | # We always want flat install with MSVC. |
| 73 | if (MSVC) |
| 74 | set(WITH_FLAT_INSTALL ON) |
| 75 | endif() |
| 76 | |
| 77 | if (WITH_JAVA AND NOT BUILD_SHARED_LIBS) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 78 | message(FATAL_ERROR " |
| 79 | FATAL: Cannot build static libs with Java enabled. |
| 80 | Static libs requires both BUILD_SHARED_LIBS=OFF and |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 81 | WITH_JAVA=OFF |
| 82 | ") |
| 83 | endif() |
| 84 | |
| 85 | if (WITH_SIMULATION_MODULES AND NOT BUILD_SHARED_LIBS) |
| 86 | message(FATAL_ERROR " |
| 87 | FATAL: Cannot build static libs with simulation modules enabled. |
| 88 | Static libs requires both BUILD_SHARED_LIBS=OFF and |
| 89 | WITH_SIMULATION_MODULES=OFF |
| 90 | ") |
| 91 | endif() |
| 92 | |
| 93 | if (NOT WITH_JAVA OR NOT WITH_CSCORE) |
| 94 | if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "") |
| 95 | message(WARNING " |
| 96 | WARNING: OpenCV Java dir set but java is not enabled! |
| 97 | It will be ignored. |
| 98 | ") |
| 99 | endif() |
| 100 | endif() |
| 101 | |
| 102 | if (NOT WITH_WPILIB AND WITH_SIMULATION_MODULES) |
| 103 | message(FATAL_ERROR " |
| 104 | FATAL: Cannot build simulation modules with wpilib disabled. |
| 105 | Enable wpilib by setting WITH_WPILIB=ON |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 106 | ") |
| 107 | endif() |
| 108 | |
| 109 | set( wpilib_dest wpilib) |
| 110 | set( include_dest wpilib/include ) |
| 111 | set( main_lib_dest wpilib/lib ) |
| 112 | set( java_lib_dest wpilib/java ) |
| 113 | set( jni_lib_dest wpilib/jni ) |
| 114 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 115 | if (WITH_FLAT_INSTALL) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 116 | set (wpilib_config_dir ${wpilib_dest}) |
| 117 | else() |
| 118 | set (wpilib_config_dir share/wpilib) |
| 119 | endif() |
| 120 | |
| 121 | if (USE_VCPKG_LIBUV) |
| 122 | set (LIBUV_VCPKG_REPLACE "find_package(unofficial-libuv CONFIG)") |
| 123 | endif() |
| 124 | |
| 125 | if (USE_VCPKG_EIGEN) |
| 126 | set (EIGEN_VCPKG_REPLACE "find_package(Eigen3 CONFIG)") |
| 127 | endif() |
| 128 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 129 | if (WITH_FLAT_INSTALL) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 130 | set(WPIUTIL_DEP_REPLACE "include($\{SELF_DIR\}/wpiutil-config.cmake)") |
| 131 | set(NTCORE_DEP_REPLACE "include($\{SELF_DIR\}/ntcore-config.cmake)") |
| 132 | set(CSCORE_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cscore-config.cmake)") |
| 133 | set(CAMERASERVER_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cameraserver-config.cmake)") |
| 134 | set(HAL_DEP_REPLACE_IMPL "include(\${SELF_DIR}/hal-config.cmake)") |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 135 | set(WPIMATH_DEP_REPLACE "include($\{SELF_DIR\}/wpimath-config.cmake)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 136 | set(WPILIBC_DEP_REPLACE_IMPL "include(\${SELF_DIR}/wpilibc-config.cmake)") |
| 137 | else() |
| 138 | set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)") |
| 139 | set(NTCORE_DEP_REPLACE "find_dependency(ntcore)") |
| 140 | set(CSCORE_DEP_REPLACE_IMPL "find_dependency(cscore)") |
| 141 | set(CAMERASERVER_DEP_REPLACE_IMPL "find_dependency(cameraserver)") |
| 142 | set(HAL_DEP_REPLACE_IMPL "find_dependency(hal)") |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 143 | set(WPIMATH_DEP_REPLACE "find_dependency(wpimath)") |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 144 | set(WPILIBC_DEP_REPLACE_IMPL "find_dependency(wpilibc)") |
| 145 | endif() |
| 146 | |
| 147 | set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)") |
| 148 | set(SELF_DIR "$\{SELF_DIR\}") |
| 149 | |
| 150 | if (WITH_TESTS) |
| 151 | enable_testing() |
| 152 | add_subdirectory(googletest) |
| 153 | include(GoogleTest) |
| 154 | endif() |
| 155 | |
| 156 | add_subdirectory(wpiutil) |
| 157 | add_subdirectory(ntcore) |
| 158 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 159 | if (WITH_GUI) |
| 160 | add_subdirectory(imgui) |
| 161 | add_subdirectory(wpigui) |
| 162 | endif() |
| 163 | |
| 164 | if (WITH_CSCORE) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 165 | 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 169 | if (WITH_WPILIB) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 170 | set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL}) |
| 171 | set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL}) |
| 172 | add_subdirectory(hal) |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 173 | add_subdirectory(wpimath) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 174 | add_subdirectory(wpilibj) |
| 175 | add_subdirectory(wpilibc) |
| 176 | add_subdirectory(myRobot) |
| 177 | endif() |
| 178 | endif() |
| 179 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 180 | if (WITH_SIMULATION_MODULES AND NOT WITH_EXTERNAL_HAL) |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 181 | add_subdirectory(simulation) |
| 182 | endif() |
| 183 | |
| 184 | configure_file(wpilib-config.cmake.in ${CMAKE_BINARY_DIR}/wpilib-config.cmake ) |
| 185 | install(FILES ${CMAKE_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir}) |