Permalink
Browse files

COMP: Fix Windows build ensuring CMAKE_CONFIGURATION_TYPES is properl…

…y passed

This is a follow up of commit r21499

List can't be passed directly to ExternalProject, they have to be converted
to string with a separator different from ";".

The function "list_to_string" allows to easily convert list to string
using a given separator.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21510 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information...
1 parent f8cbe1f commit a4bf7db2070e1e1cdff44903be10ede142a48c40 @jcfr jcfr committed Dec 8, 2012
Showing with 128 additions and 2 deletions.
  1. +119 −0 CMake/ListToString.cmake
  2. +1 −0 CMake/Testing/CMakeLists.txt
  3. +8 −2 SuperBuild.cmake
View
119 CMake/ListToString.cmake
@@ -0,0 +1,119 @@
+################################################################################
+#
+# Program: 3D Slicer
+#
+# Copyright (c) Kitware Inc.
+#
+# See COPYRIGHT.txt
+# or http://www.slicer.org/copyright/copyright.txt for details.
+#
+# 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
+#
+################################################################################
+
+function(list_to_string separator input_list output_string_var)
+ set(_string "")
+ cmake_policy(PUSH)
+ cmake_policy(SET CMP0007 OLD)
+ # 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)
+ # .. and append 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()
+ endforeach()
+ endif()
+ set(${output_string_var} ${_string} PARENT_SCOPE)
+ cmake_policy(POP)
+endfunction()
+
+
+#
+# cmake -DTEST_list_to_string_test:BOOL=ON -P ListToString.cmake
+#
+function(list_to_string_test)
+
+ function(list_to_string_test_check id current_output expected_output)
+ if(NOT "${current_output}" STREQUAL "${expected_output}")
+ message(FATAL_ERROR "Problem with list_to_string() - See testcase: ${id}\n"
+ "current_output:${current_output}\n"
+ "expected_output:${expected_output}")
+ endif()
+ endfunction()
+
+ set(id 1)
+ set(case${id}_input "")
+ set(case${id}_expected_output "")
+ list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ set(id 2)
+ set(case${id}_input item1)
+ set(case${id}_expected_output "item1")
+ list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ set(id 3)
+ set(case${id}_input item1 item2)
+ set(case${id}_expected_output "item1^^item2")
+ list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ set(id 4)
+ set(case${id}_input item1 item2 item3)
+ set(case${id}_expected_output "item1^^item2^^item3")
+ list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ set(id 5)
+ set(case${id}_input item1 item2 item3 item4)
+ set(case${id}_expected_output "item1^^item2^^item3^^item4")
+ list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ set(id 6)
+ set(case${id}_input item1 "" item3 item4)
+ set(case${id}_expected_output "item1^^item3^^item4")
+ list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ set(id 7)
+ set(case${id}_input item1 ^^item2 item3 item4)
+ set(case${id}_expected_output "item1^^^^item2^^item3^^item4")
+ list_to_string("^^" "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ set(id 8)
+ set(case${id}_input item1 item2 item3 item4)
+ set(case${id}_expected_output "item1item2item3item4")
+ list_to_string("" "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ set(id 9)
+ set(case${id}_input item1 item2 item3 item4)
+ set(case${id}_expected_output "item1 item2 item3 item4")
+ list_to_string(" " "${case${id}_input}" case${id}_current_output)
+ list_to_string_test_check(${id} "${case${id}_current_output}" "${case${id}_expected_output}")
+
+ message("SUCCESS")
+endfunction()
+if(TEST_list_to_string_test)
+ list_to_string_test()
+endif()
View
1 CMake/Testing/CMakeLists.txt
@@ -15,3 +15,4 @@ endmacro()
# Add 'CMake script' Tests
#
add_cmakescript_test(slicer_setting_variable_message_test UseSlicerMacros)
+add_cmakescript_test(list_to_string_test ListToString)
View
10 SuperBuild.cmake
@@ -59,6 +59,7 @@ include(SlicerBlockFindQtAndCheckVersion)
# Enable and setup External project global properties
#-----------------------------------------------------------------------------
include(ExternalProject)
+include(ListToString)
include(SlicerMacroCheckExternalProjectDependency)
# With CMake 2.8.9 or later, the UPDATE_COMMAND is required for updates to occur.
@@ -74,6 +75,8 @@ endif()
set(ep_base "${CMAKE_BINARY_DIR}")
#set(ep_install_dir "${ep_base}/Install")
+set(ep_list_separator "^^")
+
set(ep_common_c_flags "${CMAKE_C_FLAGS_INIT} ${ADDITIONAL_C_FLAGS}")
set(ep_common_cxx_flags "${CMAKE_CXX_FLAGS_INIT} ${ADDITIONAL_CXX_FLAGS}")
@@ -228,11 +231,13 @@ endforeach()
set(ep_superbuild_extra_args)
if(DEFINED CTEST_CONFIGURATION_TYPE)
- list(APPEND ep_superbuild_extra_args -DCTEST_CONFIGURATION_TYPE:STRING=${CTEST_CONFIGURATION_TYPE})
+ list_to_string(${ep_list_separator} "${CTEST_CONFIGURATION_TYPE}" ep_CTEST_CONFIGURATION_TYPE)
+ list(APPEND ep_superbuild_extra_args -DCTEST_CONFIGURATION_TYPE:STRING=${ep_CTEST_CONFIGURATION_TYPE})
endif()
if(DEFINED CMAKE_CONFIGURATION_TYPES)
- list(APPEND ep_superbuild_extra_args -DCMAKE_CONFIGURATION_TYPES:STRING=${CMAKE_CONFIGURATION_TYPES})
+ list_to_string(${ep_list_separator} "${CMAKE_CONFIGURATION_TYPES}" ep_CMAKE_CONFIGURATION_TYPES)
+ list(APPEND ep_superbuild_extra_args -DCMAKE_CONFIGURATION_TYPES:STRING=${ep_CMAKE_CONFIGURATION_TYPES})
endif()
if(WIN32)
@@ -350,6 +355,7 @@ ExternalProject_Add(${proj}
BINARY_DIR ${Slicer_BINARY_INNER_SUBDIR}
CMAKE_GENERATOR ${gen}
UPDATE_COMMAND ""
+ LIST_SEPARATOR ${ep_list_separator}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags}

0 comments on commit a4bf7db

Please sign in to comment.