From 9fc8b732737f139d3e466510d75668ab45578960 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 8 Mar 2016 21:02:53 +0100 Subject: sync with upstream --- project/cmake/scripts/common/projectmacros.cmake | 84 ++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 project/cmake/scripts/common/projectmacros.cmake (limited to 'project/cmake/scripts/common/projectmacros.cmake') diff --git a/project/cmake/scripts/common/projectmacros.cmake b/project/cmake/scripts/common/projectmacros.cmake new file mode 100644 index 0000000..d0739c4 --- /dev/null +++ b/project/cmake/scripts/common/projectmacros.cmake @@ -0,0 +1,84 @@ +# This script holds macros which are project specific + +# Pack a skin xbt file +# Arguments: +# input input directory to pack +# output ouput xbt file +# On return: +# xbt is added to ${XBT_FILES} +function(pack_xbt input output) + file(GLOB_RECURSE MEDIA_FILES ${input}/*) + get_filename_component(dir ${output} PATH) + add_custom_command(OUTPUT ${output} + COMMAND ${CMAKE_COMMAND} -E make_directory ${dir} + COMMAND TexturePacker::TexturePacker + ARGS -input ${input} + -output ${output} + -dupecheck + DEPENDS ${MEDIA_FILES}) + list(APPEND XBT_FILES ${output}) + set(XBT_FILES ${XBT_FILES} PARENT_SCOPE) +endfunction() + +# Add a skin to installation list, mirroring it in build tree, packing textures +# Arguments: +# skin skin directory +# relative relative base path in build tree +# On return: +# xbt is added to ${XBT_FILES}, data added to ${install_data}, mirror in build tree +function(copy_skin_to_buildtree skin relative) + file(GLOB_RECURSE FILES ${skin}/*) + file(GLOB_RECURSE MEDIA_FILES ${skin}/media/*) + list(REMOVE_ITEM FILES ${MEDIA_FILES}) + foreach(file ${FILES}) + copy_file_to_buildtree(${file} ${relative}) + endforeach() + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${dest}/media) + string(REPLACE "${relative}/" "" dest ${skin}) + pack_xbt(${skin}/media + ${CMAKE_BINARY_DIR}/${dest}/media/Textures.xbt + ${CMAKE_BINARY_DIR}) + + set(XBT_FILES ${XBT_FILES} PARENT_SCOPE) + set(install_data ${install_data} PARENT_SCOPE) +endfunction() + +# Get GTest tests as CMake tests. +# Copied from FindGTest.cmake +# Thanks to Daniel Blezek for the GTEST_ADD_TESTS code +function(GTEST_ADD_TESTS executable extra_args) + if(NOT ARGN) + message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS") + endif() + foreach(source ${ARGN}) + file(READ "${source}" contents) + string(REGEX MATCHALL "TEST_?[F]?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents}) + foreach(hit ${found_tests}) + string(REGEX REPLACE ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*" "\\1.\\2" test_name ${hit}) + add_test(${test_name} ${executable} --gtest_filter=${test_name} ${extra_args}) + endforeach() + # Groups parametrized tests under a single ctest entry + string(REGEX MATCHALL "INSTANTIATE_TEST_CASE_P\\(([^,]+), *([^,]+)" found_tests2 ${contents}) + foreach(hit ${found_tests2}) + string(SUBSTRING ${hit} 24 -1 test_name) + string(REPLACE "," ";" test_name "${test_name}") + list(GET test_name 0 filter_name) + list(GET test_name 1 test_prefix) + string(STRIP ${test_prefix} test_prefix) + add_test(${test_prefix}.${filter_name} ${executable} --gtest_filter=${filter_name}* ${extra_args}) + endforeach() + endforeach() +endfunction() + +function(whole_archive output) + if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) + set(${output} -Wl,--whole-archive ${ARGN} -Wl,--no-whole-archive PARENT_SCOPE) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL AppleClang) + foreach(library ${ARGN}) + list(APPEND ${output} -Wl,-force_load ${library}) + set(${output} ${${output}} PARENT_SCOPE) + endforeach() + else() + set(${output} ${ARGN} PARENT_SCOPE) + endif() +endfunction() -- cgit v1.2.3