|
| 1 | +## |
| 2 | +## Top-level CMakeLists.txt to build and install the whole Orocos Toolchain |
| 3 | +## |
| 4 | + |
| 5 | +cmake_minimum_required(VERSION 2.8) |
| 6 | + |
| 7 | +# capture CMake arguments specified at the command-line |
| 8 | +# (taken from https://stackoverflow.com/a/48555098) |
| 9 | + |
| 10 | +# MUST be done before call to 'project' |
| 11 | +get_cmake_property(vars CACHE_VARIABLES) |
| 12 | +foreach(var ${vars}) |
| 13 | + if(NOT var MATCHES "^(CMAKE_INSTALL_PREFIX|CMAKE_BUILD_TYPE|GIT_BASE_URL|GIT_TAG|OROCOS_TARGET|BUILD_STATIC|ENABLE_CORBA|CORBA_IMPLEMENTATION)$") |
| 14 | + get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING) |
| 15 | + if("${currentHelpString}" MATCHES "No help, variable specified on the command line." OR "${currentHelpString}" STREQUAL "") |
| 16 | + #message("${var} = [${${var}}] -- ${currentHelpString}") # uncomment to see the variables being processed |
| 17 | + list(APPEND CL_ARGS "-D${var}=${${var}}") |
| 18 | + endif() |
| 19 | + endif() |
| 20 | +endforeach() |
| 21 | + |
| 22 | +project(orocos_toolchain) |
| 23 | + |
| 24 | +###################### |
| 25 | +# Build-time options # |
| 26 | +###################### |
| 27 | + |
| 28 | +# get absolute CMAKE_INSTALL_PREFIX |
| 29 | +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 30 | + set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install") |
| 31 | +endif() |
| 32 | +set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "Install path prefix, prepended onto install directories" FORCE) |
| 33 | +message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") |
| 34 | + |
| 35 | +# (copied from rtt/orocos-rtt.default.cmake) |
| 36 | + |
| 37 | +# |
| 38 | +# Sets the CMAKE_BUILD_TYPE to Release by default. This is not a normal |
| 39 | +# CMake flag which is not readable during configuration time. |
| 40 | +if (NOT CMAKE_BUILD_TYPE) |
| 41 | + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) |
| 42 | +endif() |
| 43 | + |
| 44 | +# |
| 45 | +# Set the target operating system. One of [lxrt gnulinux xenomai macosx win32] |
| 46 | +# You may leave this as-is or force a certain target by removing the if... logic. |
| 47 | +# |
| 48 | +set(DOC_STRING "The Operating System target. One of [gnulinux lxrt macosx win32 xenomai]") |
| 49 | +set(OROCOS_TARGET_ENV $ENV{OROCOS_TARGET}) # MUST use helper variable, otherwise not picked up !!! |
| 50 | +if( OROCOS_TARGET_ENV ) |
| 51 | + set(OROCOS_TARGET ${OROCOS_TARGET_ENV} CACHE STRING "${DOC_STRING}" FORCE) |
| 52 | + message(STATUS "Detected OROCOS_TARGET environment variable. Using: ${OROCOS_TARGET}") |
| 53 | +else() |
| 54 | + if(NOT DEFINED OROCOS_TARGET ) |
| 55 | + if(MSVC) |
| 56 | + set(OROCOS_TARGET win32 CACHE STRING "${DOC_STRING}") |
| 57 | + elseif(APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 58 | + set(OROCOS_TARGET macosx CACHE STRING "${DOC_STRING}") |
| 59 | + else() |
| 60 | + set(OROCOS_TARGET gnulinux CACHE STRING "${DOC_STRING}") |
| 61 | + endif() |
| 62 | + endif() |
| 63 | + message(STATUS "No OROCOS_TARGET environment variable set. Using: ${OROCOS_TARGET}") |
| 64 | +endif() |
| 65 | + |
| 66 | +# (copied from rtt/config/check_depend.cmake) |
| 67 | + |
| 68 | +# |
| 69 | +# Build static libraries? |
| 70 | +# |
| 71 | +option(BUILD_STATIC "Build Orocos RTT as a static library." OFF) |
| 72 | + |
| 73 | +# |
| 74 | +# CORBA |
| 75 | +# |
| 76 | +option(ENABLE_CORBA "Enable CORBA" OFF) |
| 77 | +if(NOT CORBA_IMPLEMENTATION) |
| 78 | + set(CORBA_IMPLEMENTATION "TAO" CACHE STRING "The implementation of CORBA to use (allowed values: TAO or OMNIORB )" ) |
| 79 | +else() |
| 80 | + set(CORBA_IMPLEMENTATION ${CORBA_IMPLEMENTATION} CACHE STRING "The implementation of CORBA to use (allowed values: TAO or OMNIORB )" ) |
| 81 | +endif() |
| 82 | + |
| 83 | +############# |
| 84 | +# Git magic # |
| 85 | +############# |
| 86 | + |
| 87 | +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") |
| 88 | + set(IS_GIT TRUE) |
| 89 | +else() |
| 90 | + set(IS_GIT FALSE) |
| 91 | +endif() |
| 92 | + |
| 93 | +set(GIT_BASE_URL "https://github.com/orocos-toolchain/") |
| 94 | +#set(GIT_TAG "" CACHE STRING "Git branch or tag to checkout in submodules. Default to current branch (update) or default branch (clone).") |
| 95 | + |
| 96 | +# Find current branch if this is a git tree and use it as a default. |
| 97 | +if(IS_GIT) |
| 98 | + execute_process( |
| 99 | + COMMAND git --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git symbolic-ref --short HEAD |
| 100 | + OUTPUT_VARIABLE CURRENT_GIT_BRANCH |
| 101 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 102 | + ERROR_QUIET |
| 103 | + ) |
| 104 | + if(CURRENT_GIT_BRANCH) |
| 105 | + message(STATUS "Current orocos_toolchain branch: ${CURRENT_GIT_BRANCH}") |
| 106 | + if(NOT DEFINED GIT_TAG) |
| 107 | + set(GIT_TAG ${CURRENT_GIT_BRANCH}) # not cached! |
| 108 | + endif() |
| 109 | + endif() |
| 110 | +endif() |
| 111 | +if(GIT_TAG) |
| 112 | + message(STATUS "Building branch or tag ${GIT_TAG} for all submodules.") |
| 113 | +endif() |
| 114 | + |
| 115 | +################################# |
| 116 | +# Build and install subprojects # |
| 117 | +################################# |
| 118 | + |
| 119 | +include(ExternalProject) |
| 120 | +function(build_external_project project) |
| 121 | + cmake_parse_arguments(ARG "" "" "CMAKE_ARGS" ${ARGN}) |
| 122 | + |
| 123 | + set(${project}_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${project}) |
| 124 | + set(${project}_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${project}) |
| 125 | + |
| 126 | + if(IS_GIT) |
| 127 | + # Use the submodules... |
| 128 | + set(DOWNLOAD_AND_UPDATE_OPTIONS |
| 129 | + DOWNLOAD_COMMAND |
| 130 | + cd "${CMAKE_CURRENT_SOURCE_DIR}" && test -e ${project}/.git || git submodule update --init ${project} |
| 131 | + ) |
| 132 | + |
| 133 | + # Specific branch/tag? |
| 134 | + if(GIT_TAG) |
| 135 | + list(APPEND DOWNLOAD_AND_UPDATE_OPTIONS |
| 136 | + UPDATE_COMMAND |
| 137 | + cd "${CMAKE_CURRENT_SOURCE_DIR}/${project}" && git checkout "${GIT_TAG}" |
| 138 | + ) |
| 139 | + endif() |
| 140 | + |
| 141 | + else() |
| 142 | + # Clone from remote repository... |
| 143 | + set(DOWNLOAD_AND_UPDATE_OPTIONS |
| 144 | + GIT_REPOSITORY "${GIT_BASE_URL}${project}.git" |
| 145 | + GIT_TAG "${GIT_TAG}" |
| 146 | + ) |
| 147 | + endif() |
| 148 | + |
| 149 | + # Set PKG_CONFIG_PATH to be used by subprojects |
| 150 | + set(PKG_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") |
| 151 | + |
| 152 | + ExternalProject_Add(${project} |
| 153 | + PREFIX ${project} |
| 154 | + TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmp" |
| 155 | + STAMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/stamp" |
| 156 | + DOWNLOAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${project}" |
| 157 | + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${project}" |
| 158 | + BINARY_DIR "${${project}_BINARY_DIR}" |
| 159 | + INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" |
| 160 | + |
| 161 | + ${DOWNLOAD_AND_UPDATE_OPTIONS} |
| 162 | + PATCH_COMMAND #nothing |
| 163 | + BUILD_ALWAYS ON |
| 164 | + |
| 165 | + CMAKE_COMMAND |
| 166 | + ${CMAKE_COMMAND} -E env "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" ${CMAKE_COMMAND} |
| 167 | + |
| 168 | + CMAKE_ARGS |
| 169 | + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} |
| 170 | + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} |
| 171 | + -DOROCOS_TARGET=${OROCOS_TARGET} |
| 172 | + ${ARG_CMAKE_ARGS} |
| 173 | + |
| 174 | + ${ARG_UNPARSED_ARGUMENTS} |
| 175 | + ) |
| 176 | +endfunction() |
| 177 | + |
| 178 | +build_external_project(log4cpp) |
| 179 | +build_external_project(rtt |
| 180 | + CMAKE_ARGS |
| 181 | + -DENABLE_CORBA=${ENABLE_CORBA} |
| 182 | + -DCORBA_IMPLEMENTATION=${CORBA_IMPLEMENTATION} |
| 183 | + -DBUILD_STATIC=${BUILD_STATIC} |
| 184 | +) |
| 185 | +build_external_project(ocl |
| 186 | + DEPENDS log4cpp rtt |
| 187 | +) |
| 188 | + |
| 189 | +build_external_project(utilrb) |
| 190 | +build_external_project(typelib |
| 191 | + DEPENDS utilrb |
| 192 | +) |
| 193 | +build_external_project(rtt_typelib |
| 194 | + DEPENDS typelib |
| 195 | +) |
| 196 | +build_external_project(orogen |
| 197 | + DEPENDS rtt rtt_typelib utilrb |
| 198 | +) |
| 199 | + |
| 200 | +####################################### |
| 201 | +# Build orocos_toolchain meta package # |
| 202 | +####################################### |
| 203 | + |
| 204 | +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/orocos_toolchain) |
| 205 | + add_subdirectory(orocos_toolchain) |
| 206 | +endif() |
| 207 | + |
0 commit comments