summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2009-03-11 23:05:21 +0000
committercyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2009-03-11 23:05:21 +0000
commit8974008304b7a5b0fd864e9c99a2d4fd2d19433a (patch)
treed36523999b6ab0d54dd5f80e3561c60fa772b878
parent29b9577bd2846611efb732cc134e5c84956225b8 (diff)
Really corrected CMake version checking.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2156 5417fbe8-f217-4b02-8779-1006273d7864
-rw-r--r--Anope.cmake40
-rw-r--r--CMakeLists.txt52
2 files changed, 62 insertions, 30 deletions
diff --git a/Anope.cmake b/Anope.cmake
index 271d40fda..ef65641be 100644
--- a/Anope.cmake
+++ b/Anope.cmake
@@ -66,10 +66,10 @@ endmacro(append_to_list)
# the item.
###############################################################################
macro(find_in_list LIST ITEM_TO_FIND FOUND)
- if(CMAKE26_OR_BETTER OR ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} GREATER 2.4.7)
- # For CMake 2.6.x or better (as well as CMake 2.4.8 or better), we can use the FIND sub-command of list()
+ if(CMAKE248_OR_BETTER)
+ # For CMake 2.4.8 or better, we can use the FIND sub-command of list()
list(FIND ${LIST} ${ITEM_TO_FIND} ITEM_FOUND)
- else(CMAKE26_OR_BETTER OR ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} GREATER 2.4.7)
+ else(CMAKE248_OR_BETTER)
# For CMake 2.4.x before 2.4.8, we have to do this ourselves (NOTE: This is very slow due to a lack of break() as well)
# Firstly we set the position to -1 indicating nothing found, we also use a temporary position
set(ITEM_FOUND -1)
@@ -83,7 +83,7 @@ macro(find_in_list LIST ITEM_TO_FIND FOUND)
# Increase the position value by 1
math(EXPR POS "${POS} + 1")
endforeach(ITEM)
- endif(CMAKE26_OR_BETTER OR ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} GREATER 2.4.7)
+ endif(CMAKE248_OR_BETTER)
# Set the given FOUND variable to the result
set(${FOUND} ${ITEM_FOUND})
endmacro(find_in_list)
@@ -120,26 +120,31 @@ endmacro(remove_list_duplicates)
###############################################################################
# remove_item_from_list(<list> <value>)
#
-# A macro to handle removing a value from a list, uses list(REMOVE_ITEM) if
-# using CMake 2.4.2 or better, otherwise it uses a slower method of creating
-# a temporary list and adding every item except the one given.
+# A macro to handle removing a value from a list, uses list(REMOVE_ITEM) in
+# both cases, but can remove the value itself using CMake 2.4.2 or better,
+# while older versions use a slower method of iterating the list to find the
+# index of the value to remove.
###############################################################################
macro(remove_item_from_list LIST VALUE)
if(CMAKE242_OR_BETTER)
# For CMake 2.4.2 or better, this can be done automatically
list(REMOVE_ITEM ${LIST} ${VALUE})
else(CMAKE242_OR_BETTER)
- # For CMake 2.4.x before 2.4.2, we have to do this ourselves, firstly we'll create a temporary list
- set(NEW_LIST)
+ # For CMake 2.4.x before 2.4.2, we have to do this ourselves, firstly we set the index and a variable to indicate if the item was found
+ set(INDEX 0)
+ set(FOUND FALSE)
# Iterate through the old list
foreach(ITEM ${${LIST}})
- # Check if the current item is the same as the item we are removing, and if it isn't, append it to the list
- if(NOT ITEM STREQUAL ${VALUE})
- append_to_list(NEW_LIST ${ITEM})
- endif(NOT ITEM STREQUAL ${VALUE})
+ # If the item hasn't been found yet, but the current item is the same, remove it
+ if(NOT FOUND)
+ if(ITEM STREQUAL ${VALUE})
+ set(FOUND TRUE)
+ list(REMOVE_ITEM ${LIST} ${INDEX})
+ endif(ITEM STREQUAL ${VALUE})
+ endif(NOT FOUND)
+ # Increase the index value by 1
+ math(EXPR INDEX "${INDEX} + 1")
endforeach(ITEM)
- # Replace the old list with the new list
- set(${LIST} ${NEW_LIST})
endif(CMAKE242_OR_BETTER)
endmacro(remove_item_from_list)
@@ -166,11 +171,12 @@ macro(sort_list LIST)
foreach(NEW_ITEM ${NEW_LIST})
# Compare the items, only if nothing was found before
if(NOT FOUND)
- if(NEW_ITEM STRGREATER ${ITEM})
+ if(NEW_ITEM STRGREATER "${ITEM}")
set(FOUND TRUE)
list(INSERT NEW_LIST ${INDEX} ${ITEM})
- endif(NEW_ITEM STRGREATER ${ITEM})
+ endif(NEW_ITEM STRGREATER "${ITEM}")
endif(NOT FOUND)
+ # Increase the index value by 1
math(EXPR INDEX "${INDEX} + 1")
endforeach(NEW_ITEM)
# If the item was never found, just append it to the end
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6af50021f..676748249 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,27 +13,53 @@ endif(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR} AND NOT W
project(Anope CXX)
enable_language(C)
+# Detect the version of CMake for the later conditional checks
+execute_process(COMMAND ${CMAKE_COMMAND} --version OUTPUT_VARIABLE VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
+string(REGEX REPLACE "cmake version 2\\.(.*)" "\\1" ONLY_VERSION "${VERSION}")
+string(REGEX MATCH "-patch .*$" HAS_PATCH "${ONLY_VERSION}")
+if(HAS_PATCH)
+ string(REGEX REPLACE "(.*)-patch .*" "\\1" MINOR_VERSION "${ONLY_VERSION}")
+ string(REGEX REPLACE ".*-patch (.*)" "\\1" PATCH_VERSION "${ONLY_VERSION}")
+else(HAS_PATCH)
+ string(REGEX REPLACE "(.*)-beta" "\\1" MINOR_VERSION "${ONLY_VERSION}")
+ if(MINOR_VERSION STREQUAL "4-1\n")
+ set(PATCH_VERSION 1)
+ else(MINOR_VERSION STREQUAL "4-1\n")
+ set(PATCH_VERSION 0)
+ endif(MINOR_VERSION STREQUAL "4-1\n")
+ set(MINOR_VERSION 4)
+endif(HAS_PATCH)
+
# Detect is we are using CMake 2.6 or better, these versions include functions that require less work than CMake 2.4 does
-if(CMAKE_MINOR_VERSION GREATER 5)
+if(MINOR_VERSION GREATER 5)
set(CMAKE26_OR_BETTER TRUE)
+ set(CMAKE248_OR_BETTER TRUE)
set(CMAKE244_OR_BETTER TRUE)
set(CMAKE242_OR_BETTER TRUE)
-else(CMAKE_MINOR_VERSION GREATER 5)
+else(MINOR_VERSION GREATER 5)
set(CMAKE26_OR_BETTER FALSE)
- # Also detect if we are using CMake 2.4.4 or better, the CheckCXXCompilerFlag module is non-existant in earlier versions
- if(CMAKE_PATCH_VERSION GREATER 3)
+ # Also detect if we are using CMake 2.4.8 or better, the FIND sub-command of list() is non-existant in earlier versions
+ if(PATCH_VERSION GREATER 7)
+ set(CMAKE248_OR_BETTER TRUE)
set(CMAKE244_OR_BETTER TRUE)
set(CMAKE242_OR_BETTER TRUE)
- else(CMAKE_PATCH_VERSION GREATER 3)
- set(CMAKE244_OR_BETTER FALSE)
- # ALSO detect if we are using CMake 2.4.2 or better, the APPEND sub-command of list() is non-existant in earlier versions
- if(CMAKE_PATCH_VERSION GREATER 1)
+ else(PATCH_VERSION GREATER 7)
+ set(CMAKE248_OR_BETTER FALSE)
+ # Also detect if we are using CMake 2.4.4 or better, the CheckCXXCompilerFlag module and SORT sub-command of list() are non-existant in earlier versions
+ if(PATCH_VERSION GREATER 3)
+ set(CMAKE244_OR_BETTER TRUE)
set(CMAKE242_OR_BETTER TRUE)
- else(CMAKE_PATCH_VERSION GREATER 1)
- set(CMAKE242_OR_BETTER FALSE)
- endif(CMAKE_PATCH_VERSION GREATER 1)
- endif(CMAKE_PATCH_VERSION GREATER 3)
-endif(CMAKE_MINOR_VERSION GREATER 5)
+ else(PATCH_VERSION GREATER 3)
+ set(CMAKE244_OR_BETTER FALSE)
+ # ALSO detect if we are using CMake 2.4.2 or better, the APPEND sub-command of list() is non-existant in earlier versions
+ if(PATCH_VERSION GREATER 1)
+ set(CMAKE242_OR_BETTER TRUE)
+ else(PATCH_VERSION GREATER 1)
+ set(CMAKE242_OR_BETTER FALSE)
+ endif(PATCH_VERSION GREATER 1)
+ endif(PATCH_VERSION GREATER 3)
+ endif(PATCH_VERSION GREATER 7)
+endif(MINOR_VERSION GREATER 5)
# Override the module include path to include our directory, for our Anope.cmake, as well as we are using our own version of the NSIS template
set(CMAKE_MODULE_PATH ${Anope_SOURCE_DIR})