diff options
author | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-12-19 20:09:37 +0000 |
---|---|---|
committer | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-12-19 20:09:37 +0000 |
commit | 75b4bc020f5e08a458753423841118e5c962e18c (patch) | |
tree | 31710d7089f13be113a37267529c9d2c85b89e0b | |
parent | 51353104ee019584441676289e563d5137049cdc (diff) |
Some more CMake fixes for 2.4.x (Apparently 2.4.x before 2.4.8 didn't have a FIND sub-command for the list() function)
As a side-note, I'd also recommend trying (it's not required) to get CMake 2.6.x to use with Anope, the workarounds to get 2.6.x's functionality with 2.4.x are slow.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1849 5417fbe8-f217-4b02-8779-1006273d7864
-rw-r--r-- | CMakeLists.txt | 36 | ||||
-rw-r--r-- | lang/CMakeLists.txt | 8 |
2 files changed, 31 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 09a40f8cf..80c529082 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,15 +2,11 @@ cmake_minimum_required(VERSION 2.4.4 FATAL_ERROR) # 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_MAJOR_VERSION GREATER 2) +if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) set(CMAKE26_OR_BETTER TRUE) -else(CMAKE_MAJOR_VERSION GREATER 2) - if(CMAKE_MINOR_VERSION GREATER 5) - set(CMAKE26_OR_BETTER TRUE) - else(CMAKE_MINOR_VERSION GREATER 5) - set(CMAKE26_OR_BETTER FALSE) - endif(CMAKE_MINOR_VERSION GREATER 5) -endif(CMAKE_MAJOR_VERSION GREATER 2) +else(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + set(CMAKE26_OR_BETTER FALSE) +endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) # If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition # and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE @@ -193,6 +189,28 @@ macro(read_from_file FILE REGEX STRINGS) set(${STRINGS} ${RESULT}) endmacro(read_from_file) +# A macro to handle searching within a list +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() + 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) + # 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 that we a temporary boolean + set(ITEM_FOUND -1) + set(POS 0) + # Iterate through the list + foreach(ITEM ${${LIST}}) + # If the item we are looking at is the item we are trying to find, set that we've found the item + if(${ITEM} STREQUAL ${ITEM_TO_FIND}) + set(ITEM_FOUND ${POS}) + endif(${ITEM} STREQUAL ${ITEM_TO_FIND}) + 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) + # Set the given FOUND variable to the result + set(${FOUND} ${ITEM_FOUND}) +endmacro(find_in_list) + # A macro to handle removing duplicates from a list macro(remove_list_duplicates LIST) if(CMAKE26_OR_BETTER) @@ -204,7 +222,7 @@ macro(remove_list_duplicates LIST) # Iterate through the old list foreach(ITEM ${${LIST}}) # Check if the item is in the new list - list(FIND NEW_LIST ${ITEM} FOUND_ITEM) + find_in_list(NEW_LIST ${ITEM} FOUND_ITEM) if(FOUND_ITEM EQUAL -1) # If the item was not found, append it to the list list(APPEND NEW_LIST ${ITEM}) diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index d38320d93..1de7bfca8 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -13,19 +13,19 @@ if(NOT GREP OR NOT PERL) set_target_properties(langtool PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}") endif(NOT GREP OR NOT PERL) -# If grep exists, use it to generate the index file -if(GREP) +# If grep exists (and we aren't using Visual Studio, it hates this), use it to generate the index file +if(NOT MSVC AND GREP) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/index COMMAND ${GREP} '^[A-Z]' ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l > ${CMAKE_CURRENT_BINARY_DIR}/index MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l ) # Otherwise, use langtool to generate the index file -else(GREP) +else(NOT MSVC AND GREP) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/index COMMAND ${CMAKE_CURRENT_BINARY_DIR}/langtool index ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l ${CMAKE_CURRENT_BINARY_DIR}/index MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l DEPENDS langtool ) -endif(GREP) +endif(NOT MSVC AND GREP) # Find all the *.l files within the current source directory, and sort the list file(GLOB LANG_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.l") |