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) |
| 51 | option(USE_EXTERNAL_HAL "Use a separately built HAL" OFF) |
| 52 | set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File") |
| 53 | |
| 54 | if (NOT WITHOUT_JAVA AND NOT BUILD_SHARED_LIBS) |
| 55 | message(FATAL_ERROR " |
| 56 | FATAL: Cannot build static libs with Java enabled. |
| 57 | Static libs requires both BUILD_SHARED_LIBS=OFF and |
| 58 | WITHOUT_JAVA=ON |
| 59 | ") |
| 60 | endif() |
| 61 | |
| 62 | set( wpilib_dest wpilib) |
| 63 | set( include_dest wpilib/include ) |
| 64 | set( main_lib_dest wpilib/lib ) |
| 65 | set( java_lib_dest wpilib/java ) |
| 66 | set( jni_lib_dest wpilib/jni ) |
| 67 | |
| 68 | if (MSVC) |
| 69 | set (wpilib_config_dir ${wpilib_dest}) |
| 70 | else() |
| 71 | set (wpilib_config_dir share/wpilib) |
| 72 | endif() |
| 73 | |
| 74 | add_subdirectory(wpiutil) |
| 75 | add_subdirectory(ntcore) |
| 76 | |
| 77 | if (NOT WITHOUT_CSCORE) |
| 78 | add_subdirectory(cscore) |
| 79 | add_subdirectory(cameraserver) |
| 80 | set (CSCORE_DEP_REPLACE "find_dependency(cscore)") |
| 81 | set (CAMERASERVER_DEP_REPLACE "find_dependency(cameraserver)") |
| 82 | if (NOT WITHOUT_ALLWPILIB) |
| 83 | add_subdirectory(hal) |
| 84 | add_subdirectory(wpilibj) |
| 85 | add_subdirectory(wpilibc) |
| 86 | set (HAL_DEP_REPLACE "find_dependency(hal)") |
| 87 | set (WPILIBC_DEP_REPLACE "find_dependency(wpilibc)") |
| 88 | endif() |
| 89 | endif() |
| 90 | |
| 91 | configure_file(wpilib-config.cmake.in ${CMAKE_BINARY_DIR}/wpilib-config.cmake ) |
| 92 | install(FILES ${CMAKE_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir}) |