blob: e659add36480c1a8e321c33644ed14f0c21475f9 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -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
19if(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)
21endif()
22
23set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
24set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
25set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
26set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${CMAKE_BINARY_DIR}/jar)
27
28# use, i.e. don't skip the full RPATH for the build tree
29SET(CMAKE_SKIP_BUILD_RPATH FALSE)
30
31# when building, don't use the install RPATH already
32# (but later on when installing)
33SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
34
35SET(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
39SET(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
42LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/wpilib/lib" isSystemDir)
43IF("${isSystemDir}" STREQUAL "-1")
44 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/wpilib/lib")
45ENDIF("${isSystemDir}" STREQUAL "-1")
46
47option(WITHOUT_JAVA "don't include java and JNI in the build" OFF)
48option(BUILD_SHARED_LIBS "build with shared libs (needed for JNI)" ON)
49option(WITHOUT_CSCORE "Don't build cscore (removes OpenCV requirement)" OFF)
50option(WITHOUT_ALLWPILIB "Don't build allwpilib (removes OpenCV requirement)" ON)
51option(USE_EXTERNAL_HAL "Use a separately built HAL" OFF)
52set(EXTERNAL_HAL_FILE "" CACHE FILEPATH "Location to look for an external HAL CMake File")
53
54if (NOT WITHOUT_JAVA AND NOT BUILD_SHARED_LIBS)
55 message(FATAL_ERROR "
56FATAL: Cannot build static libs with Java enabled.
57 Static libs requires both BUILD_SHARED_LIBS=OFF and
58 WITHOUT_JAVA=ON
59")
60endif()
61
62set( wpilib_dest wpilib)
63set( include_dest wpilib/include )
64set( main_lib_dest wpilib/lib )
65set( java_lib_dest wpilib/java )
66set( jni_lib_dest wpilib/jni )
67
68if (MSVC)
69 set (wpilib_config_dir ${wpilib_dest})
70else()
71 set (wpilib_config_dir share/wpilib)
72endif()
73
74add_subdirectory(wpiutil)
75add_subdirectory(ntcore)
76
77if (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()
89endif()
90
91configure_file(wpilib-config.cmake.in ${CMAKE_BINARY_DIR}/wpilib-config.cmake )
92install(FILES ${CMAKE_BINARY_DIR}/wpilib-config.cmake DESTINATION ${wpilib_config_dir})