summaryrefslogtreecommitdiff
path: root/cmake/deps-helper.cmake
diff options
context:
space:
mode:
authorGereon Kremer <gereon.kremer@cs.rwth-aachen.de>2021-03-27 10:41:49 +0100
committerGitHub <noreply@github.com>2021-03-27 09:41:49 +0000
commit4b7e392eca42f89d103c5eb74157a44d4b40fe4b (patch)
tree649e24b292ac6b6dba11fe4a0e5df69ab4406019 /cmake/deps-helper.cmake
parent1ac0ebabb80f68c6c666d1eae1588c0950a6f2f7 (diff)
Refactor ANTLR3 dependency (#6202)
This PR refactors our first, and arguably most fragile, dependency. Right now all dependencies need to be manually installed (by calling the appropriate contrib/get-X script). For optional dependencies, we additionally need to enable them when calling the configure script (or via ccmake). This PR is the first step in refactoring all dependencies to be automatically build (if required) as an external project. Note that this not only eliminates the need to call contrib scripts, but also simplifies cross compilation: as all dependencies are now built within the build folders, every build folder has its own copy which may use different toolchains.
Diffstat (limited to 'cmake/deps-helper.cmake')
-rw-r--r--cmake/deps-helper.cmake50
1 files changed, 50 insertions, 0 deletions
diff --git a/cmake/deps-helper.cmake b/cmake/deps-helper.cmake
new file mode 100644
index 000000000..bdc3e5de1
--- /dev/null
+++ b/cmake/deps-helper.cmake
@@ -0,0 +1,50 @@
+# where to build dependencies
+set(DEPS_PREFIX "${CMAKE_BINARY_DIR}/deps")
+# base path to installed dependencies
+set(DEPS_BASE "${CMAKE_BINARY_DIR}/deps")
+# CMake wants directories specified via INTERFACE_INCLUDE_DIRECTORIES
+# (and similar) to exist when target property is set.
+file(MAKE_DIRECTORY "${DEPS_BASE}/include/")
+
+macro(check_system_version name)
+ # find_package sets this variable when called with a version
+ # https://cmake.org/cmake/help/latest/command/find_package.html#version-selection
+ # we ignore the EXACT option and version ranges here
+ if (${name}_FIND_VERSION)
+ if(${name}_VERSION VERSION_LESS ${name}_FIND_VERSION)
+ message(VERBOSE "System version for ${name} has incompatible \
+version: required ${${name}_FIND_VERSION} but found ${${name}_VERSION}")
+ set(${name}_FOUND_SYSTEM FALSE)
+ endif()
+ endif()
+endmacro(check_system_version)
+
+# fail if we are cross compiling as indicated by name and processor
+# we are cross compiling if
+# - CMAKE_SYSTEM_NAME has been changed to ${name}
+# - CMAKE_SYSTEM_PROCESSOR has been changed to ${processor}
+function(fail_if_cross_compiling name processor target error)
+ set(FAIL FALSE)
+ if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
+ if(NOT "${name}" STREQUAL "")
+ if("${CMAKE_SYSTEM_NAME}" STREQUAL "${name}")
+ set(FAIL TRUE)
+ endif()
+ endif()
+ endif()
+ if(NOT "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}")
+ if(NOT "${processor}" STREQUAL "")
+ if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "${processor}")
+ set(FAIL TRUE)
+ endif()
+ endif()
+ endif()
+ if(FAIL)
+ message(SEND_ERROR
+ "We are cross compiling from \
+${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR} to \
+${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}.\n"
+ "This is not supported by ${target}:\n"
+ "${error}")
+ endif()
+endfunction(fail_if_cross_compiling)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback