draco_features.cmake 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. if (NOT DRACO_CMAKE_DRACO_FEATURES_CMAKE_)
  2. set(DRACO_CMAKE_DRACO_FEATURES_CMAKE_ 1)
  3. set(draco_features_file_name "${draco_build_dir}/draco/draco_features.h")
  4. set(draco_features_list)
  5. # Macro that handles tracking of Draco preprocessor symbols for the purpose of
  6. # producing draco_features.h.
  7. #
  8. # draco_enable_feature(FEATURE <feature_name> [TARGETS <target_name>])
  9. # FEATURE is required. It should be a Draco preprocessor symbol.
  10. # TARGETS is optional. It can be one or more draco targets.
  11. #
  12. # When the TARGETS argument is not present the preproc symbol is added to
  13. # draco_features.h. When it is draco_features.h is unchanged, and
  14. # target_compile_options() is called for each target specified.
  15. macro (draco_enable_feature)
  16. set(def_flags)
  17. set(def_single_arg_opts FEATURE)
  18. set(def_multi_arg_opts TARGETS)
  19. cmake_parse_arguments(DEF "${def_flags}" "${def_single_arg_opts}"
  20. "${def_multi_arg_opts}" ${ARGN})
  21. if ("${DEF_FEATURE}" STREQUAL "")
  22. message(FATAL_ERROR "Empty FEATURE passed to draco_enable_feature().")
  23. endif ()
  24. # Do nothing/return early if $DEF_FEATURE is already in the list.
  25. list(FIND draco_features_list ${DEF_FEATURE} df_index)
  26. if (NOT df_index EQUAL -1)
  27. return ()
  28. endif ()
  29. list(LENGTH DEF_TARGETS df_targets_list_length)
  30. if (${df_targets_list_length} EQUAL 0)
  31. list(APPEND draco_features_list ${DEF_FEATURE})
  32. else ()
  33. foreach (target ${DEF_TARGETS})
  34. target_compile_definitions(${target} PRIVATE ${DEF_FEATURE})
  35. endforeach ()
  36. endif ()
  37. endmacro ()
  38. # Function for generating draco_features.h.
  39. function (draco_generate_features_h)
  40. file(WRITE "${draco_features_file_name}"
  41. "// GENERATED FILE -- DO NOT EDIT\n\n"
  42. "#ifndef DRACO_FEATURES_H_\n"
  43. "#define DRACO_FEATURES_H_\n\n")
  44. foreach (feature ${draco_features_list})
  45. file(APPEND "${draco_features_file_name}" "#define ${feature}\n")
  46. endforeach ()
  47. file(APPEND "${draco_features_file_name}" "\n#endif // DRACO_FEATURES_H_")
  48. endfunction ()
  49. endif () # DRACO_CMAKE_DRACO_FEATURES_CMAKE_