From 6b6970ad9f39d2892c70b95c377ce91eca5bc3dd Mon Sep 17 00:00:00 2001 From: Markus Blatt <mblatt@dune-project.org> Date: Mon, 20 Aug 2012 15:05:20 +0000 Subject: [PATCH] Use functions instead of macros. Allow replacement of all possible properties. [[Imported from SVN: r6912]] --- cmake/modules/DuneMacros.cmake | 79 ++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/cmake/modules/DuneMacros.cmake b/cmake/modules/DuneMacros.cmake index 04ec5dd44..f7690c462 100644 --- a/cmake/modules/DuneMacros.cmake +++ b/cmake/modules/DuneMacros.cmake @@ -580,7 +580,7 @@ macro(dune_add_library basename) endif(NOT DUNE_LIB_NO_EXPORT) endmacro(dune_add_library basename sources) -macro(dune_target_link_libraries basename libraries) +function(dune_target_link_libraries basename libraries) target_link_libraries(${basename} ${libraries}) if(DUNE_BUILD_BOTH_LIBS) if(BUILD_SHARED_LIBS) @@ -589,30 +589,40 @@ macro(dune_target_link_libraries basename libraries) target_link_libraries(${basename}-shared ${libraries}) endif(BUILD_SHARED_LIBS) endif(DUNE_BUILD_BOTH_LIBS) -endmacro(dune_target_link_libraries basename libraries) +endfunction(dune_target_link_libraries basename libraries) -macro(replace_current_dir_properties) +function(replace_current_dir_properties) include(CMakeParseArguments) - #cmake_parse_arguments(REPLACE "GLOBAL;" - # "" "TARGET;SOURCE;TEST;CACHE;PROPERTY" ${ARGN}) - cmake_parse_arguments(REPLACE "" - "PROPERTY" "TARGET;SOURCE;TEST;CACHE" ${ARGN}) - set(REPLACE_DIRECTORY TRUE) - list(LENGTH REPLACE_UNPARSED_ARGUMENTS length) -# if(NOT (REPLACE_GLOBAL AND REPLACE_TARGET AND -# REPLACE_SOURCE AND REPLACE - math(EXPR mlength "${length} % 2 ") - math(EXPR hlength "${length} / 2 - 1") - - if(NOT ${mlength} EQUAL 0) - message(ERROR "You need to specify pairs consisting of a regular expression and a replacement string.") - endif(NOT ${mlength} EQUAL 0) + set(_first_opts "GLOBAL;DIRECTORY;TARGET;SOURCES;CACHE") + cmake_parse_arguments(REPLACE "GLOBAL" + "DIRECTORY;PROPERTY" "TARGET;SOURCES;TEST;CACHE" ${ARGN}) + + set(MY_DIRECTORY TRUE) + foreach(i ${_first_opts}) + if(REPLACE_${i}) + set(MY_DIRECTORY FALSE) + endif(REPLACE_${i}) + endforeach(i ${_first_opts}) + if(NOT MY_DIRECTORY) + list(FIND REPLACE_UNPARSED_ARGUMENTS DIRECTORY _found) + if(_found GREATER -1) + list(REMOVE_AT REPLACE_UNPARSED_ARGUMENTS ${_found}) + set(MY_DIRECTORY TRUE) + set(REPLACE_DIRECTORY "") + endif(_found GREATER -1) + else(NOT MY_DIRECTORY) + #set(REPLACE_PROPERTY + endif(NOT MY_DIRECTORY) #setup options if(REPLACE_GLOBAL) set(option_command GLOBAL) + elseif(MY_DIRECTORY) + set(option_command DIRECTORY) + message("DIR=${CMAKE_CURRENT_SOURCE_DIR}") elseif(REPLACE_DIRECTORY) set(option_command DIRECTORY) + set(option_arg ${REPLACE_DIRECTORY}) elseif(REPLACE_TARGET) set(option_command TARGET) set(option_arg ${REPLACE_TARGET}) @@ -630,17 +640,40 @@ macro(replace_current_dir_properties) " has to be present") endif() + message("${option_command} ${option_arg} REPLACE_UNPARSED_ARGUMENTS=${REPLACE_UNPARSED_ARGUMENTS}") + list(LENGTH REPLACE_UNPARSED_ARGUMENTS length) +# if(NOT (REPLACE_GLOBAL AND REPLACE_TARGET AND +# REPLACE_SOURCE AND REPLACE + math(EXPR mlength "${length} % 2 ") + math(EXPR hlength "${length} / 2 - 1") + + if(NOT ${mlength} EQUAL 0) + message(ERROR "You need to specify pairs consisting of a regular expression and a replacement string.") + endif(NOT ${mlength} EQUAL 0) - get_property(properties ${option_command} ${option_arg} PROPERTY ${REPLACE_PROPERTY}) + if(NOT length GREATER 0) + message(ERROR "You need to specify at least on pair consisting of a regular expression +and a replacement string. ${REPLACE_UNPARSED_ARGUMENTS}") + endif(NOT length GREATER 0) + message("get_property(properties ${option_command} ${option_arg} PROPERTY ${REPLACE_PROPERTY})") + get_property(properties ${option_command} ${option_arg} + PROPERTY ${REPLACE_PROPERTY}) + message(STATUS " old property ${option_command} ${option_arg}: ${properties}") if(NOT properties) # property not set. set it directly - message(STATUS "properties not yet set. Setting...") + foreach(i RANGE 0 ${hlength}) + math(EXPR idx "(2 * ${i}) + 1") + list(GET REPLACE_UNPARSED_ARGUMENTS ${idx} repl) + list(APPEND replacement ${repl}) + endforeach(i RANGE 0 ${hlength}) + message("hlength=${hlength} replacement=${replacemnt}") + list(REMOVE_DUPLICATES replacement) + message(STATUS "properties not yet set. Setting ${replacement} ...") set_property(${option_command} ${option_arg} ${REPLACE_APPEND} - ${REPLACE_APPEND_STRING} PROPERTY ${REPLACE_PROPERY} ${replacement}) + ${REPLACE_APPEND_STRING} PROPERTY ${REPLACE_PROPERTY} ${replacement}) return() endif(NOT properties) - message(STATUS "old properties are ${properties}") foreach(prop ${properties}) set(matched FALSE) foreach(i RANGE 0 ${hlength}) @@ -662,6 +695,8 @@ macro(replace_current_dir_properties) endforeach(prop ${properties}) set_property(${option_command} ${option_arg} PROPERTY ${REPLACE_PROPERTY} ${new_props}) + message("setting prop ${option_command} ${option_arg} + PROPERTY ${REPLACE_PROPERTY} ${new_props}") get_property(properties ${option_command} ${option_arg} PROPERTY ${REPLACE_PROPERTY}) message(STATUS "new properties are ${properties}") -endmacro(replace_current_dir_properties) +endfunction(replace_current_dir_properties) -- GitLab