Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -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 | |
| 19 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND MSVC) |
| 20 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install dir on windows" FORCE) |
| 21 | endif() |
| 22 | |
| 23 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 24 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 25 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 26 | set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${CMAKE_BINARY_DIR}/jar) |
| 27 | |
| 28 | # use, i.e. don't skip the full RPATH for the build tree |
| 29 | SET(CMAKE_SKIP_BUILD_RPATH FALSE) |
| 30 | |
| 31 | # when building, don't use the install RPATH already |
| 32 | # (but later on when installing) |
| 33 | SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
| 34 | |
| 35 | SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib") |
| 36 | |
| 37 | # add the automatically determined parts of the RPATH |
| 38 | # which point to directories outside the build tree to the install RPATH |
| 39 | SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
| 40 | |
| 41 | # the RPATH to be used when installing, but only if it's not a system directory |
| 42 | LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/wpilib/lib" isSystemDir) |
| 43 | IF("${isSystemDir}" STREQUAL "-1") |
| 44 | SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib") |
| 45 | ENDIF("${isSystemDir}" STREQUAL "-1") |
| 46 | |
| 47 | option(WITHOUT_JAVA "don't include java and JNI in the build" OFF) |
| 48 | option(BUILD_SHARED_LIBS "build with shared libs (needed for JNI)" ON) |
| 49 | option(WITHOUT_CSCORE "Don't build cscore (removes OpenCV requirement)" OFF) |
| 50 | option(WITHOUT_ALLWPILIB "Don't build allwpilib (removes OpenCV requirement)" ON) |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 51 | option(WITH_TESTS "build unit tests (requires internet connection)" OFF) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 52 | option(USE_EXTERNAL_HAL "Use a separately built HAL" OFF) |
| 53 | set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File") |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 54 | option(USE_VCPKG_LIBUV "Use vcpkg libuv" OFF) |
| 55 | option(USE_VCPKG_EIGEN "Use vcpkg eigen" OFF) |
| 56 | option(FLAT_INSTALL_WPILIB "Use a flat install directory" OFF) |
| 57 | option(WITH_SIMULATION_MODULES "build simulation modules" OFF) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 58 | |
| 59 | if (NOT WITHOUT_JAVA AND NOT BUILD_SHARED_LIBS) |
| 60 | message(FATAL_ERROR " |
| 61 | FATAL: Cannot build static libs with Java enabled. |
| 62 | Static libs requires both BUILD_SHARED_LIBS=OFF and |
| 63 | WITHOUT_JAVA=ON |
| 64 | ") |
| 65 | endif() |
| 66 | |
| 67 | set( wpilib_dest wpilib) |
| 68 | set( include_dest wpilib/include ) |
| 69 | set( main_lib_dest wpilib/lib ) |
| 70 | set( java_lib_dest wpilib/java ) |
| 71 | set( jni_lib_dest wpilib/jni ) |
| 72 | |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 73 | if (MSVC OR FLAT_INSTALL_WPILIB) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 74 | set (wpilib_config_dir ${wpilib_dest}) |
| 75 | else() |
| 76 | set (wpilib_config_dir share/wpilib) |
| 77 | endif() |
| 78 | |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 79 | if (USE_VCPKG_LIBUV) |
| 80 | set (LIBUV_VCPKG_REPLACE "find_package(unofficial-libuv CONFIG)") |
| 81 | endif() |
| 82 | |
| 83 | if (USE_VCPKG_EIGEN) |
| 84 | set (EIGEN_VCPKG_REPLACE "find_package(Eigen3 CONFIG)") |
| 85 | endif() |
| 86 | |
| 87 | if (MSVC OR FLAT_INSTALL_WPILIB) |
| 88 | set(WPIUTIL_DEP_REPLACE "include($\{SELF_DIR\}/wpiutil-config.cmake)") |
| 89 | set(NTCORE_DEP_REPLACE "include($\{SELF_DIR\}/ntcore-config.cmake)") |
| 90 | set(CSCORE_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cscore-config.cmake)") |
| 91 | set(CAMERASERVER_DEP_REPLACE_IMPL "include(\${SELF_DIR}/cameraserver-config.cmake)") |
| 92 | set(HAL_DEP_REPLACE_IMPL "include(\${SELF_DIR}/hal-config.cmake)") |
| 93 | set(WPILIBC_DEP_REPLACE_IMPL "include(\${SELF_DIR}/wpilibc-config.cmake)") |
| 94 | else() |
| 95 | set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)") |
| 96 | set(NTCORE_DEP_REPLACE "find_dependency(ntcore)") |
| 97 | set(CSCORE_DEP_REPLACE_IMPL "find_dependency(cscore)") |
| 98 | set(CAMERASERVER_DEP_REPLACE_IMPL "find_dependency(cameraserver)") |
| 99 | set(HAL_DEP_REPLACE_IMPL "find_dependency(hal)") |
| 100 | set(WPILIBC_DEP_REPLACE_IMPL "find_dependency(wpilibc)") |
| 101 | endif() |
| 102 | |
| 103 | set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)") |
| 104 | set(SELF_DIR "$\{SELF_DIR\}") |
| 105 | |
| 106 | if (WITH_TESTS) |
| 107 | enable_testing() |
| 108 | add_subdirectory(googletest) |
| 109 | include(GoogleTest) |
| 110 | endif() |
| 111 | |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 112 | add_subdirectory(wpiutil) |
| 113 | add_subdirectory(ntcore) |
| 114 | |
| 115 | if (NOT WITHOUT_CSCORE) |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 116 | set(CSCORE_DEP_REPLACE ${CSCORE_DEP_REPLACE_IMPL}) |
| 117 | set(CAMERASERVER_DEP_REPLACE ${CAMERASERVER_DEP_REPLACE_IMPL}) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 118 | add_subdirectory(cscore) |
| 119 | add_subdirectory(cameraserver) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 120 | if (NOT WITHOUT_ALLWPILIB) |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 121 | set(HAL_DEP_REPLACE ${HAL_DEP_REPLACE_IMPL}) |
| 122 | set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL}) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 123 | add_subdirectory(hal) |
| 124 | add_subdirectory(wpilibj) |
| 125 | add_subdirectory(wpilibc) |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 126 | add_subdirectory(myRobot) |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 127 | endif() |
| 128 | endif() |
| 129 | |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 130 | if (WITH_SIMULATION_MODULES AND NOT USE_EXTERNAL_HAL) |
| 131 | add_subdirectory(imgui) |
| 132 | add_subdirectory(simulation) |
| 133 | endif() |
| 134 | |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 135 | configure_file(wpilib-config.cmake.in ${CMAKE_BINARY_DIR}/wpilib-config.cmake ) |
| 136 | install(FILES ${CMAKE_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir}) |