summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_test_files.cmake
blob: 06a600e2eebf0d88db5191f77ef81a6824bdee2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

function(write_unity_build_anon_ns_test_files OUTVAR)
  set(srcs)
  foreach(s RANGE 1 8)
    set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.cpp")
    file(WRITE "${src}" "
#ifndef CONFIG_H
#define CONFIG_H
#define MY_ANON_NAMESPACE MY_ANON_ID
#define MY_ANON(Name) MY_ANON_NAMESPACE::Name
#define MY_ANON_USING_NAMESPACE using namespace MY_ANON_NAMESPACE
#endif

namespace { namespace MY_ANON_NAMESPACE {
  int i = ${s};
}}
int use_plain_${s}() {
  return MY_ANON_NAMESPACE::i;
}
int func_like_macro_${s}() {
  return MY_ANON(i);
}
int using_macro_${s}() {
  MY_ANON_USING_NAMESPACE;
  return i;
}
")
    list(APPEND srcs "${src}")
  endforeach()
  set(${OUTVAR} ${srcs} PARENT_SCOPE)
endfunction()