Hello,

When calling a macro, the variables can be dereferenced but they are not
DEFINED, and the list() command fails in several way (please have a look
at the attached test for more details)

Is this a wanted behaviour? If it is, perhaps it should be documented in
macro() command documentation.


Cheers,
 Daniele

macro(foo _bar)
    message(STATUS "_bar = ${_bar}")
    if(NOT DEFINED _bar)
        message("_bar NOT DEFINED")
    endif()

    list(LENGTH _bar _bar_len)
    if(NOT _bar_len EQUAL 2)
        message("_bar LENGTH = ${_bar_len}")
    endif()

    list(FIND _bar "hey" _bar_hey_index)
    if(NOT _bar_hey_index EQUAL 0)
        message("_bar_hey_index = ${_bar_hey_index}")
    endif()

    set(_count1 0)
    foreach(_i ${_bar})
        message(STATUS "foreach 1: ${_count1}: ${_i}")
        math(EXPR _count1 "${_count1} + 1")
    endforeach()
    if(NOT ${_count1} EQUAL 2)
        message("_count1 = ${_count1}")
    endif()

    set(_count2 0)
    foreach(_i IN LISTS _bar)
        message(STATUS "foreach 2: ${_count2}: ${_i}")
        math(EXPR _count2 "${_count2} + 1")
    endforeach()
    if(NOT ${_count2} EQUAL 2)
        message("_count2 = ${_count2}")
    endif()
endmacro()


function(boo _bar)
    message(STATUS "_bar = ${_bar}")
    if(NOT DEFINED _bar)
        message("_bar NOT DEFINED")
    endif()

    list(LENGTH _bar _bar_len)
    if(NOT _bar_len EQUAL 2)
        message("_bar LENGTH = ${_bar_len}")
    endif()

    list(FIND _bar "hey" _bar_hey_index)
    if(NOT _bar_hey_index EQUAL 0)
        message("_bar_hey_index = ${_bar_hey_index}")
    endif()

    set(_count1 0)
    foreach(_i ${_bar})
        message(STATUS "foreach 1: ${_count1}: ${_i}")
        math(EXPR _count1 "${_count1} + 1")
    endforeach()
    if(NOT ${_count1} EQUAL 2)
        message("_count1 = ${_count1}")
    endif()

    set(_count2 0)
    foreach(_i IN LISTS _bar)
        message(STATUS "foreach 2: ${_count2}: ${_i}")
        math(EXPR _count2 "${_count2} + 1")
    endforeach()
    if(NOT ${_count2} EQUAL 2)
        message("_count2 = ${_count2}")
    endif()
endfunction()


message(STATUS "----------------------\n")
message(STATUS "Calling foo macro\n")
foo("hey;you" "a;b")

message(STATUS "----------------------\n")
set(_bar "hey;hey2;hey3")
message(STATUS "Calling foo macro (with _bar set to \"${_bar}\")\n")
foo("hey;you" "a;b")

message(STATUS "----------------------\n")
message(STATUS "Calling boo function (OK)\n")
boo("hey;you" "a;b")

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to