summaryrefslogtreecommitdiffhomepage
path: root/cmake
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-05-16 03:31:00 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-05-16 03:31:00 +0200
commit6faab6ff960e2dd04aa35e8ef1aa62bce2976725 (patch)
treee23afb50b7091cb15b00a37020a7080be352fa83 /cmake
parentbb664a1e794860fe86c2bca6d8e92d78fade1dd8 (diff)
add otr_prop for appending property strings
Diffstat (limited to 'cmake')
-rw-r--r--cmake/opentrack-boilerplate.cmake78
1 files changed, 75 insertions, 3 deletions
diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake
index 4c056c3e..bb596951 100644
--- a/cmake/opentrack-boilerplate.cmake
+++ b/cmake/opentrack-boilerplate.cmake
@@ -75,7 +75,7 @@ endfunction()
function(otr_compat target)
if(NOT MSVC)
- set_property(SOURCE ${${target}-moc} APPEND_STRING PROPERTY COMPILE_FLAGS " -w -Wno-error")
+ otr_prop(SOURCE ${${target}-moc} COMPILE_FLAGS "-w -Wno-error")
endif()
if(WIN32)
target_link_libraries(${target} dinput8 dxguid strmiids)
@@ -97,8 +97,8 @@ function(otr_compat target)
set(l-props "-Wl,--as-needed")
endif()
- set_property(TARGET ${target} APPEND_STRING PROPERTY COMPILE_FLAGS " ${c-props} ${arg_COMPILE}")
- set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " ${l-props} ${arg_LINK}")
+ otr_prop(TARGET ${target} COMPILE_FLAGS "${c-props} ${arg_COMPILE}"
+ LINK_FLAGS "${l-props} ${arg_LINK}")
endfunction()
include(CMakeParseArguments)
@@ -209,3 +209,75 @@ function(otr_module n_)
set_property(GLOBAL APPEND PROPERTY opentrack-all-source-dirs "${CMAKE_CURRENT_SOURCE_DIR}")
endfunction()
+function(otr_prop type)
+ set(files "")
+ set(opts ${ARGN})
+ # only SOURCE allows for multiple files
+ if(".${type}" STREQUAL ".SOURCE")
+ while(TRUE)
+ # keep popping first element off `opts' and adding to `files`
+ list(LENGTH opts len)
+ if(NOT "${len}" GREATER 0)
+ break()
+ endif()
+ list(GET opts 0 k)
+ string(FIND "${k}" "." idx1)
+ string(FIND "${k}" "/" idx2)
+ if("${idx1}" GREATER -1 AND "${idx2}" GREATER -1)
+ list(REMOVE_AT opts 0)
+ list(APPEND files "${k}")
+ else()
+ # not a pathname
+ break()
+ endif()
+ endwhile()
+ # no files, break early
+ # happens a few in the codebase
+ list(LENGTH files len)
+ if(len EQUAL 0)
+ return()
+ endif()
+ else()
+ # single file argument
+ set(opts "${ARGN}")
+ list(GET opts 0 files)
+ list(REMOVE_AT opts 0)
+ endif()
+ # must pass some properties at least
+ list(LENGTH opts len)
+ if(NOT "${len}" GREATER 1)
+ message(FATAL_ERROR "no properties given")
+ endif()
+
+ # prop name but no value
+ list(LENGTH opts len)
+ math(EXPR mod "${len} % 2")
+ if(NOT "${mod}" EQUAL 0)
+ message(FATAL_ERROR "must specify parameter for each property")
+ endif()
+
+ foreach(f ${files})
+ set(opts-copy "${opts}")
+
+ while(TRUE)
+ list(LENGTH opts-copy len)
+ if ("${len}" LESS 2)
+ break()
+ endif()
+
+ # pop off two elements, set property
+ list(GET opts-copy 0 name)
+ list(GET opts-copy 1 value)
+ list(REMOVE_AT opts-copy 1 0)
+
+ get_property(old "${type}" "${f}" PROPERTY "${name}")
+ if(".${old}" STREQUAL ".")
+ set(spc "")
+ else()
+ set(spc " ")
+ endif()
+
+ set_property("${type}" "${f}" APPEND_STRING PROPERTY "${name}" "${spc}${value}")
+ endwhile()
+ endforeach()
+endfunction()