2018-01-12 13:49:13 +11:00
|
|
|
# set_default
|
|
|
|
#
|
|
|
|
# Define a variable to a default value if otherwise unset.
|
|
|
|
#
|
|
|
|
# Priority for new value is:
|
|
|
|
# - Existing cmake value (ie set with cmake -D, or already set in CMakeLists)
|
|
|
|
# - Value of any non-empty environment variable of the same name
|
|
|
|
# - Default value as provided to function
|
|
|
|
#
|
|
|
|
function(set_default variable default_value)
|
|
|
|
if(NOT ${variable})
|
|
|
|
if($ENV{${variable}})
|
|
|
|
set(${variable} $ENV{${variable}} PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
set(${variable} ${default_value} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# spaces2list
|
|
|
|
#
|
|
|
|
# Take a variable whose value was space-delimited values, convert to a cmake
|
|
|
|
# list (semicolon-delimited)
|
|
|
|
#
|
|
|
|
# Note: if using this for directories, keeps the issue in place that
|
|
|
|
# directories can't contain spaces...
|
2018-01-15 13:20:38 +11:00
|
|
|
#
|
|
|
|
# TODO: look at cmake separate_arguments, which is quote-aware
|
2018-01-12 13:49:13 +11:00
|
|
|
function(spaces2list variable_name)
|
|
|
|
string(REPLACE " " ";" tmp "${${variable_name}}")
|
|
|
|
set("${variable_name}" "${tmp}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2018-01-15 13:20:38 +11:00
|
|
|
|
|
|
|
# lines2list
|
|
|
|
#
|
|
|
|
# Take a variable with multiple lines of output in it, convert it
|
|
|
|
# to a cmake list (semicolon-delimited), one line per item
|
|
|
|
#
|
|
|
|
function(lines2list variable_name)
|
|
|
|
string(REGEX REPLACE "\r?\n" ";" tmp "${${variable_name}}")
|
|
|
|
set("${variable_name}" "${tmp}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
2018-01-12 13:49:13 +11:00
|
|
|
# move_if_different
|
|
|
|
#
|
|
|
|
# If 'source' has different md5sum to 'destination' (or destination
|
|
|
|
# does not exist, move it across.
|
|
|
|
#
|
|
|
|
# If 'source' has the same md5sum as 'destination', delete 'source'.
|
|
|
|
#
|
|
|
|
# Avoids timestamp updates for re-generated files where content hasn't
|
|
|
|
# changed.
|
|
|
|
function(move_if_different source destination)
|
|
|
|
set(do_copy 1)
|
|
|
|
file(GLOB dest_exists ${destination})
|
|
|
|
if(dest_exists)
|
|
|
|
file(MD5 ${source} source_md5)
|
|
|
|
file(MD5 ${destination} dest_md5)
|
|
|
|
if(source_md5 STREQUAL dest_md5)
|
|
|
|
set(do_copy "")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(do_copy)
|
|
|
|
message("Moving ${source} -> ${destination}")
|
|
|
|
file(RENAME ${source} ${destination})
|
|
|
|
else()
|
|
|
|
message("Not moving ${source} -> ${destination}")
|
|
|
|
file(REMOVE ${source})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
endfunction()
|
2018-01-16 11:16:14 +11:00
|
|
|
|
|
|
|
# add_compile_options variant for C++ code only
|
|
|
|
#
|
|
|
|
# This adds global options, set target properties for
|
|
|
|
# component-specific flags
|
|
|
|
function(add_cxx_compile_options)
|
|
|
|
foreach(option ${ARGV})
|
|
|
|
# note: the Visual Studio Generator doesn't support this...
|
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${option}>)
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# add_compile_options variant for C code only
|
|
|
|
#
|
|
|
|
# This adds global options, set target properties for
|
|
|
|
# component-specific flags
|
|
|
|
function(add_c_compile_options)
|
|
|
|
foreach(option ${ARGV})
|
|
|
|
# note: the Visual Studio Generator doesn't support this...
|
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:C>:${option}>)
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|