[asterisk-scf-commits] asterisk-scf/release/cmake.git branch "ice-package" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Jan 13 11:48:57 CST 2011


branch "ice-package" has been updated
       via  999d481236d8830deb5603ac115072e97798f861 (commit)
      from  66dfaaaf0d862e5884b295fb53b8bc468fb9773a (commit)

Summary of changes:
 modules/FindIce.cmake |  167 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 111 insertions(+), 56 deletions(-)


- Log -----------------------------------------------------------------
commit 999d481236d8830deb5603ac115072e97798f861
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Thu Jan 13 11:47:38 2011 -0600

    Use a much better method of finding Ice that allows for
    exact-version matching and also will prefer locations with
    major/minor versions in the directory name (no patch version).

diff --git a/modules/FindIce.cmake b/modules/FindIce.cmake
index 5a1588e..f96bd26 100644
--- a/modules/FindIce.cmake
+++ b/modules/FindIce.cmake
@@ -1,73 +1,128 @@
 find_package(PackageHandleStandardArgs)
 
-# Function which scans a path for matching files or directories,
-# whose names end with a standard version number string, and
-# returns the one with the 'highest' version found, or NOTFOUND
-# if there were no matches. Single-character globs (?) can
-# be used in the base string, but not multi-character globs (*).
-function(find_best_version output base)
-  get_filename_component(base_full "${base}" ABSOLUTE)
-  file(GLOB path_list "${base_full}*")
-  string(LENGTH "${base_full}" base_length)
-  foreach(path ${path_list})
-    get_filename_component(path_full "${path}" ABSOLUTE)
-    string(LENGTH "${path_full}" path_length)
-    math(EXPR get "${path_length} - ${base_length}")
-    string(SUBSTRING "${path_full}" ${base_length} ${get} ver)
-    if(NOT DEFINED best_ver)
-      set(best_ver ${ver})
-      set(best_path "${path_full}")
-    elseif(best_ver VERSION_LESS ver)
-      set(best_ver ${ver})
-      set(best_path "${path_full}")
-    endif()
-  endforeach()
-  if(DEFINED best_ver)
-    set(${output} "${best_path}" PARENT_SCOPE)
-  else()
-    set(${output} "NOTFOUND" PARENT_SCOPE)
-  endif()
-endfunction()
-
 macro(set_cache_var var value reason)
   set(${var} ${value} CACHE INTERNAL "${reason}" FORCE)
   mark_as_advanced(FORCE ${var})
 endmacro()
 
-set(ice "$ENV{ICE_HOME}")
-set(version "${Ice_FIND_VERSION}")
-if(NOT ice)
-  if(WIN32)
-    find_best_version(ice "C:/Ice-${version}")
-  elseif(UNIX)
-    find_best_version(ice "/opt/Ice-${version}")
+if(NOT ICE_DIR)
+  if(NOT Ice_FIND_VERSION)
+    find_package_handle_standard_args(Ice "Major and minor version numbers (at least) must be supplied to find Ice." ICE_DIR)
   endif()
-endif()
-
-if(ice)
-  file(TO_CMAKE_PATH "${ice}" ice_cmake_path)
-  set_cache_var(ICE_DIR "${ice_cmake_path}" "Location of Ice")
 
-  find_path(ICE_SLICE_DIR Ice/Current.ice PATHS "${ICE_DIR}/../slice" "${ICE_DIR}/slice" NO_DEFAULT_PATH)
-  if(NOT ICE_SLICE_DIR)
-    message(WARNING "Ice installation located at ${ICE_DIR} is incomplete or broken (missing 'slice' directory)")
+  if($ENV{ICE_HOME})
+    # if ICE_HOME is set, we will only look there; if the version present there
+    # does not satisfy the requested version, then the search will fail
+    list(APPEND candidate_directories "$ENV{ICE_HOME}")
   else()
-    mark_as_advanced(FORCE ICE_SLICE_DIR)
+    if(Ice_FIND_VERSION_EXACT)
+      # we prefer to find an Ice directory without a patch version specified if possible, so put
+      # that in the list first
+      list(APPEND candidate_versions
+	"${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}"
+	"${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}.${Ice_FIND_VERSION_PATCH}")
+    else()
+      # we prefer to find an Ice directory without a patch version specified if possible, so put
+      # that in the list first
+      list(APPEND candidate_versions
+	"${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}")
+
+      # next, search for any patch version greater-than or equal-to what was requested
+      foreach(patch "10" "9" "8" "7" "6" "5" "4" "3" "2" "1" "0")
+	if(NOT "${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}.${patch}" VERSION_LESS "${Ice_FIND_VERSION}")
+	  list(APPEND candidate_versions
+	    "${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}.${patch}")
+	endif()
+      endforeach()
+
+    endif()
+
+    # now convert each candidate version into a directory path
+    foreach(version ${candidate_versions})
+      if(WIN32)
+	list(APPEND candidate_directories "C:/Ice-${version}")
+      elseif(UNIX)
+	list(APPEND candidate_directories "/opt/Ice-${version}")
+      endif()
+    endforeach()
+
   endif()
 
-  find_path(ICE_INCLUDE_DIR Ice/Ice.h PATHS "${ICE_DIR}/include" NO_DEFAULT_PATH)
-  if(NOT ICE_INCLUDE_DIR)
-    message(WARNING "Ice installation located at ${ICE_DIR} is incomplete or broken (missing headers)")
-  else()
-    mark_as_advanced(FORCE ICE_INCLUDE_DIR)
+  if(Ice_DEBUG)
+    message(STATUS
+      "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+      "will search for Ice in these directories: ${candidate_directories}")
   endif()
 
-  # This block essentially tricks the GNU compiler into treating the Ice header files as system headers. This has
-  # the benefit of having warnings emitted by the headers NOT treated as errors, even if the compiler has been told
-  # to do so. This is currently being utilized by the C++0x support in this file so that Ice itself does not have to
-  # be updated to be C++0x safe.
-  if(CMAKE_COMPILER_IS_GNUCXX)
-    set_cache_var(ICE_CXX_FLAGS "-isystem ${ICE_INCLUDE_DIR}" "Ice-specific compiler flags")
+  # since we may find a copy of Ice with a directory name that matches one of our candidates
+  # but does not provide an adequate version, we have to be prepared to search repeatedly
+  # until either an adequate version is found or all the candidates are exhausted
+  while(NOT ICE_DIR)
+    find_path(ICE_INCLUDE_DIR NAMES "IceUtil/Config.h" PATHS ${candidate_directories} PATH_SUFFIXES "include" NO_DEFAULT_PATH)
+
+    # if nothing was found, then stop now
+    if(NOT ICE_INCLUDE_DIR)
+      break()
+    endif()
+
+    if(Ice_DEBUG)
+      message(STATUS
+	"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+        "found Ice includes at: ${ICE_INCLUDE_DIR}")
+    endif()
+
+    get_filename_component(possible_ice_dir "${ICE_INCLUDE_DIR}" PATH)
+
+    # now check the embedded version in the IceUtil/Config.h file to ensure it
+    # satisfies the version requested
+    file(READ "${ICE_INCLUDE_DIR}/IceUtil/Config.h" config_contents)
+    string(REGEX REPLACE ".*#define.*ICE_STRING_VERSION.*\"([0-9]+\\.[0-9]+\\.[0-9]+)\".*" "\\1" ice_version "${config_contents}")
+
+    if(Ice_DEBUG)
+      message(STATUS
+	"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+        "Ice version detected: ${ice_version}")
+    endif()
+
+    if(NOT Ice_FIND_VERSION_EXACT)
+      set_cache_var(ICE_DIR "${possible_ice_dir}" "Location of Ice")
+      break()
+    endif()
+
+    if(${ice_version} VERSION_EQUAL ${Ice_FIND_VERSION})
+      set_cache_var(ICE_DIR "${possible_ice_dir}" "Location of Ice")
+      break()
+    endif()
+
+    if(Ice_DEBUG)
+      message(STATUS
+	"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+	"Ice version ${ice_version} does not match requested ${Ice_FIND_VERSION}")
+    endif()
+
+    # we are in EXACT find mode, and the version in the directory found
+    # does not satisfy the requested version... so remove this directory
+    # as a candidate and try again
+    list(REMOVE_ITEM candidate_directories ${possible_ice_dir})
+    unset(ICE_INCLUDE_DIR CACHE)
+  endwhile()
+
+  if(ICE_DIR)
+    mark_as_advanced(FORCE ICE_INCLUDE_DIR)
+    
+    find_path(ICE_SLICE_DIR "Ice/Current.ice" PATHS "${ICE_DIR}" PATH_SUFFIXES "slice" NO_DEFAULT_PATH)
+    if(NOT ICE_SLICE_DIR)
+      message(WARNING "Ice installation located at ${ICE_DIR} is incomplete or broken (missing 'slice' directory)")
+    else()
+      mark_as_advanced(FORCE ICE_SLICE_DIR)
+    endif()
+    
+    # This block essentially tricks the GNU compiler into treating the Ice header files as system headers. This has
+    # the benefit of having warnings emitted by the headers NOT treated as errors, even if the compiler has been told
+    # to do so. This is being utilized so that Ice itself does not have to be updated to be C++0x safe.
+    if(CMAKE_COMPILER_IS_GNUCXX)
+      set_cache_var(ICE_CXX_FLAGS "-isystem ${ICE_INCLUDE_DIR}" "Ice-specific compiler flags")
+    endif()
   endif()
 endif()
 

-----------------------------------------------------------------------


-- 
asterisk-scf/release/cmake.git



More information about the asterisk-scf-commits mailing list