draco_variables.cmake 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright 2021 The Draco Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  4. # use this file except in compliance with the License. You may obtain a copy of
  5. # the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations under
  13. # the License.
  14. if(DRACO_CMAKE_DRACO_VARIABLES_CMAKE_)
  15. return()
  16. endif() # DRACO_CMAKE_DRACO_VARIABLES_CMAKE_
  17. set(DRACO_CMAKE_DRACO_VARIABLES_CMAKE_ 1)
  18. # Halts generation when $variable_name does not refer to a directory that
  19. # exists.
  20. macro(draco_variable_must_be_directory variable_name)
  21. if("${variable_name}" STREQUAL "")
  22. message(
  23. FATAL_ERROR
  24. "Empty variable_name passed to draco_variable_must_be_directory.")
  25. endif()
  26. if("${${variable_name}}" STREQUAL "")
  27. message(
  28. FATAL_ERROR "Empty variable ${variable_name} is required to build draco.")
  29. endif()
  30. if(NOT IS_DIRECTORY "${${variable_name}}")
  31. message(
  32. FATAL_ERROR
  33. "${variable_name}, which is ${${variable_name}}, does not refer to a\n"
  34. "directory.")
  35. endif()
  36. endmacro()
  37. # Adds $var_name to the tracked variables list.
  38. macro(draco_track_configuration_variable var_name)
  39. if(DRACO_VERBOSE GREATER 2)
  40. message("---- draco_track_configuration_variable ----\n"
  41. "var_name=${var_name}\n"
  42. "----------------------------------------------\n")
  43. endif()
  44. list(APPEND draco_configuration_variables ${var_name})
  45. list(REMOVE_DUPLICATES draco_configuration_variables)
  46. endmacro()
  47. # Logs current C++ and executable linker flags via the CMake message command.
  48. macro(draco_dump_cmake_flag_variables)
  49. unset(flag_variables)
  50. list(APPEND flag_variables "CMAKE_CXX_FLAGS_INIT" "CMAKE_CXX_FLAGS"
  51. "CMAKE_EXE_LINKER_FLAGS_INIT" "CMAKE_EXE_LINKER_FLAGS")
  52. if(CMAKE_BUILD_TYPE)
  53. list(
  54. APPEND flag_variables
  55. "CMAKE_BUILD_TYPE"
  56. "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}_INIT"
  57. "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}"
  58. "CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE}_INIT"
  59. "CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE}")
  60. endif()
  61. foreach(flag_variable ${flag_variables})
  62. message("${flag_variable}:${${flag_variable}}")
  63. endforeach()
  64. endmacro()
  65. # Dumps the variables tracked in $draco_configuration_variables via the CMake
  66. # message command.
  67. macro(draco_dump_tracked_configuration_variables)
  68. foreach(config_variable ${draco_configuration_variables})
  69. message("${config_variable}:${${config_variable}}")
  70. endforeach()
  71. endmacro()