[CMake] Test example with list(FIND inside a macro.

Steven Truppe workbench at gmx.at
Sat Jul 20 18:04:07 EDT 2019


Hi everyone, i have the following code:

nclude(CMakePrintHelpers)

## MACROS
###########################################################
macro(bsIsInListBefore)
     message(STATUS "bsIsInListBefore(): #${ARGV0}#${ARGV1}")

     set(index1 0)
     set(index2 0)

     cmake_print_variables(ARG1)
     list(FIND ${LIBS_TO_BUILD} ${ARGV1} index1)
     cmake_print_variables(index1)
     if(index1 GREATER -1)
         list(FIND ${LIBS_TO_BUILD} ${ARG2} index2)
         message(STATUS "index found")

     elseif()
         message(STATUS "index NO found")
     endif()
endmacro()

set(LIBS_TO_BUILD
     glad
     glfw
     eigen
     cppflags
     python
     boost
)


## Main ############################################################
cmake_print_variables(LIBS_TO_BUILD)
bsIsInListBefore(${LIBS_TO_BUILD} glfw glad is_before)
if(${is_before})
     message(STATUS "-------> glfw in in front of glad")
endif()
message(STATUS "YES glfw is before glad in the list !!!!")


I've never use list(FIND and i never knoe if i should pass a variable
with %{VAR} or VAR only..


best regards,

Steven Truppe



More information about the CMake mailing list