unitybuild_anon_ns_test_files.cmake 696 B

12345678910111213141516171819202122232425262728293031
  1. function(write_unity_build_anon_ns_test_files OUTVAR)
  2. set(srcs)
  3. foreach(s RANGE 1 8)
  4. set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.cpp")
  5. file(WRITE "${src}" "
  6. #ifndef CONFIG_H
  7. #define CONFIG_H
  8. #define MY_ANON_NAMESPACE MY_ANON_ID
  9. #define MY_ANON(Name) MY_ANON_NAMESPACE::Name
  10. #define MY_ANON_USING_NAMESPACE using namespace MY_ANON_NAMESPACE
  11. #endif
  12. namespace { namespace MY_ANON_NAMESPACE {
  13. int i = ${s};
  14. }}
  15. int use_plain_${s}() {
  16. return MY_ANON_NAMESPACE::i;
  17. }
  18. int func_like_macro_${s}() {
  19. return MY_ANON(i);
  20. }
  21. int using_macro_${s}() {
  22. MY_ANON_USING_NAMESPACE;
  23. return i;
  24. }
  25. ")
  26. list(APPEND srcs "${src}")
  27. endforeach()
  28. set(${OUTVAR} ${srcs} PARENT_SCOPE)
  29. endfunction()