CMakeGenericSystem.cmake 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. include(CMakeInitializeConfigs)
  4. set(CMAKE_SHARED_LIBRARY_C_FLAGS "") # -pic
  5. set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
  6. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib
  7. set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "") # -rpath
  8. set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "") # : or empty
  9. set(CMAKE_INCLUDE_FLAG_C "-I") # -I
  10. set(CMAKE_LIBRARY_PATH_FLAG "-L")
  11. set(CMAKE_LIBRARY_PATH_TERMINATOR "") # for the Digital Mars D compiler the link paths have to be terminated with a "/"
  12. set(CMAKE_LINK_LIBRARY_FLAG "-l")
  13. set(CMAKE_LINK_LIBRARY_SUFFIX "")
  14. set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
  15. set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
  16. set(CMAKE_SHARED_LIBRARY_PREFIX "lib") # lib
  17. set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") # .so
  18. set(CMAKE_EXECUTABLE_SUFFIX "") # .exe
  19. set(CMAKE_DL_LIBS "dl")
  20. set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
  21. set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
  22. # Define feature "DEFAULT" as supported. This special feature generates the
  23. # default option to link a library
  24. # This feature is intended to be used in LINK_LIBRARY_OVERRIDE and
  25. # LINK_LIBRARY_OVERRIDE_<LIBRARY> target properties
  26. set(CMAKE_LINK_LIBRARY_USING_DEFAULT_SUPPORTED TRUE)
  27. if(NOT DEFINED CMAKE_AUTOGEN_ORIGIN_DEPENDS)
  28. set(CMAKE_AUTOGEN_ORIGIN_DEPENDS ON)
  29. endif()
  30. if(NOT DEFINED CMAKE_AUTOMOC_COMPILER_PREDEFINES)
  31. set(CMAKE_AUTOMOC_COMPILER_PREDEFINES ON)
  32. endif()
  33. if(NOT DEFINED CMAKE_AUTOMOC_PATH_PREFIX)
  34. set(CMAKE_AUTOMOC_PATH_PREFIX OFF)
  35. endif()
  36. if(NOT DEFINED CMAKE_AUTOMOC_MACRO_NAMES)
  37. set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")
  38. endif()
  39. # basically all general purpose OSs support shared libs
  40. set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  41. set (CMAKE_SKIP_RPATH "NO" CACHE BOOL
  42. "If set, runtime paths are not added when using shared libraries.")
  43. set (CMAKE_SKIP_INSTALL_RPATH "NO" CACHE BOOL
  44. "If set, runtime paths are not added when installing shared libraries, but are added when building.")
  45. set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.")
  46. if(DEFINED ENV{CMAKE_COLOR_DIAGNOSTICS} AND NOT DEFINED CACHE{CMAKE_COLOR_DIAGNOSTICS})
  47. set(CMAKE_COLOR_DIAGNOSTICS $ENV{CMAKE_COLOR_DIAGNOSTICS} CACHE BOOL "Enable colored diagnostics throughout.")
  48. endif()
  49. if(CMAKE_GENERATOR MATCHES "Make")
  50. if(NOT DEFINED CMAKE_COLOR_DIAGNOSTICS)
  51. set(CMAKE_COLOR_MAKEFILE ON CACHE BOOL "Enable/Disable color output during build.")
  52. endif()
  53. mark_as_advanced(CMAKE_COLOR_MAKEFILE)
  54. if(DEFINED CMAKE_RULE_MESSAGES)
  55. set_property(GLOBAL PROPERTY RULE_MESSAGES ${CMAKE_RULE_MESSAGES})
  56. endif()
  57. if(DEFINED CMAKE_TARGET_MESSAGES)
  58. set_property(GLOBAL PROPERTY TARGET_MESSAGES ${CMAKE_TARGET_MESSAGES})
  59. endif()
  60. endif()
  61. if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS AND CMAKE_GENERATOR MATCHES "Ninja|Unix Makefiles")
  62. set(CMAKE_EXPORT_COMPILE_COMMANDS "$ENV{CMAKE_EXPORT_COMPILE_COMMANDS}"
  63. CACHE BOOL "Enable/Disable output of compile commands during generation."
  64. )
  65. mark_as_advanced(CMAKE_EXPORT_COMPILE_COMMANDS)
  66. endif()
  67. if(NOT DEFINED CMAKE_EXPORT_BUILD_DATABASE AND CMAKE_GENERATOR MATCHES "Ninja")
  68. set(CMAKE_EXPORT_BUILD_DATABASE "$ENV{CMAKE_EXPORT_BUILD_DATABASE}"
  69. CACHE BOOL "Enable/Disable output of build database during the build."
  70. )
  71. mark_as_advanced(CMAKE_EXPORT_BUILD_DATABASE)
  72. endif()
  73. # GetDefaultWindowsPrefixBase
  74. #
  75. # Compute the base directory for CMAKE_INSTALL_PREFIX based on:
  76. # - is this 32-bit or 64-bit Windows
  77. # - is this 32-bit or 64-bit CMake running
  78. # - what architecture targets will be built
  79. #
  80. function(GetDefaultWindowsPrefixBase var)
  81. # Try to guess what architecture targets will end up being built as,
  82. # even if CMAKE_SIZEOF_VOID_P is not computed yet... We need to know
  83. # the architecture of the targets being built to choose the right
  84. # default value for CMAKE_INSTALL_PREFIX.
  85. #
  86. if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
  87. set(arch_hint "x64")
  88. elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64")
  89. set(arch_hint "x64")
  90. elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64")
  91. set(arch_hint "ARM64")
  92. elseif("${CMAKE_GENERATOR}" MATCHES "ARM")
  93. set(arch_hint "ARM")
  94. elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM")
  95. set(arch_hint "ARM")
  96. elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  97. set(arch_hint "x64")
  98. elseif("$ENV{LIB}" MATCHES "(amd64|ia64)")
  99. set(arch_hint "x64")
  100. endif()
  101. if(NOT arch_hint)
  102. set(arch_hint "x86")
  103. endif()
  104. # default env in a 64-bit app on Win64:
  105. # ProgramFiles=C:\Program Files
  106. # ProgramFiles(x86)=C:\Program Files (x86)
  107. # ProgramW6432=C:\Program Files
  108. #
  109. # default env in a 32-bit app on Win64:
  110. # ProgramFiles=C:\Program Files (x86)
  111. # ProgramFiles(x86)=C:\Program Files (x86)
  112. # ProgramW6432=C:\Program Files
  113. #
  114. # default env in a 32-bit app on Win32:
  115. # ProgramFiles=C:\Program Files
  116. # ProgramFiles(x86) NOT DEFINED
  117. # ProgramW6432 NOT DEFINED
  118. # By default, use the ProgramFiles env var as the base value of
  119. # CMAKE_INSTALL_PREFIX:
  120. #
  121. set(_PREFIX_ENV_VAR "ProgramFiles")
  122. if ("$ENV{ProgramW6432}" STREQUAL "")
  123. # running on 32-bit Windows
  124. # must be a 32-bit CMake, too...
  125. #message("guess: this is a 32-bit CMake running on 32-bit Windows")
  126. else()
  127. # running on 64-bit Windows
  128. if ("$ENV{ProgramW6432}" STREQUAL "$ENV{ProgramFiles}")
  129. # 64-bit CMake
  130. #message("guess: this is a 64-bit CMake running on 64-bit Windows")
  131. if(NOT "${arch_hint}" STREQUAL "x64")
  132. # building 32-bit targets
  133. set(_PREFIX_ENV_VAR "ProgramFiles(x86)")
  134. endif()
  135. else()
  136. # 32-bit CMake
  137. #message("guess: this is a 32-bit CMake running on 64-bit Windows")
  138. if("${arch_hint}" STREQUAL "x64")
  139. # building 64-bit targets
  140. set(_PREFIX_ENV_VAR "ProgramW6432")
  141. endif()
  142. endif()
  143. endif()
  144. #if("${arch_hint}" STREQUAL "x64")
  145. # message("guess: you are building a 64-bit app")
  146. #else()
  147. # message("guess: you are building a 32-bit app")
  148. #endif()
  149. if(NOT "$ENV{${_PREFIX_ENV_VAR}}" STREQUAL "")
  150. file(TO_CMAKE_PATH "$ENV{${_PREFIX_ENV_VAR}}" _base)
  151. elseif(NOT "$ENV{SystemDrive}" STREQUAL "")
  152. set(_base "$ENV{SystemDrive}/Program Files")
  153. else()
  154. set(_base "C:/Program Files")
  155. endif()
  156. set(${var} "${_base}" PARENT_SCOPE)
  157. endfunction()
  158. # Set a variable to indicate whether the value of CMAKE_INSTALL_PREFIX
  159. # was initialized by the block below. This is useful for user
  160. # projects to change the default prefix while still allowing the
  161. # command line to override it.
  162. if(NOT DEFINED CMAKE_INSTALL_PREFIX AND
  163. NOT DEFINED ENV{CMAKE_INSTALL_PREFIX})
  164. set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT 1)
  165. endif()
  166. if(DEFINED ENV{CMAKE_INSTALL_PREFIX})
  167. set(CMAKE_INSTALL_PREFIX "$ENV{CMAKE_INSTALL_PREFIX}"
  168. CACHE PATH "Install path prefix, prepended onto install directories.")
  169. else()
  170. # If CMAKE_INSTALL_PREFIX env variable is not set,
  171. # choose a default install prefix for this platform.
  172. if(CMAKE_HOST_UNIX)
  173. set(CMAKE_INSTALL_PREFIX "/usr/local"
  174. CACHE PATH "Install path prefix, prepended onto install directories.")
  175. else()
  176. GetDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
  177. set(CMAKE_INSTALL_PREFIX
  178. "${CMAKE_GENERIC_PROGRAM_FILES}/${PROJECT_NAME}"
  179. CACHE PATH "Install path prefix, prepended onto install directories.")
  180. set(CMAKE_GENERIC_PROGRAM_FILES)
  181. endif()
  182. endif()
  183. # Set a variable which will be used as component name in install() commands
  184. # where no COMPONENT has been given:
  185. set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "Unspecified")
  186. mark_as_advanced(
  187. CMAKE_SKIP_RPATH
  188. CMAKE_SKIP_INSTALL_RPATH
  189. CMAKE_VERBOSE_MAKEFILE
  190. )