SuperBuild_Macro.cmake 3.75 KB
Newer Older
1 2 3 4 5
include(CMakeParseArguments)

# Macro SETUP_SYSTEM_LIBRARY : defines USE_SYSTEM_XXX option, initialize
# internal variables
macro(SETUP_SYSTEM_LIBRARY)
6
  cmake_parse_arguments(NEW_SYSLIB  "" "PROJECT;DEFAULT" "" ${ARGN})
7
  option(USE_SYSTEM_${NEW_SYSLIB_PROJECT}
8 9
    "  Use a system build of ${NEW_SYSLIB_PROJECT}."
    ${NEW_SYSLIB_DEFAULT}
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
    )
  set(SYSTEM_${NEW_SYSLIB_PROJECT}_CMAKE_CACHE)
endmacro(SETUP_SYSTEM_LIBRARY)

# Macro ADD_SYSTEM_LOCATION : define variables to specific system locations
macro(ADD_SYSTEM_LOCATION)
  cmake_parse_arguments(NEW_SYSLOC  "" "PROJECT" "VARIABLES" ${ARGN})
  foreach(var ${NEW_SYSLOC_VARIABLES})
    set(${var} "" CACHE FILEPATH "Set a custom system location")
    mark_as_advanced(${var})
    if(USE_SYSTEM_${NEW_SYSLOC_PROJECT})
      set_property(CACHE ${var} PROPERTY TYPE FILEPATH)
    else()
      set_property(CACHE ${var} PROPERTY TYPE INTERNAL)
    endif()
    # add variable to cache if not empty
    if(NOT ${var} STREQUAL "")
      # additional argument for CMake cache
      set(ITEM_FOR_CMAKE_CACHE "-D${var}:STRING=${${var}}")
      list(APPEND SYSTEM_${NEW_SYSLOC_PROJECT}_CMAKE_CACHE ${ITEM_FOR_CMAKE_CACHE})
    endif()
  endforeach(var)
endmacro(ADD_SYSTEM_LOCATION)
33 34 35

# Macro ADD_SYSTEM_PREFIX : defines a system prefix for the given project
#   - creates a cache variable SYSTEM_${PROJECT}_PREFIX
36 37
#   - if CMAKE_ALIAS is defined, it is used to add an entry in cache
#       -D${CMAKE_ALIAS}:PATH=${SYSTEM_${PROJECT}_PREFIX}
38
macro(ADD_SYSTEM_PREFIX)
39
  cmake_parse_arguments(NEW_SYSPREFIX  "" "PROJECT;CMAKE_ALIAS" "" ${ARGN})
40 41 42 43 44 45 46
  set(SYSTEM_${NEW_SYSPREFIX_PROJECT}_PREFIX "" CACHE PATH "Set a custom system prefix")
  mark_as_advanced(SYSTEM_${NEW_SYSPREFIX_PROJECT}_PREFIX)
  if(USE_SYSTEM_${NEW_SYSPREFIX_PROJECT})
    set_property(CACHE SYSTEM_${NEW_SYSPREFIX_PROJECT}_PREFIX PROPERTY TYPE PATH)
  else()
    set_property(CACHE SYSTEM_${NEW_SYSPREFIX_PROJECT}_PREFIX PROPERTY TYPE INTERNAL)
  endif()
47 48 49 50 51 52 53
  if(NOT ${NEW_SYSPREFIX_CMAKE_ALIAS} STREQUAL "")
    if(NOT SYSTEM_${NEW_SYSPREFIX_PROJECT}_PREFIX STREQUAL "")
      set(ITEM_FOR_CMAKE_CACHE
        "-D${NEW_SYSPREFIX_CMAKE_ALIAS}:PATH=${SYSTEM_${NEW_SYSPREFIX_PROJECT}_PREFIX}")
      list(APPEND SYSTEM_${NEW_SYSLOC_PROJECT}_CMAKE_CACHE ${ITEM_FOR_CMAKE_CACHE})
    endif()
  endif()
54
endmacro(ADD_SYSTEM_PREFIX)
55 56 57 58 59 60 61 62 63

# Macro SETUP_SUPERBUILD
# Initialize usefull variables to build a superbuild project
macro(SETUP_SUPERBUILD)
  cmake_parse_arguments(NEW_SB "" "PROJECT" "" ${ARGN})
  set(${NEW_SB_PROJECT}_DEPENDENCIES)
  set(${NEW_SB_PROJECT}_SB_BUILD_DIR ${CMAKE_BINARY_DIR}/${NEW_SB_PROJECT}/build)
  set(${NEW_SB_PROJECT}_SB_SRC ${CMAKE_BINARY_DIR}/${NEW_SB_PROJECT}/src/${NEW_SB_PROJECT})
  set(${NEW_SB_PROJECT}_SB_CONFIG)
64
  set(_SB_${NEW_SB_PROJECT}_ROOT ${SB_INSTALL_PREFIX})
65
endmacro(SETUP_SUPERBUILD)
66 67 68 69 70 71 72 73 74

# Macro to include dependencies
macro(INCLUDE_SUPERBUILD_DEPENDENCIES)
  foreach(dep ${ARGV})
    string(TOLOWER ${dep} dep_lower)
    include(External_${dep_lower})
  endforeach()
endmacro(INCLUDE_SUPERBUILD_DEPENDENCIES)

75 76
# Macro to add a cmake variable to ${proj}_SB_CONFIG (var type: string)
macro(ADD_SUPERBUILD_CMAKE_VAR var)
77 78 79 80 81
  if(DEFINED _SB_${var})
    list(APPEND ${proj}_SB_CONFIG
      -D${var}:STRING=${_SB_${var}}
      )
  elseif(DEFINED ${var})
82 83 84 85
    list(APPEND ${proj}_SB_CONFIG
      -D${var}:STRING=${${var}}
      )
  endif()
86
endmacro(ADD_SUPERBUILD_CMAKE_VAR)
87

88
# Macro to add a configure variable to ${proj}_SB_CONFIG
89
# optional 3rd argument : suffix to the variable
90
macro(ADD_SUPERBUILD_CONFIGURE_VAR var name)
91
  set(suffix "${ARGV2}")
92 93
  if(DEFINED _SB_${var})
    list(APPEND ${proj}_SB_CONFIG
94
      ${name}=${_SB_${var}}${suffix}
95 96
      )
  elseif(DEFINED ${var})
97
    list(APPEND ${proj}_SB_CONFIG
98
      ${name}=${${var}}${suffix}
99 100 101
      )
  endif()
endmacro(ADD_SUPERBUILD_CONFIGURE_VAR)