Commit b6521c67 authored by Alexis Girault's avatar Alexis Girault

WIP: Superbuild Cmake Architecture + g3log

parent 7714bb2d
set( CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH} )
include(ExternalProject)
#-----------------------------------------------------------------------------
# Git protocol option
#-----------------------------------------------------------------------------
if(NOT GIT_EXECUTABLE)
find_package(Git REQUIRED)
endif()
option(${PROJECT_NAME}_USE_GIT_PROTOCOL "If behind a firewall turn this OFF to use http instead." ON)
set(git_protocol "git")
if(NOT ${PROJECT_NAME}_USE_GIT_PROTOCOL)
set(git_protocol "http")
endif()
#-----------------------------------------------------------------------------
# CMake global args
#-----------------------------------------------------------------------------
list(APPEND CMAKE_CONFIG_ARGS
-Wno-dev
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}
-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}
-DCMAKE_INCLUDE_PATH:STRING=${${PROJECT_NAME}_CMAKE_INCLUDE_PATH}
-DCMAKE_LIBRARY_PATH:STRING=${${PROJECT_NAME}_CMAKE_LIBRARY_PATH}
)
#-----------------------------------------------------------------------------
# CMake args if Apple
#-----------------------------------------------------------------------------
if(APPLE)
list(APPEND CMAKE_CONFIG_OSX_ARGS
-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
-DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT}
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
-DCMAKE_MACOSX_RPATH:BOOL=ON
)
endif()
#-----------------------------------------------------------------------------
# Solve dependencies
#-----------------------------------------------------------------------------
include(imstkSolveDependencies)
set(EXTERNAL_PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
ExternalProject_Include_Dependencies( ${PROJECT_NAME}
DEPENDS_VAR ${PROJECT_NAME}_DEPENDENCIES
SUPERBUILD_VAR ${PROJECT_NAME}_SUPERBUILD
)
#-----------------------------------------------------------------------------
# Inner build of the main project
#-----------------------------------------------------------------------------
ExternalProject_Add( ${PROJECT_NAME}
DOWNLOAD_COMMAND ""
INSTALL_COMMAND ""
DOWNLOAD_DIR ${${PROJECT_NAME}_SOURCE_DIR}
SOURCE_DIR ${${PROJECT_NAME}_SOURCE_DIR}
BINARY_DIR ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-${CMAKE_BUILD_TYPE}
CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_ARGS
-D${PROJECT_NAME}_SUPERBUILD:BOOL=OFF
# -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
# -DBUILD_DOCUMENTATION:BOOL=${BUILD_DOCUMENTATION}
# -DBUILD_EXAMPLES:BOOL=${BUILD_EXAMPLES}
# -DBUILD_TESTING:BOOL=${BUILD_TESTING}
${CMAKE_CONFIG_ARGS}
${CMAKE_CONFIG_OSX_ARGS}
${${PROJECT_NAME}_EXTERNAL_PROJECTS_PATHS}
DEPENDS ${${PROJECT_NAME}_DEPENDENCIES}
)
set(proj Uncrustify)
string(TOUPPER "${proj}" PROJ)
set(extProj Uncrustify)
set(${extProj}_DEPENDENCIES "")
set(${extProj}_REPOSITORY ${git_protocol}://github.com/uncrustify/uncrustify.git)
set(${extProj}_GIT_TAG uncrustify-0.62)
#-----------------------------------------------------------------------------
# Make sure this file is included only once
# Sanity checks
#-----------------------------------------------------------------------------
get_filename_component(CMAKE_CURRENT_LIST_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME_WE)
if(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED)
return()
if(DEFINED ${extProj}_EXECUTABLE AND NOT EXISTS ${${extProj}_EXECUTABLE})
message(FATAL_ERROR
"${extProj}_EXECUTABLE variable is defined but corresponds to non-existing executable")
endif()
set(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED 1)
#-----------------------------------------------------------------------------
# Sanity checks
# Solve dependencies
#-----------------------------------------------------------------------------
if(DEFINED ${PROJ}_EXECUTABLE AND NOT EXISTS ${${PROJ}_EXECUTABLE})
message(FATAL_ERROR "${PROJ}_EXECUTABLE variable is defined but corresponds to non-existing file")
endif()
ExternalProject_Include_Dependencies( ${extProj}
PROJECT_VAR extProj
DEPENDS_VAR ${extProj}_DEPENDENCIES
USE_SYSTEM_VAR USE_SYSTEM_${extProj}
SUPERBUILD_VAR ${PROJECT_NAME}_SUPERBUILD
)
#-----------------------------------------------------------------------------
# Set dependency list
# Set extProject directory
#-----------------------------------------------------------------------------
set(${proj}_DEPENDENCIES "")
set(${extProj}_SOURCE_DIR ${CMAKE_BINARY_DIR}/External/${extProj}/src)
set(${extProj}_PREFIX_DIR ${CMAKE_BINARY_DIR}/External/${extProj}/prefix)
set(${extProj}_DIR ${CMAKE_BINARY_DIR}/External/${extProj}/build)
#-----------------------------------------------------------------------------
# If needs to download and build
#-----------------------------------------------------------------------------
if(NOT DEFINED ${PROJ}_EXECUTABLE AND NOT ${USE_SYSTEM_${PROJ}})
if(NOT DEFINED ${extProj}_EXECUTABLE AND NOT ${USE_SYSTEM_${extProj}})
#-----------------------------------------------------------------------------
# Set project Git info
#-----------------------------------------------------------------------------
set(${proj}_REPOSITORY ${git_protocol}://github.com/uncrustify/uncrustify.git)
set(${proj}_GIT_TAG uncrustify-0.62)
#-----------------------------------------------------------------------------
# Set project directory
#-----------------------------------------------------------------------------
set(${proj}_SOURCE_DIR ${CMAKE_BINARY_DIR}/Superbuild/${proj}-src)
set(${proj}_PREFIX_DIR ${CMAKE_BINARY_DIR}/Superbuild/${proj}-prefix)
set(${proj}_DIR ${CMAKE_BINARY_DIR}/Superbuild/${proj}-build)
set(${extProj}_EXECUTABLE ${${extProj}_DIR}/src/uncrustify)
#-----------------------------------------------------------------------------
# Add project
# Add extProject
#-----------------------------------------------------------------------------
include(ExternalProject)
ExternalProject_add(${proj}
GIT_REPOSITORY ${${proj}_REPOSITORY}
GIT_TAG ${${proj}_GIT_TAG}
ExternalProject_add(${extProj}
GIT_REPOSITORY ${${extProj}_REPOSITORY}
GIT_TAG ${${extProj}_GIT_TAG}
SOURCE_DIR ${${extProj}_SOURCE_DIR}
BINARY_DIR ${${extProj}_DIR}
PREFIX ${${extProj}_PREFIX_DIR}
UPDATE_COMMAND ""
PREFIX ${${proj}_PREFIX_DIR}
SOURCE_DIR ${${proj}_SOURCE_DIR}
BINARY_DIR ${${proj}_DIR}
INSTALL_COMMAND ""
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<BINARY_DIR> #TODO: does not work on Windows, see --host= option
DEPENDS ${${proj}_DEPENDENCIES}
DEPENDS ${${extProj}_DEPENDENCIES}
)
set(${PROJ}_EXECUTABLE ${${proj}_DIR}/bin/uncrustify)
#-----------------------------------------------------------------------------
# If using system
#-----------------------------------------------------------------------------
else()
if(${USE_SYSTEM_${PROJ}})
find_program(${PROJ}_EXECUTABLE ${proj} DOC "Path of ${proj} program")
if(NOT ${PROJ}_EXECUTABLE)
message(FATAL_ERROR "To use the system ${proj}, set ${PROJ}_EXECUTABLE")
endif()
elseif(${USE_SYSTEM_${extProj}})
find_program(${extProj}_EXECUTABLE ${extProj} DOC "Path of ${extProj} program")
if(NOT ${extProj}_EXECUTABLE)
message(FATAL_ERROR "To use the system ${extProj}, set ${extProj}_EXECUTABLE")
endif()
#-----------------------------------------------------------------------------
# Add empty project (to solve dependencies)
#-----------------------------------------------------------------------------
ExternalProject_Add(${project_name}
SOURCE_DIR ${${extProj}_SOURCE_DIR}
BINARY_DIR ${${extProj}_DIR}
PREFIX ${${extProj}_PREFIX_DIR}
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
DEPENDS ${${extProj}_DEPENDENCIES}
)
endif()
set(TEST true)
#-----------------------------------------------------------------------------
# Keep track of project path to add it in the superbuild cache
#-----------------------------------------------------------------------------
list( APPEND ${PROJECT_NAME}_EXTERNAL_PROJECTS_PATHS -D${extProj}_EXECUTABLE:PATH=${${extProj}_EXECUTABLE} )
#-----------------------------------------------------------------------------
# Add External Project
#-----------------------------------------------------------------------------
include(imstkAddExternalProject)
imstk_add_external_project( g3log
REPOSITORY ${git_protocol}://github.com/KjellKod/g3log.git
GIT_TAG 579579962c94213a46fadbb70a996f08c19be3a2
#DEPENDENCIES ""
#VERBOSE
)
#-----------------------------------------------------------------------------
# Find path
#-----------------------------------------------------------------------------
find_path(g3log_INCLUDE_DIR
NAMES
g3log/g3log.hpp
g3log/logworker.hpp
)
mark_as_advanced(g3log_INCLUDE_DIR)
#-----------------------------------------------------------------------------
# Find library
#-----------------------------------------------------------------------------
find_library(g3log_LIBRARY
NAMES
g3logger_shared)
mark_as_advanced(g3log_LIBRARY)
#-----------------------------------------------------------------------------
# Find package
#-----------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(g3log
REQUIRED_VARS
g3log_INCLUDE_DIR
g3log_LIBRARY)
#-----------------------------------------------------------------------------
# If missing target, create it
#-----------------------------------------------------------------------------
if(G3LOG_FOUND AND NOT TARGET g3log::g3log)
add_library(g3log::g3log INTERFACE IMPORTED)
set_target_properties(g3log::g3log PROPERTIES
INTERFACE_LINK_LIBRARIES "${g3log_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${g3log_INCLUDE_DIR}")
endif()
#-----------------------------------------------------------------------------
# Define configuration files
#-----------------------------------------------------------------------------
set(UNCRUSTIFY_CONFIG "${CMAKE_SOURCE_DIR}/Utilities/Uncrustify/${PROJECT_NAME}Uncrustify.cfg")
set(Uncrustify_CONFIG "${CMAKE_SOURCE_DIR}/Utilities/Uncrustify/${PROJECT_NAME}Uncrustify.cfg")
#-----------------------------------------------------------------------------
# Setup git hook for Uncrustify executable path
#-----------------------------------------------------------------------------
find_package(Git)
if(GIT_FOUND)
if(EXISTS "${UNCRUSTIFY_EXECUTABLE}" AND EXISTS "${UNCRUSTIFY_CONFIG}")
if(EXISTS "${Uncrustify_EXECUTABLE}" AND EXISTS "${Uncrustify_CONFIG}")
message(STATUS "Uncrustify found: enabling in git hook")
execute_process(COMMAND ${GIT_EXECUTABLE} config uncrustify.path "${UNCRUSTIFY_EXECUTABLE}"
execute_process(COMMAND ${GIT_EXECUTABLE} config uncrustify.path "${Uncrustify_EXECUTABLE}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(COMMAND ${GIT_EXECUTABLE} config uncrustify.conf "${UNCRUSTIFY_CONFIG}"
execute_process(COMMAND ${GIT_EXECUTABLE} config uncrustify.conf "${Uncrustify_CONFIG}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process( COMMAND ${GIT_EXECUTABLE} config uncrustify.enabled true
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
else()
if(NOT EXISTS "${UNCRUSTIFY_EXECUTABLE}")
if(NOT EXISTS "${Uncrustify_EXECUTABLE}")
message(STATUS "Uncrustify executable not found: disabling in git hook")
execute_process(COMMAND ${GIT_EXECUTABLE} config --unset uncrustify.path
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
if(NOT EXISTS "${UNCRUSTIFY_CONFIG}")
if(NOT EXISTS "${Uncrustify_CONFIG}")
message(STATUS "Uncrustify config file not found: disabling in git hook")
execute_process(COMMAND ${GIT_EXECUTABLE} config --unset uncrustify.conf
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
......
macro(imstk_add_external_project extProj)
set(options VERBOSE)
set(oneValueArgs REPOSITORY GIT_TAG)
set(multiValueArgs DEPENDENCIES)
include(CMakeParseArguments)
cmake_parse_arguments(${extProj} "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
#-----------------------------------------------------------------------------
# Verbose (display arguments)
#-----------------------------------------------------------------------------
if(${extProj}_VERBOSE)
foreach(opt ${options} ${oneValueArgs} ${multiValueArgs})
message(STATUS "${extProj}_${opt}:${${extProj}_${opt}}")
endforeach()
endif()
#-----------------------------------------------------------------------------
# Sanity checks
#-----------------------------------------------------------------------------
if(DEFINED ${extProj}_DIR AND NOT EXISTS ${${extProj}_DIR})
message(FATAL_ERROR
"${extProj}_DIR variable is defined but corresponds to non-existing directory")
endif()
#-----------------------------------------------------------------------------
# Solve dependencies
#-----------------------------------------------------------------------------
set(PROJECT_VAR_TEMP ${extProj})
ExternalProject_Include_Dependencies( ${extProj}
PROJECT_VAR PROJECT_VAR_TEMP
DEPENDS_VAR ${extProj}_DEPENDENCIES
USE_SYSTEM_VAR USE_SYSTEM_${extProj}
SUPERBUILD_VAR ${PROJECT_NAME}_SUPERBUILD
)
#-----------------------------------------------------------------------------
# If needs to download and build
#-----------------------------------------------------------------------------
if(NOT DEFINED ${extProj}_DIR AND NOT ${USE_SYSTEM_${extProj}})
#-----------------------------------------------------------------------------
# Set project directory
#-----------------------------------------------------------------------------
set(${extProj}_SOURCE_DIR ${CMAKE_BINARY_DIR}/External/${extProj}/src)
set(${extProj}_PREFIX_DIR ${CMAKE_BINARY_DIR}/External/${extProj}/prefix)
set(${extProj}_DIR ${CMAKE_BINARY_DIR}/External/${extProj}/build-${CMAKE_BUILD_TYPE})
#-----------------------------------------------------------------------------
# Add project
#-----------------------------------------------------------------------------
ExternalProject_add( ${extProj}
SOURCE_DIR ${${extProj}_SOURCE_DIR}
BINARY_DIR ${${extProj}_DIR}
PREFIX ${${extProj}_PREFIX_DIR}
GIT_REPOSITORY ${${extProj}_REPOSITORY}
GIT_TAG ${${extProj}_GIT_TAG}
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_ARGS
${CMAKE_CONFIG_ARGS}
${CMAKE_CONFIG_OSX_ARGS}
#-DBUILD_SHARED_LIBS:BOOL=${shared}
#-DBUILD_EXAMPLES:BOOL=OFF
#-DBUILD_TESTING:BOOL=OFF
DEPENDS ${${extProj}_DEPENDENCIES}
)
#-----------------------------------------------------------------------------
# If project already built on system
#-----------------------------------------------------------------------------
else()
if( ${USE_SYSTEM_${extProj}} )
find_package( ${extProj} REQUIRED )
endif()
#-----------------------------------------------------------------------------
# Add empty project (to solve dependencies)
#-----------------------------------------------------------------------------
ExternalProject_Add(${project_name}
SOURCE_DIR ${${extProj}_SOURCE_DIR}
BINARY_DIR ${${extProj}_DIR}
PREFIX ${${extProj}_PREFIX_DIR}
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
DEPENDS ${${extProj}_DEPENDENCIES}
)
endif()
#-----------------------------------------------------------------------------
# Keep track of project path to add it in the superbuild cache
#-----------------------------------------------------------------------------
list( APPEND ${PROJECT_NAME}_EXTERNAL_PROJECTS_PATHS -D${extProj}_DIR:PATH=${${extProj}_DIR} )
endmacro()
......@@ -3,6 +3,7 @@ function(imstk_add_library target)
set(options VERBOSE)
set(oneValueArgs)
set(multiValueArgs H_FILES CPP_FILES LIBRARIES)
include(CMakeParseArguments)
cmake_parse_arguments(target "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
message(STATUS "Configuring ${target}")
......@@ -15,7 +16,7 @@ function(imstk_add_library target)
message(STATUS "${opt}:${target_${opt}}")
endforeach()
endif()
#-----------------------------------------------------------------------------
# Create target (library)
#-----------------------------------------------------------------------------
......@@ -23,14 +24,14 @@ function(imstk_add_library target)
${target_H_FILES}
${target_CPP_FILES}
)
#-----------------------------------------------------------------------------
# Link libraries to current target
#-----------------------------------------------------------------------------
target_link_libraries( ${target}
${target_LIBRARIES}
)
#-----------------------------------------------------------------------------
# Include directories
#-----------------------------------------------------------------------------
......@@ -58,4 +59,3 @@ function(imstk_add_library target)
)
endfunction()
##############################################################################
#
# Library: TubeTK
#
# Copyright 2010 Kitware Inc. 28 Corporate Drive,
# Clifton Park, NY, 12065, USA.
#
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#.rst:
# ExternalProjectDependency
# -------------------------
###########################################################################
#
# Library: CTK
#
# Copyright (c) Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 3P41RR013218-12S1
#
###########################################################################
include(CMakeParseArguments)
if(NOT DEFINED EP_LIST_SEPARATOR)
set(EP_LIST_SEPARATOR "^^")
endif()
#.rst:
# .. cmake:variable:: EXTERNAL_PROJECT_DIR
#
if(NOT EXISTS "${EXTERNAL_PROJECT_DIR}")
set(EXTERNAL_PROJECT_DIR ${CMAKE_SOURCE_DIR}/SuperBuild)
endif()
#.rst:
# .. cmake:variable:: EXTERNAL_PROJECT_FILE_PREFIX
#
if(NOT DEFINED EXTERNAL_PROJECT_FILE_PREFIX)
set(EXTERNAL_PROJECT_FILE_PREFIX "External_")
endif()
# Compute -G arg for configuring external projects with the same CMake generator:
if(CMAKE_EXTRA_GENERATOR)
set(EP_CMAKE_GENERATOR "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
else()
set(EP_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
endif()
#.rst:
# .. cmake:function:: mark_as_superbuild
#
# .. code-block:: cmake
#
# mark_as_superbuild(<varname1>[:<vartype1>] [<varname2>[:<vartype2>] [...]])
#
# .. code-block:: cmake
#
# mark_as_superbuild(
# VARS <varname1>[:<vartype1>] [<varname2>[:<vartype2>] [...]]
# [PROJECTS <projectname> [<projectname> [...]] | ALL_PROJECTS]
# [LABELS <label1> [<label2> [...]]]
# )
#
# .. code-block:: cmake
#
# PROJECTS corresponds to a list of <projectname> that will be added using 'ExternalProject_Add' function.
# If not specified and called within a project file, it defaults to the value of 'SUPERBUILD_TOPLEVEL_PROJECT'
# Otherwise, it defaults to 'CMAKE_PROJECT_NAME'.
# If instead 'ALL_PROJECTS' is specified, the variables and labels will be passed to all projects.
#
# VARS is an expected list of variables specified as <varname>:<vartype> to pass to <projectname>
#
#
# LABELS is an optional list of label to associate with the variable names specified using 'VARS' and passed to
# the <projectname> as CMake CACHE args of the form:
# -D<projectname>_EP_LABEL_<label1>=<varname1>;<varname2>[...]
# -D<projectname>_EP_LABEL_<label2>=<varname1>;<varname2>[...]
#
function(mark_as_superbuild)
set(options ALL_PROJECTS CMAKE_CMD)
set(oneValueArgs)
set(multiValueArgs VARS PROJECTS LABELS)
cmake_parse_arguments(_sb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(_vars ${_sb_UNPARSED_ARGUMENTS})
set(_named_parameters_expected 0)
if(_sb_PROJECTS OR _sb_ALL_PROJECTS OR _sb_LABELS OR _sb_VARS)
set(_named_parameters_expected 1)
set(_vars ${_sb_VARS})
endif()
if(_named_parameters_expected AND _sb_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Arguments '${_sb_UNPARSED_ARGUMENTS}' should be associated with VARS parameter !")
endif()
if(_sb_PROJECTS AND _sb_ALL_PROJECTS)
message(FATAL_ERROR "Arguments 'PROJECTS' and 'ALL_PROJECTS' are mutually exclusive !")
endif()
foreach(var ${_vars})
set(_type_specified 0)
if(var MATCHES ":")
set(_type_specified 1)
endif()
# XXX Display warning with variable type is also specified for cache variable.
set(_var ${var})
if(NOT _type_specified)
get_property(_type_set_in_cache CACHE ${_var} PROPERTY TYPE SET)
set(_var_name ${_var})
set(_var_type "STRING")
if(_type_set_in_cache)
get_property(_var_type CACHE ${_var_name} PROPERTY TYPE)
endif()
set(_var ${_var_name}:${_var_type})
endif()
list(APPEND _vars_with_type ${_var})
endforeach()
if(_sb_ALL_PROJECTS)
set(optional_arg_ALL_PROJECTS "ALL_PROJECTS")
else()
set(optional_arg_ALL_PROJECTS PROJECTS ${_sb_PROJECTS})
endif()
_sb_append_to_cmake_args(
VARS ${_vars_with_type} LABELS ${_sb_LABELS} ${optional_arg_ALL_PROJECTS})
endfunction()
#
# _sb_extract_varname_and_vartype(<cmake_varname_and_type> <varname_var> [<vartype_var>])
#
# <cmake_varname_and_type> corresponds to variable name and variable type passed as "<varname>:<vartype>"
#
# <varname_var> will be set to "<varname>"
#
# <vartype_var> is an optional variable name that will be set to "<vartype>"
#
function(_sb_extract_varname_and_vartype cmake_varname_and_type varname_var)
set(_vartype_var "${ARGV2}")
string(REPLACE ":" ";" varname_and_vartype ${cmake_varname_and_type})
list(GET varname_and_vartype 0 _varname)
list(GET varname_and_vartype 1 _vartype)
set(${varname_var} ${_varname} PARENT_SCOPE)
if(_vartype_var MATCHES ".+")
set(${_vartype_var} ${_vartype} PARENT_SCOPE)
endif()
endfunction()
function(_sb_list_to_string separator input_list output_string_var)
set(_string "")
# Get list length
list(LENGTH input_list list_length)
# If the list has 0 or 1 element, there is no need to loop over.
if(list_length LESS 2)
set(_string "${input_list}")
else()
math(EXPR last_element_index "${list_length} - 1")
foreach(index RANGE ${last_element_index})
# Get current item_value
list(GET input_list ${index} item_value)
if(NOT item_value STREQUAL "")
# .. and append non-empty value to output string
set(_string "${_string}${item_value}")
# Append separator if current element is NOT the last one.
if(NOT index EQUAL last_element_index)
set(_string "${_string}${separator}")
endif()
endif()
endforeach()
endif()
set(${output_string_var} ${_string} PARENT_SCOPE)
endfunction()
#
# _sb_cmakevar_to_cmakearg(<cmake_varname_and_type> <cmake_arg_var> <has_cfg_intdir_var> [<varname_var> [<vartype_var>]])
#
# <cmake_varname_and_type> corresponds to variable name and variable type passed as "<varname>:<vartype>"
#
# <cmake_arg_var> is a variable name that will be set to "-D<varname>:<vartype>=${<varname>}"
#
# <has_int_dir_var> is set to either TRUE or FALSE.
# FALSE means that the value does NOT reference ${CMAKE_CFG_INTDIR} and
# the generated cmake argument should be passed to ExternalProject_Add as CMAKE_CACHE_ARGS.
# TRUEmeans that the value does reference ${CMAKE_CFG_INTDIR} and
# the generated cmake argument should be passed to ExternalProject_Add as CMAKE_ARGS.
#
# <varname_var> is an optional variable name that will be set to "<varname>"
#
# <vartype_var> is an optional variable name that will be set to "<vartype>"
#
function(_sb_cmakevar_to_cmakearg cmake_varname_and_type cmake_arg_var has_cfg_intdir_var)
set(_varname_var "${ARGV3}")
set(_vartype_var "${ARGV4}")
_sb_extract_varname_and_vartype(${cmake_varname_and_type} _varname _vartype)
set(_var_value "${${_varname}}")
get_property(_value_set_in_cache CACHE ${_varname} PROPERTY VALUE SET)
if(_value_set_in_cache)
get_property(_var_value CACHE ${_varname} PROPERTY VALUE)
endif()
set(_has_cfg_intdir FALSE)
if(CMAKE_CONFIGURATION_TYPES)
string(FIND "${_var_value}" ${CMAKE_CFG_INTDIR} _index)
if(NOT _index EQUAL -1)
# Separate list item with <EP_LIST_SEPARATOR>
_sb_list_to_string(${EP_LIST_SEPARATOR} "${_var_value}" _var_value)
set(_has_cfg_intdir TRUE)
endif()
endif()
set(${cmake_arg_var} -D${_varname}:${_vartype}=${_var_value} PARENT_SCOPE)
set(${has_cfg_intdir_var} ${_has_cfg_intdir} PARENT_SCOPE)
if(_varname_var MATCHES ".+")
set(${_varname_var} ${_varname} PARENT_SCOPE)
endif()
if(_vartype_var MATCHES ".+")
set(${_vartype_var} ${_vartype} PARENT_SCOPE)
endif()
endfunction()
set(_ALL_PROJECT_IDENTIFIER "ALLALLALL")
#
# _sb_append_to_cmake_args(
# VARS <varname1>:<vartype1> [<varname2>:<vartype2> [...]]
# [PROJECTS <projectname> [<projectname> [...]] | ALL_PROJECTS]
# [LABELS <label1> [<label2> [...]]]
# )
#
# PROJECTS corresponds to a list of <projectname> that will be added using 'ExternalProject_Add' function.
# If not specified and called within a project file, it defaults to the value of 'SUPERBUILD_TOPLEVEL_PROJECT'
# Otherwise, it defaults to 'CMAKE_PROJECT_NAME'.
# If instead 'ALL_PROJECTS' is specified, the variables and labels will be passed to all projects.
#
# VARS is an expected list of variables specified as <varname>:<vartype> to pass to <projectname>
#
#
# LABELS is an optional list of label to associate with the variable names specified using 'VARS' and passed to
# the <projectname> as CMake CACHE args of the form:
# -D<projectname>_EP_LABEL_<label1>=<varname1>;<varname2>[...]
# -D<projectname>_EP_LABEL_<label2>=<varname1>;<varname2>[...]
#
function(_sb_append_to_cmake_args)
set(options ALL_PROJECTS)
set(oneValueArgs)
set(multiValueArgs VARS PROJECTS LABELS)
cmake_parse_arguments(_sb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT _sb_PROJECTS AND NOT _sb_ALL_PROJECTS)
if(SUPERBUILD_TOPLEVEL_PROJECT)
set(_sb_PROJECTS ${SUPERBUILD_TOPLEVEL_PROJECT})
else()
set(_sb_PROJECTS ${CMAKE_PROJECT_NAME})
endif()
endif()
if(_sb_ALL_PROJECTS)
set(_sb_PROJECTS ${_ALL_PROJECT_IDENTIFIER})
endif()
foreach(_sb_PROJECT ${_sb_PROJECTS})
set(_ep_varnames "")
foreach(varname_and_vartype ${_sb_VARS})
if(NOT TARGET ${_sb_PROJECT})