Workaround CMake awful auto-expanding vars in some if-statements without $\{\} being used
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3062 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 1eb37d17b12b18f0f230ce3efbc051080c456937 Former-commit-id: 7fbab9e92742956c026e3cf517b4c0cc6bd3cad2
This commit is contained in:
parent
30f6c03a54
commit
d6a9c05ad5
1 changed files with 62 additions and 39 deletions
|
@ -1,4 +1,28 @@
|
|||
############################################################################
|
||||
#
|
||||
# file : split_argn.cmake
|
||||
# copyright : (C) 2008 by Mart Kelder
|
||||
# web : www.speed-dreams.org
|
||||
# version : $Id$
|
||||
#
|
||||
############################################################################
|
||||
|
||||
############################################################################
|
||||
# #
|
||||
# This program is free software; you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License as published by #
|
||||
# the Free Software Foundation; either version 2 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
############################################################################
|
||||
|
||||
# @file Generic macro argument parser
|
||||
# @author Mart Kelder
|
||||
# @version $Id$
|
||||
|
||||
# Internal use only : Get the list of specified keywords
|
||||
MACRO(SPLIT_ARGN_KEYWORDS SAK_RESULT)
|
||||
|
||||
SET(SAK_FIRST TRUE)
|
||||
SET(SAK_FINISHED FALSE)
|
||||
|
||||
|
@ -18,9 +42,12 @@ MACRO(SPLIT_ARGN_KEYWORDS SAK_RESULT)
|
|||
ENDIF(${SAK_ITEM} STREQUAL ARGUMENTS)
|
||||
ENDIF(NOT SAK_FINISHED)
|
||||
ENDFOREACH(SAK_ITEM ${ARGN})
|
||||
|
||||
ENDMACRO(SPLIT_ARGN_KEYWORDS SAK_RESULT)
|
||||
|
||||
MACRO(SPLIT_ARGN_CLEAN_ISVARS)
|
||||
# Internal use only : Initialize output vars for each keyword
|
||||
MACRO(SPLIT_ARGN_CLEAN_VARS)
|
||||
|
||||
SET(SACI_FINISHED FALSE)
|
||||
|
||||
FOREACH(SACI_ITEM ${ARGN})
|
||||
|
@ -30,15 +57,22 @@ MACRO(SPLIT_ARGN_CLEAN_ISVARS)
|
|||
ELSE(${SACI_ITEM} STREQUAL ARGUMENTS)
|
||||
STRING(REPLACE "," ";" SACI_ITEMLIST ${SACI_ITEM})
|
||||
LIST(GET SACI_ITEMLIST 3 SACI_ISVARNAME)
|
||||
IF(NOT "${SACI_ISVARNAME}" STREQUAL "_")
|
||||
#IF(NOT "${SACI_ISVARNAME}" STREQUAL "_")
|
||||
SET(${SACI_ISVARNAME} FALSE)
|
||||
ENDIF(NOT "${SACI_ISVARNAME}" STREQUAL "_")
|
||||
#ENDIF(NOT "${SACI_ISVARNAME}" STREQUAL "_")
|
||||
LIST(GET SACI_ITEMLIST 4 SACI_VARNAME)
|
||||
#IF(NOT "${SACI_VARNAME}" STREQUAL "_")
|
||||
SET(${SACI_VARNAME})
|
||||
#ENDIF(NOT "${SACI_VARNAME}" STREQUAL "_")
|
||||
ENDIF(${SACI_ITEM} STREQUAL ARGUMENTS)
|
||||
ENDIF(NOT SACI_FINISHED)
|
||||
ENDFOREACH(SACI_ITEM ${ARGN})
|
||||
ENDMACRO(SPLIT_ARGN_CLEAN_ISVARS)
|
||||
|
||||
ENDMACRO(SPLIT_ARGN_CLEAN_VARS)
|
||||
|
||||
# Internal use only : Parse args for a given keyword
|
||||
MACRO(SPLIT_ARGN_GET_KEYWORD SAG_KEYWORD SAG_FOUND SAG_KEYWORDNAME SAG_MINCOUNT SAG_MAXCOUNT SAG_ISVARNAME SAG_VARNAME)
|
||||
|
||||
SET(${SAG_FOUND} FALSE)
|
||||
SET(SAG_FINISHED FALSE)
|
||||
|
||||
|
@ -51,90 +85,78 @@ MACRO(SPLIT_ARGN_GET_KEYWORD SAG_KEYWORD SAG_FOUND SAG_KEYWORDNAME SAG_MINCOUNT
|
|||
LIST(GET SAG_ITEMLIST 0 SAG_ITEMKEYWORD)
|
||||
IF(${SAG_KEYWORD} STREQUAL ${SAG_ITEMKEYWORD})
|
||||
SET(${SAG_FOUND} TRUE)
|
||||
IF(NOT "${SAG_KEYWORDNAME}" STREQUAL "_")
|
||||
LIST(GET SAG_ITEMLIST 0 ${SAG_KEYWORDNAME})
|
||||
ENDIF(NOT "${SAG_KEYWORDNAME}" STREQUAL "_")
|
||||
IF(NOT "${SAG_MINCOUNT}" STREQUAL "_")
|
||||
LIST(GET SAG_ITEMLIST 1 ${SAG_MINCOUNT})
|
||||
ENDIF(NOT "${SAG_MINCOUNT}" STREQUAL "_")
|
||||
IF(NOT "${SAG_MAXCOUNT}" STREQUAL "_")
|
||||
LIST(GET SAG_ITEMLIST 2 ${SAG_MAXCOUNT})
|
||||
ENDIF(NOT "${SAG_MAXCOUNT}" STREQUAL "_")
|
||||
IF(NOT "${SAG_ISVARNAME}" STREQUAL "_")
|
||||
LIST(GET SAG_ITEMLIST 3 ${SAG_ISVARNAME})
|
||||
ENDIF(NOT "${SAG_ISVARNAME}" STREQUAL "_")
|
||||
IF(NOT "${SAG_VARNAME}" STREQUAL "_")
|
||||
LIST(GET SAG_ITEMLIST 4 ${SAG_VARNAME})
|
||||
ENDIF(NOT "${SAG_VARNAME}" STREQUAL "_")
|
||||
LIST(GET SAG_ITEMLIST 0 ${SAG_KEYWORDNAME})
|
||||
LIST(GET SAG_ITEMLIST 1 ${SAG_MINCOUNT})
|
||||
LIST(GET SAG_ITEMLIST 2 ${SAG_MAXCOUNT})
|
||||
LIST(GET SAG_ITEMLIST 3 ${SAG_ISVARNAME})
|
||||
LIST(GET SAG_ITEMLIST 4 ${SAG_VARNAME})
|
||||
ENDIF(${SAG_KEYWORD} STREQUAL ${SAG_ITEMKEYWORD})
|
||||
ENDIF(${SAG_ITEM} STREQUAL ARGUMENTS)
|
||||
ENDIF(NOT SAG_FINISHED)
|
||||
ENDFOREACH(SAG_ITEM ${ARGN})
|
||||
|
||||
ENDMACRO(SPLIT_ARGN_GET_KEYWORD SAG_KEYWORD SAG_FOUND SAG_KEYWORDNAME SAG_MINCOUNT SAG_MAXCOUNT SAG_ISVARNAME SAG_VARNAME)
|
||||
|
||||
# Internal use only : Test if a string is a keyword
|
||||
MACRO(SPLIT_ARGN_IS_KEYWORD SAG_KEYWORDS SAG_ITEM SAG_RESULT)
|
||||
|
||||
LIST(FIND ${SAG_KEYWORDS} ${SAG_ITEM} SAG_FIND)
|
||||
IF(${SAG_FIND} LESS 0)
|
||||
SET(${SAG_RESULT} FALSE)
|
||||
ELSE(${SAG_FIND} LESS 0)
|
||||
SET(${SAG_RESULT} TRUE)
|
||||
ENDIF(${SAG_FIND} LESS 0)
|
||||
|
||||
ENDMACRO(SPLIT_ARGN_IS_KEYWORD SAG_KEYWORDS SAG_ITEM)
|
||||
|
||||
# The argument parser
|
||||
MACRO(SPLIT_ARGN)
|
||||
|
||||
SPLIT_ARGN_KEYWORDS(SA_KEYWORDS ${ARGN})
|
||||
#IF(__DEBUG__)
|
||||
# MESSAGE(STATUS "KEYWORDS: ${SA_KEYWORDS}")
|
||||
#ENDIF()
|
||||
SPLIT_ARGN_CLEAN_ISVARS(${ARGN})
|
||||
SPLIT_ARGN_CLEAN_VARS(${ARGN})
|
||||
SET(SA_EXPECT_KEYWORD TRUE)
|
||||
SET(SA_EXPECT_VALUE FALSE)
|
||||
SET(SA_START FALSE)
|
||||
|
||||
#Loop through list
|
||||
FOREACH(SA_ITEM ${ARGN})
|
||||
|
||||
IF(NOT SA_START)
|
||||
|
||||
IF(${SA_ITEM} STREQUAL ARGUMENTS)
|
||||
SET(SA_START TRUE)
|
||||
ENDIF(${SA_ITEM} STREQUAL ARGUMENTS)
|
||||
|
||||
ELSE(NOT SA_START)
|
||||
|
||||
#Check if the current item is a keyword
|
||||
SPLIT_ARGN_IS_KEYWORD(SA_KEYWORDS ${SA_ITEM} SA_ISKEYWORD)
|
||||
#IF(__DEBUG__)
|
||||
# MESSAGE(STATUS "ITEM=${SA_ITEM} KEYWORD=${SA_ISKEYWORD}")
|
||||
#ENDIF()
|
||||
|
||||
IF(SA_ISKEYWORD)
|
||||
|
||||
#Check if it is what we expect
|
||||
IF(NOT SA_EXPECT_KEYWORD)
|
||||
MESSAGE(ERROR "Unexpected keyword in SPLIT_ARGN, got \"${SA_ITEM}\".")
|
||||
ELSE(NOT SA_EXPECT_KEYWORD)
|
||||
#Save information about the keyword
|
||||
SPLIT_ARGN_GET_KEYWORD(${SA_ITEM} SA_KEYWORD_FOUND SA_CUR_KEYWORD SA_CUR_MINCOUNT SA_CUR_MAXCOUNT SA_CUR_ISVARNAME SA_CUR_VARNAME ${ARGN})
|
||||
#IF(__DEBUG__)
|
||||
# MESSAGE(STATUS "KEYWORD: FOUND=${SA_KEYWORD_FOUND} KEYW=${SA_CUR_KEYWORD} MIN=${SA_CUR_MINCOUNT} MAX=${SA_CUR_MAXCOUNT} ISVAR=${SA_CUR_ISVARNAME} VARNAME=${SA_CUR_VARNAME}")
|
||||
#ENDIF()
|
||||
IF(SA_KEYWORD_FOUND)
|
||||
SET(SA_CUR_INDEX 0)
|
||||
IF(NOT "${SA_CUR_VARNAME}" STREQUAL "_")
|
||||
SET(${SA_CUR_VARNAME})
|
||||
ENDIF(NOT "${SA_CUR_VARNAME}" STREQUAL "_")
|
||||
IF(NOT "${SA_CUR_ISVARNAME}" STREQUAL "_")
|
||||
SET(${SA_CUR_ISVARNAME} FALSE)
|
||||
ENDIF(NOT "${SA_CUR_ISVARNAME}" STREQUAL "_")
|
||||
SET(${SA_CUR_VARNAME})
|
||||
SET(${SA_CUR_ISVARNAME} FALSE)
|
||||
ELSE(SA_KEYWORD_FOUND)
|
||||
MESSAGE(ERROR "Got keyword, but didn't found information about \"${SA_ITEM}\"")
|
||||
ENDIF(SA_KEYWORD_FOUND)
|
||||
ENDIF(NOT SA_EXPECT_KEYWORD)
|
||||
|
||||
ELSE(SA_ISKEYWORD)
|
||||
|
||||
#Check if it is what we expect
|
||||
IF(NOT SA_EXPECT_VALUE)
|
||||
MESSAGE(ERROR "Unexpected value in SPLIT_ARGN, got \"${SA_ITEM}\".")
|
||||
ELSE(NOT SA_EXPECT_VALUE)
|
||||
#Save this item to the list
|
||||
IF(NOT "${SA_CUR_VARNAME}" STREQUAL "_")
|
||||
SET(${SA_CUR_VARNAME} ${${SA_CUR_VARNAME}} ${SA_ITEM})
|
||||
ENDIF(NOT "${SA_CUR_VARNAME}" STREQUAL "_")
|
||||
SET(${SA_CUR_VARNAME} ${${SA_CUR_VARNAME}} ${SA_ITEM})
|
||||
|
||||
#Increase index
|
||||
MATH(EXPR SA_CUR_INDEX_TMP "${SA_CUR_INDEX}+1")
|
||||
|
@ -149,7 +171,6 @@ MACRO(SPLIT_ARGN)
|
|||
ELSE(${SA_CUR_INDEX} LESS ${SA_CUR_MINCOUNT})
|
||||
SET(${SA_CUR_ISVARNAME} TRUE)
|
||||
SET(SA_EXPECT_KEYWORD TRUE)
|
||||
|
||||
IF(${SA_CUR_INDEX} LESS ${SA_CUR_MAXCOUNT} OR ${SA_CUR_MAXCOUNT} LESS 0)
|
||||
SET(SA_EXPECT_VALUE TRUE)
|
||||
ELSE(${SA_CUR_INDEX} LESS ${SA_CUR_MAXCOUNT} OR ${SA_CUR_MAXCOUNT} LESS 0)
|
||||
|
@ -157,11 +178,13 @@ MACRO(SPLIT_ARGN)
|
|||
ENDIF(${SA_CUR_INDEX} LESS ${SA_CUR_MAXCOUNT} OR ${SA_CUR_MAXCOUNT} LESS 0)
|
||||
ENDIF(${SA_CUR_INDEX} LESS ${SA_CUR_MINCOUNT})
|
||||
ENDIF(NOT SA_START)
|
||||
|
||||
ENDFOREACH(SA_ITEM ${ARGN})
|
||||
|
||||
IF(SA_START AND NOT SA_EXPECT_KEYWORD)
|
||||
#Didn't get all the expected values of the last keyword
|
||||
MESSAGE(ERROR "Missing values at the end in SPLIT_ARGN.")
|
||||
ENDIF(SA_START AND NOT SA_EXPECT_KEYWORD)
|
||||
|
||||
ENDMACRO(SPLIT_ARGN)
|
||||
|
||||
|
|
Loading…
Reference in a new issue