CMakeGenericSystem.cmake 6.5 KB

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