summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/common/projectmacros.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'project/cmake/scripts/common/projectmacros.cmake')
-rw-r--r--project/cmake/scripts/common/projectmacros.cmake84
1 files changed, 84 insertions, 0 deletions
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 @@
1# This script holds macros which are project specific
2
3# Pack a skin xbt file
4# Arguments:
5# input input directory to pack
6# output ouput xbt file
7# On return:
8# xbt is added to ${XBT_FILES}
9function(pack_xbt input output)
10 file(GLOB_RECURSE MEDIA_FILES ${input}/*)
11 get_filename_component(dir ${output} PATH)
12 add_custom_command(OUTPUT ${output}
13 COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
14 COMMAND TexturePacker::TexturePacker
15 ARGS -input ${input}
16 -output ${output}
17 -dupecheck
18 DEPENDS ${MEDIA_FILES})
19 list(APPEND XBT_FILES ${output})
20 set(XBT_FILES ${XBT_FILES} PARENT_SCOPE)
21endfunction()
22
23# Add a skin to installation list, mirroring it in build tree, packing textures
24# Arguments:
25# skin skin directory
26# relative relative base path in build tree
27# On return:
28# xbt is added to ${XBT_FILES}, data added to ${install_data}, mirror in build tree
29function(copy_skin_to_buildtree skin relative)
30 file(GLOB_RECURSE FILES ${skin}/*)
31 file(GLOB_RECURSE MEDIA_FILES ${skin}/media/*)
32 list(REMOVE_ITEM FILES ${MEDIA_FILES})
33 foreach(file ${FILES})
34 copy_file_to_buildtree(${file} ${relative})
35 endforeach()
36 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${dest}/media)
37 string(REPLACE "${relative}/" "" dest ${skin})
38 pack_xbt(${skin}/media
39 ${CMAKE_BINARY_DIR}/${dest}/media/Textures.xbt
40 ${CMAKE_BINARY_DIR})
41
42 set(XBT_FILES ${XBT_FILES} PARENT_SCOPE)
43 set(install_data ${install_data} PARENT_SCOPE)
44endfunction()
45
46# Get GTest tests as CMake tests.
47# Copied from FindGTest.cmake
48# Thanks to Daniel Blezek <blezek@gmail.com> for the GTEST_ADD_TESTS code
49function(GTEST_ADD_TESTS executable extra_args)
50 if(NOT ARGN)
51 message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS")
52 endif()
53 foreach(source ${ARGN})
54 file(READ "${source}" contents)
55 string(REGEX MATCHALL "TEST_?[F]?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
56 foreach(hit ${found_tests})
57 string(REGEX REPLACE ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*" "\\1.\\2" test_name ${hit})
58 add_test(${test_name} ${executable} --gtest_filter=${test_name} ${extra_args})
59 endforeach()
60 # Groups parametrized tests under a single ctest entry
61 string(REGEX MATCHALL "INSTANTIATE_TEST_CASE_P\\(([^,]+), *([^,]+)" found_tests2 ${contents})
62 foreach(hit ${found_tests2})
63 string(SUBSTRING ${hit} 24 -1 test_name)
64 string(REPLACE "," ";" test_name "${test_name}")
65 list(GET test_name 0 filter_name)
66 list(GET test_name 1 test_prefix)
67 string(STRIP ${test_prefix} test_prefix)
68 add_test(${test_prefix}.${filter_name} ${executable} --gtest_filter=${filter_name}* ${extra_args})
69 endforeach()
70 endforeach()
71endfunction()
72
73function(whole_archive output)
74 if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
75 set(${output} -Wl,--whole-archive ${ARGN} -Wl,--no-whole-archive PARENT_SCOPE)
76 elseif(CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
77 foreach(library ${ARGN})
78 list(APPEND ${output} -Wl,-force_load ${library})
79 set(${output} ${${output}} PARENT_SCOPE)
80 endforeach()
81 else()
82 set(${output} ${ARGN} PARENT_SCOPE)
83 endif()
84endfunction()