CMakeGenericSystem.cmake 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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_USING_DEFAULT_SUPPORTED TRUE)
  27. set(CMAKE_AUTOGEN_ORIGIN_DEPENDS ON)
  28. set(CMAKE_AUTOMOC_COMPILER_PREDEFINES ON)
  29. if(NOT DEFINED CMAKE_AUTOMOC_PATH_PREFIX)
  30. set(CMAKE_AUTOMOC_PATH_PREFIX OFF)
  31. endif()
  32. set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")
  33. # basically all general purpose OSs support shared libs
  34. set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
  35. set (CMAKE_SKIP_RPATH "NO" CACHE BOOL
  36. "If set, runtime paths are not added when using shared libraries.")
  37. set (CMAKE_SKIP_INSTALL_RPATH "NO" CACHE BOOL
  38. "If set, runtime paths are not added when installing shared libraries, but are added when building.")
  39. 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.")
  40. if(DEFINED ENV{CMAKE_COLOR_DIAGNOSTICS} AND NOT DEFINED CACHE{CMAKE_COLOR_DIAGNOSTICS})
  41. set(CMAKE_COLOR_DIAGNOSTICS $ENV{CMAKE_COLOR_DIAGNOSTICS} CACHE BOOL "Enable colored diagnostics throughout.")
  42. endif()
  43. if(CMAKE_GENERATOR MATCHES "Make")
  44. if(NOT DEFINED CMAKE_COLOR_DIAGNOSTICS)
  45. set(CMAKE_COLOR_MAKEFILE ON CACHE BOOL "Enable/Disable color output during build.")
  46. endif()
  47. mark_as_advanced(CMAKE_COLOR_MAKEFILE)
  48. if(DEFINED CMAKE_RULE_MESSAGES)
  49. set_property(GLOBAL PROPERTY RULE_MESSAGES ${CMAKE_RULE_MESSAGES})
  50. endif()
  51. if(DEFINED CMAKE_TARGET_MESSAGES)
  52. set_property(GLOBAL PROPERTY TARGET_MESSAGES ${CMAKE_TARGET_MESSAGES})
  53. endif()
  54. endif()
  55. if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS AND CMAKE_GENERATOR MATCHES "Ninja|Unix Makefiles")
  56. set(CMAKE_EXPORT_COMPILE_COMMANDS "$ENV{CMAKE_EXPORT_COMPILE_COMMANDS}"
  57. CACHE BOOL "Enable/Disable output of compile commands during generation."
  58. )
  59. mark_as_advanced(CMAKE_EXPORT_COMPILE_COMMANDS)
  60. endif()
  61. # GetDefaultWindowsPrefixBase
  62. #
  63. # Compute the base directory for CMAKE_INSTALL_PREFIX based on:
  64. # - is this 32-bit or 64-bit Windows
  65. # - is this 32-bit or 64-bit CMake running
  66. # - what architecture targets will be built
  67. #
  68. function(GetDefaultWindowsPrefixBase var)
  69. # Try to guess what architecture targets will end up being built as,
  70. # even if CMAKE_SIZEOF_VOID_P is not computed yet... We need to know
  71. # the architecture of the targets being built to choose the right
  72. # default value for CMAKE_INSTALL_PREFIX.
  73. #
  74. if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
  75. set(arch_hint "x64")
  76. elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64")
  77. set(arch_hint "x64")
  78. elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64")
  79. set(arch_hint "ARM64")
  80. elseif("${CMAKE_GENERATOR}" MATCHES "ARM")
  81. set(arch_hint "ARM")
  82. elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM")
  83. set(arch_hint "ARM")
  84. elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  85. set(arch_hint "x64")
  86. elseif("$ENV{LIB}" MATCHES "(amd64|ia64)")
  87. set(arch_hint "x64")
  88. endif()
  89. if(NOT arch_hint)
  90. set(arch_hint "x86")
  91. endif()
  92. # default env in a 64-bit app on Win64:
  93. # ProgramFiles=C:\Program Files
  94. # ProgramFiles(x86)=C:\Program Files (x86)
  95. # ProgramW6432=C:\Program Files
  96. #
  97. # default env in a 32-bit app on Win64:
  98. # ProgramFiles=C:\Program Files (x86)
  99. # ProgramFiles(x86)=C:\Program Files (x86)
  100. # ProgramW6432=C:\Program Files
  101. #
  102. # default env in a 32-bit app on Win32:
  103. # ProgramFiles=C:\Program Files
  104. # ProgramFiles(x86) NOT DEFINED
  105. # ProgramW6432 NOT DEFINED
  106. # By default, use the ProgramFiles env var as the base value of
  107. # CMAKE_INSTALL_PREFIX:
  108. #
  109. set(_PREFIX_ENV_VAR "ProgramFiles")
  110. if ("$ENV{ProgramW6432}" STREQUAL "")
  111. # running on 32-bit Windows
  112. # must be a 32-bit CMake, too...
  113. #message("guess: this is a 32-bit CMake running on 32-bit Windows")
  114. else()
  115. # running on 64-bit Windows
  116. if ("$ENV{ProgramW6432}" STREQUAL "$ENV{ProgramFiles}")
  117. # 64-bit CMake
  118. #message("guess: this is a 64-bit CMake running on 64-bit Windows")
  119. if(NOT "${arch_hint}" STREQUAL "x64")
  120. # building 32-bit targets
  121. set(_PREFIX_ENV_VAR "ProgramFiles(x86)")
  122. endif()
  123. else()
  124. # 32-bit CMake
  125. #message("guess: this is a 32-bit CMake running on 64-bit Windows")
  126. if("${arch_hint}" STREQUAL "x64")
  127. # building 64-bit targets
  128. set(_PREFIX_ENV_VAR "ProgramW6432")
  129. endif()
  130. endif()
  131. endif()
  132. #if("${arch_hint}" STREQUAL "x64")
  133. # message("guess: you are building a 64-bit app")
  134. #else()
  135. # message("guess: you are building a 32-bit app")
  136. #endif()
  137. if(NOT "$ENV{${_PREFIX_ENV_VAR}}" STREQUAL "")
  138. file(TO_CMAKE_PATH "$ENV{${_PREFIX_ENV_VAR}}" _base)
  139. elseif(NOT "$ENV{SystemDrive}" STREQUAL "")
  140. set(_base "$ENV{SystemDrive}/Program Files")
  141. else()
  142. set(_base "C:/Program Files")
  143. endif()
  144. set(${var} "${_base}" PARENT_SCOPE)
  145. endfunction()
  146. # Set a variable to indicate whether the value of CMAKE_INSTALL_PREFIX
  147. # was initialized by the block below. This is useful for user
  148. # projects to change the default prefix while still allowing the
  149. # command line to override it.
  150. if(NOT DEFINED CMAKE_INSTALL_PREFIX)
  151. set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT 1)
  152. endif()
  153. # Choose a default install prefix for this platform.
  154. if(CMAKE_HOST_UNIX)
  155. set(CMAKE_INSTALL_PREFIX "/usr/local"
  156. CACHE PATH "Install path prefix, prepended onto install directories.")
  157. else()
  158. GetDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
  159. set(CMAKE_INSTALL_PREFIX
  160. "${CMAKE_GENERIC_PROGRAM_FILES}/${PROJECT_NAME}"
  161. CACHE PATH "Install path prefix, prepended onto install directories.")
  162. set(CMAKE_GENERIC_PROGRAM_FILES)
  163. endif()
  164. # Set a variable which will be used as component name in install() commands
  165. # where no COMPONENT has been given:
  166. set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "Unspecified")
  167. mark_as_advanced(
  168. CMAKE_SKIP_RPATH
  169. CMAKE_SKIP_INSTALL_RPATH
  170. CMAKE_VERBOSE_MAKEFILE
  171. )