utils.cmake 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #############################################################
  2. function(set_bundle_dir)
  3. set(args SOURCES DEST EXCLUDE)
  4. include(CMakeParseArguments)
  5. cmake_parse_arguments(BD "" "" "${args}" ${ARGN})
  6. foreach(_BDIR ${BD_SOURCES})
  7. file(GLOB _DIRCONTENTS ${_BDIR}/*)
  8. foreach(_BDFILE ${_DIRCONTENTS})
  9. get_filename_component(_BDFILE_NAME ${_BDFILE} NAME)
  10. set(PROCESS_FILE 1)
  11. foreach(EX_FILE ${BD_EXCLUDE})
  12. string(REGEX MATCH ${EX_FILE} DID_MATCH ${_BDFILE})
  13. if(NOT "${DID_MATCH}" STREQUAL "")
  14. set(PROCESS_FILE 0)
  15. endif(NOT "${DID_MATCH}" STREQUAL "")
  16. endforeach(EX_FILE ${BD_EXCLUDE})
  17. if(PROCESS_FILE STREQUAL "1")
  18. if(IS_DIRECTORY ${_BDFILE})
  19. set_bundle_dir(SOURCES ${_BDFILE} DEST ${BD_DEST}/${_BDFILE_NAME} EXCLUDE ${BD_EXCLUDE})
  20. else(IS_DIRECTORY ${_BDFILE})
  21. #message("set_bundle_dir : setting package_location ${_BDFILE} = ${BD_DEST}")
  22. set_source_files_properties(${_BDFILE} PROPERTIES MACOSX_PACKAGE_LOCATION ${BD_DEST})
  23. get_property(BUNDLED_FILES GLOBAL PROPERTY CONFIG_BUNDLED_FILES)
  24. set_property(GLOBAL PROPERTY CONFIG_BUNDLED_FILES ${BUNDLED_FILES} ${_BDFILE})
  25. string(REPLACE "/" "\\\\" GNAME ${BD_DEST})
  26. source_group(${GNAME} FILES ${_BDFILE})
  27. endif(IS_DIRECTORY ${_BDFILE})
  28. endif()
  29. endforeach(_BDFILE ${_DIRCONTENTS})
  30. endforeach(_BDIR ${BD_SOURCES})
  31. endfunction(set_bundle_dir)
  32. #############################################################
  33. macro(find_all_sources DIRECTORY VARIABLE)
  34. aux_source_directory(${DIRECTORY} ${VARIABLE})
  35. file(GLOB headers ${DIRECTORY}/*h)
  36. list(APPEND ${VARIABLE} ${headers})
  37. endmacro()
  38. #############################################################
  39. # function to collect all the sources from sub-directories
  40. # into a single list
  41. function(add_sources)
  42. get_property(is_defined GLOBAL PROPERTY SRCS_LIST DEFINED)
  43. if(NOT is_defined)
  44. define_property(GLOBAL PROPERTY SRCS_LIST
  45. BRIEF_DOCS "List of source files"
  46. FULL_DOCS "List of source files to be compiled in one library")
  47. endif()
  48. # make absolute paths
  49. set(SRCS)
  50. foreach(s IN LISTS ARGN)
  51. if(NOT IS_ABSOLUTE "${s}")
  52. get_filename_component(s "${s}" ABSOLUTE)
  53. endif()
  54. list(APPEND SRCS "${s}")
  55. endforeach()
  56. string(REPLACE ${CMAKE_SOURCE_DIR}/src/ "" SUBDIR ${CMAKE_CURRENT_SOURCE_DIR})
  57. string(TOLOWER ${SUBDIR} SUBDIR)
  58. string(REPLACE "/" "\\\\" LIBNAME ${SUBDIR})
  59. source_group(${LIBNAME} FILES ${SRCS})
  60. # add it to the global list.
  61. set_property(GLOBAL APPEND PROPERTY SRCS_LIST ${SRCS})
  62. endfunction(add_sources)
  63. ## ---------------------------------------------------------------------
  64. ##
  65. ## Copyright (C) 2012 - 2014 by the deal.II authors
  66. ##
  67. ## This file is part of the deal.II library.
  68. ##
  69. ## The deal.II library is free software; you can use it, redistribute
  70. ## it, and/or modify it under the terms of the GNU Lesser General
  71. ## Public License as published by the Free Software Foundation; either
  72. ## version 2.1 of the License, or (at your option) any later version.
  73. ## The full text of the license can be found in the file LICENSE at
  74. ## the top level of the deal.II distribution.
  75. ##
  76. ## ---------------------------------------------------------------------
  77. #
  78. # Tests whether the cxx compiler understands a flag.
  79. # If so, add it to 'variable'.
  80. #
  81. # Usage:
  82. # ENABLE_IF_SUPPORTED(variable flag)
  83. #
  84. include(CheckCXXCompilerFlag)
  85. MACRO(ENABLE_IF_SUPPORTED _variable _flag)
  86. #
  87. # Clang is too conservative when reporting unsupported compiler flags.
  88. # Therefore, we promote all warnings for an unsupported compiler flag to
  89. # actual errors with the -Werror switch:
  90. #
  91. IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  92. SET(_werror_string "-Werror ")
  93. ELSE()
  94. SET(_werror_string "")
  95. ENDIF()
  96. STRING(STRIP "${_flag}" _flag_stripped)
  97. SET(_flag_stripped_orig "${_flag_stripped}")
  98. #
  99. # Gcc does not emit a warning if testing -Wno-... flags which leads to
  100. # false positive detection. Unfortunately it later warns that an unknown
  101. # warning option is used if another warning is emitted in the same
  102. # compilation unit.
  103. # Therefore we invert the test for -Wno-... flags:
  104. #
  105. IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  106. STRING(REPLACE "-Wno-" "-W" _flag_stripped "${_flag_stripped}")
  107. ENDIF()
  108. IF(NOT "${_flag_stripped}" STREQUAL "")
  109. STRING(REGEX REPLACE "^-" "" _flag_name "${_flag_stripped}")
  110. STRING(REPLACE "," "" _flag_name "${_flag_name}")
  111. STRING(REPLACE "-" "_" _flag_name "${_flag_name}")
  112. STRING(REPLACE "+" "_" _flag_name "${_flag_name}")
  113. CHECK_CXX_COMPILER_FLAG(
  114. "${_werror_string}${_flag_stripped}"
  115. HAVE_FLAG_${_flag_name}
  116. )
  117. IF(HAVE_FLAG_${_flag_name})
  118. SET(${_variable} "${${_variable}} ${_flag_stripped_orig}")
  119. STRING(STRIP "${${_variable}}" ${_variable})
  120. ENDIF()
  121. ENDIF()
  122. ENDMACRO()
  123. #
  124. # Tests whether it is possible to compile and link a dummy program with a
  125. # given flag.
  126. # If so, add it to variable.
  127. #
  128. # Usage:
  129. # ENABLE_IF_LINKS(variable flag)
  130. #
  131. MACRO(ENABLE_IF_LINKS _variable _flag)
  132. STRING(STRIP "${_flag}" _flag_stripped)
  133. IF(NOT "${_flag_stripped}" STREQUAL "")
  134. STRING(REGEX REPLACE "^-" "" _flag_name "${_flag_stripped}")
  135. STRING(REPLACE "," "" _flag_name "${_flag_name}")
  136. STRING(REPLACE "-" "_" _flag_name "${_flag_name}")
  137. STRING(REPLACE "+" "_" _flag_name "${_flag_name}")
  138. SET(_backup ${CMAKE_REQUIRED_LIBRARIES})
  139. LIST(APPEND CMAKE_REQUIRED_LIBRARIES "${_flag_stripped}")
  140. CHECK_CXX_COMPILER_FLAG(
  141. ""
  142. HAVE_FLAG_${_flag_name}
  143. )
  144. SET(CMAKE_REQUIRED_LIBRARIES ${_backup})
  145. IF(HAVE_FLAG_${_flag_name})
  146. SET(${_variable} "${${_variable}} ${_flag_stripped}")
  147. STRING(STRIP "${${_variable}}" ${_variable})
  148. ENDIF()
  149. ENDIF()
  150. ENDMACRO()
  151. #############################################################
  152. function(std_target_properties target)
  153. set_target_properties(${target} PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED ON)
  154. endfunction()