Skip to content

Instantly share code, notes, and snippets.

@robertmaynard
Created March 19, 2018 12:47
Show Gist options
  • Save robertmaynard/f44fd9fc72d13a0ae00bf04e79478f9a to your computer and use it in GitHub Desktop.
Save robertmaynard/f44fd9fc72d13a0ae00bf04e79478f9a to your computer and use it in GitHub Desktop.
CMakeMakeAbsPaths.cmake
function(add_to_list variable_name)
#variable_name holds the name of the variable that we need to set
#so ${variable} == name, ${${variable}} == contents of said variable
message(STATUS "adding to variable ${variable_name}")
set(srcs )
foreach(source_file ${ARGN})
list(APPEND srcs "${CMAKE_CURRENT_SOURCE_DIR}/${source_file}")
endforeach()
#Functions have local scope so we need to set the callers version of the
#variable to what our version has.
#Note the double dereference to get the contents of
#the variable whose name we are given
set(${variable_name} ${${variable_name}} ${srcs} PARENT_SCOPE)
endfunction()
set(srcs ${CMAKE_CURRENT_SOURCE_DIR}/a)
add_to_list(srcs b c d e f g)
message(FATAL_ERROR "srcs: ${srcs}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment