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