diff options
Diffstat (limited to 'cmake/opentrack-boilerplate.cmake')
-rw-r--r-- | cmake/opentrack-boilerplate.cmake | 82 |
1 files changed, 77 insertions, 5 deletions
diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake index 3c5bd90a..ec1946f0 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) @@ -110,17 +110,17 @@ function(otr_install_pdb_current_project target) endfunction() function(otr_i18n_for_target_directory n) + set(k "opentrack-${n}") foreach(i ${opentrack-all-translations}) set(t "${CMAKE_CURRENT_SOURCE_DIR}/lang/${i}.ts") add_custom_command(OUTPUT "${t}" COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/lang" COMMAND "${Qt5_DIR}/../../../bin/lupdate" -silent -recursive -no-obsolete -locations relative . -ts "${t}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - DEPENDS ${${n}-cc} ${${n}-hh} ${${n}-ui} ${${n}-rc} + DEPENDS ${${k}-cc} ${${k}-hh} ${${k}-ui} ${${k}-rc} COMMENT "Running lupdate for ${n}/${i}") set(target-name "i18n-lang-${i}-module-${n}") add_custom_target(${target-name} DEPENDS "${t}") - set_property(GLOBAL APPEND PROPERTY "opentrack-ts-targets-${i}" "${target-name}") set_property(GLOBAL APPEND PROPERTY "opentrack-ts-files-${i}" "${t}") endforeach() endfunction() @@ -208,3 +208,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 0) + 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() |