[WIN32K]
[reactos.git] / reactos / cmake / Platform / Windows-MSVC.cmake
1
2 #=============================================================================
3 # Copyright 2001-2012 Kitware, Inc.
4 #
5 # Distributed under the OSI-approved BSD License (the "License");
6 # see accompanying file Copyright.txt for details.
7 #
8 # This software is distributed WITHOUT ANY WARRANTY; without even the
9 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # See the License for more information.
11 #=============================================================================
12 # (To distribute this file outside of CMake, substitute the full
13 # License text for the above reference.)
14
15 # This module is shared by multiple languages; use include blocker.
16 if(__WINDOWS_MSVC)
17 return()
18 endif()
19 set(__WINDOWS_MSVC 1)
20
21 set(CMAKE_LIBRARY_PATH_FLAG "-LIBPATH:")
22 set(CMAKE_LINK_LIBRARY_FLAG "")
23 set(MSVC 1)
24
25 # hack: if a new cmake (which uses CMAKE_LINKER) runs on an old build tree
26 # (where link was hardcoded) and where CMAKE_LINKER isn't in the cache
27 # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
28 # hardcode CMAKE_LINKER here to link, so it behaves as it did before, Alex
29 if(NOT DEFINED CMAKE_LINKER)
30 set(CMAKE_LINKER link)
31 endif()
32
33 if(CMAKE_VERBOSE_MAKEFILE)
34 set(CMAKE_CL_NOLOGO)
35 else()
36 set(CMAKE_CL_NOLOGO "/nologo")
37 endif()
38
39 set(WIN32 1)
40
41 if(CMAKE_SYSTEM_NAME MATCHES "WindowsCE")
42 set(CMAKE_CREATE_WIN32_EXE "/subsystem:windowsce /entry:WinMainCRTStartup")
43 set(CMAKE_CREATE_CONSOLE_EXE "/subsystem:windowsce /entry:mainACRTStartup")
44 set(WINCE 1)
45 else()
46 set(CMAKE_CREATE_WIN32_EXE "/subsystem:windows")
47 set(CMAKE_CREATE_CONSOLE_EXE "/subsystem:console")
48 endif()
49
50 if(CMAKE_GENERATOR MATCHES "Visual Studio 6")
51 set (CMAKE_NO_BUILD_TYPE 1)
52 endif()
53 if(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio")
54 set (CMAKE_NO_BUILD_TYPE 1)
55 set (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING
56 "Semicolon separated list of supported configuration types, only supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything else will be ignored.")
57 mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
58 endif()
59
60 # make sure to enable languages after setting configuration types
61 enable_language(RC)
62 set(CMAKE_COMPILE_RESOURCE "rc <FLAGS> /fo<OBJECT> <SOURCE>")
63
64 if("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
65 set(MSVC_IDE 1)
66 else()
67 set(MSVC_IDE 0)
68 endif()
69
70 if(NOT MSVC_VERSION)
71 if(CMAKE_C_COMPILER_VERSION)
72 set(_compiler_version ${CMAKE_C_COMPILER_VERSION})
73 else()
74 set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION})
75 endif()
76 if("${_compiler_version}" MATCHES "^([0-9]+)\\.([0-9]+)")
77 math(EXPR MSVC_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
78 else()
79 message(FATAL_ERROR "MSVC compiler version not detected properly: ${_compiler_version}")
80 endif()
81
82 set(MSVC10)
83 set(MSVC11)
84 set(MSVC12)
85 set(MSVC60)
86 set(MSVC70)
87 set(MSVC71)
88 set(MSVC80)
89 set(MSVC90)
90 set(CMAKE_COMPILER_2005)
91 set(CMAKE_COMPILER_SUPPORTS_PDBTYPE)
92 if(NOT "${_compiler_version}" VERSION_LESS 18)
93 set(MSVC12 1)
94 elseif(NOT "${_compiler_version}" VERSION_LESS 17)
95 set(MSVC11 1)
96 elseif(NOT "${_compiler_version}" VERSION_LESS 16)
97 set(MSVC10 1)
98 elseif(NOT "${_compiler_version}" VERSION_LESS 15)
99 set(MSVC90 1)
100 elseif(NOT "${_compiler_version}" VERSION_LESS 14)
101 set(MSVC80 1)
102 set(CMAKE_COMPILER_2005 1)
103 elseif(NOT "${_compiler_version}" VERSION_LESS 13.10)
104 set(MSVC71 1)
105 elseif(NOT "${_compiler_version}" VERSION_LESS 13)
106 set(MSVC70 1)
107 else()
108 set(MSVC60 1)
109 set(CMAKE_COMPILER_SUPPORTS_PDBTYPE 1)
110 endif()
111 endif()
112
113 if(MSVC_C_ARCHITECTURE_ID MATCHES 64 OR MSVC_CXX_ARCHITECTURE_ID MATCHES 64)
114 set(CMAKE_CL_64 1)
115 else()
116 set(CMAKE_CL_64 0)
117 endif()
118 if(CMAKE_FORCE_WIN64 OR CMAKE_FORCE_IA64)
119 set(CMAKE_CL_64 1)
120 endif()
121
122 if(MSVC_VERSION GREATER 1599)
123 set(MSVC_INCREMENTAL_DEFAULT ON)
124 endif()
125
126 # default to Debug builds
127 set(CMAKE_BUILD_TYPE_INIT Debug)
128
129 if(CMAKE_SYSTEM_NAME MATCHES "WindowsCE")
130 string(TOUPPER "${MSVC_C_ARCHITECTURE_ID}" _MSVC_C_ARCHITECTURE_ID_UPPER)
131 string(TOUPPER "${MSVC_CXX_ARCHITECTURE_ID}" _MSVC_CXX_ARCHITECTURE_ID_UPPER)
132
133 if("${CMAKE_SYSTEM_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)")
134 math(EXPR _CE_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
135 elseif("${CMAKE_SYSTEM_VERSION}" STREQUAL "")
136 set(_CE_VERSION "500")
137 else()
138 message(FATAL_ERROR "Invalid Windows CE version: ${CMAKE_SYSTEM_VERSION}")
139 endif()
140
141 set(_PLATFORM_DEFINES "/D_WIN32_WCE=0x${_CE_VERSION} /DUNDER_CE")
142 set(_PLATFORM_DEFINES_C " /D${MSVC_C_ARCHITECTURE_ID} /D_${_MSVC_C_ARCHITECTURE_ID_UPPER}_")
143 set(_PLATFORM_DEFINES_CXX " /D${MSVC_CXX_ARCHITECTURE_ID} /D_${_MSVC_CXX_ARCHITECTURE_ID_UPPER}_")
144
145 set(_RTC1 "")
146 set(_FLAGS_CXX " /GR /EHsc")
147 set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib")
148 set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib")
149 else()
150 set(_PLATFORM_DEFINES "/DWIN32")
151
152 if(MSVC_VERSION GREATER 1310)
153 set(_RTC1 "/RTC1")
154 set(_FLAGS_CXX " /GR /EHsc")
155 set(CMAKE_C_STANDARD_LIBRARIES_INIT "")
156 else()
157 set(_RTC1 "/GZ")
158 set(_FLAGS_CXX " /GR /GX")
159 set(CMAKE_C_STANDARD_LIBRARIES_INIT "")
160 endif()
161 endif()
162
163 set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")
164
165 # executable linker flags
166 set (CMAKE_LINK_DEF_FILE_FLAG "/DEF:")
167 # set the machine type
168 set(_MACHINE_ARCH_FLAG ${MSVC_C_ARCHITECTURE_ID})
169 if(NOT _MACHINE_ARCH_FLAG)
170 set(_MACHINE_ARCH_FLAG ${MSVC_CXX_ARCHITECTURE_ID})
171 endif()
172 if(CMAKE_SYSTEM_NAME MATCHES "WindowsCE")
173 if(_MACHINE_ARCH_FLAG MATCHES "ARM")
174 set(_MACHINE_ARCH_FLAG "THUMB")
175 elseif(_MACHINE_ARCH_FLAG MATCHES "SH")
176 set(_MACHINE_ARCH_FLAG "SH4")
177 endif()
178 endif()
179 set (CMAKE_EXE_LINKER_FLAGS_INIT
180 "${CMAKE_EXE_LINKER_FLAGS_INIT} /machine:${_MACHINE_ARCH_FLAG} /MANIFEST:NO")
181
182 # add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype
183 # on versions that support it
184 set( MSVC_INCREMENTAL_YES_FLAG "")
185 if(NOT MSVC_INCREMENTAL_DEFAULT)
186 set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES")
187 else()
188 set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL" )
189 endif()
190
191 if (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
192 set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept")
193 set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}")
194 else ()
195 set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug")
196 set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}")
197 endif ()
198 # for release and minsize release default to no incremental linking
199 set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO")
200 set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO")
201
202 # copy the EXE_LINKER flags to SHARED and MODULE linker flags
203 # shared linker flags
204 set (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT})
205 set (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
206 set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
207 set (CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT})
208 set (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
209 # module linker flags
210 set (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT})
211 set (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT})
212 set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT})
213 set (CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT})
214 set (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
215
216 macro(__windows_compiler_msvc lang)
217 if(NOT "${CMAKE_${lang}_COMPILER_VERSION}" VERSION_LESS 14)
218 # for 2005 make sure the manifest is put in the dll with mt
219 set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll ")
220 set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe ")
221 endif()
222 set(CMAKE_${lang}_CREATE_SHARED_LIBRARY "<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /pdb:<TARGET_PDB> /dll /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <LINK_FLAGS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
223
224 set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY})
225 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_LINKER> /lib ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ")
226
227 set(CMAKE_${lang}_COMPILE_OBJECT
228 "<CMAKE_${lang}_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> /Fo<OBJECT> /Fd<OBJECT_DIR>/ -c <SOURCE>${CMAKE_END_TEMP_FILE}")
229 set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE
230 "<CMAKE_${lang}_COMPILER> > <PREPROCESSED_SOURCE> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> -E <SOURCE>${CMAKE_END_TEMP_FILE}")
231 set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE
232 "<CMAKE_${lang}_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> /FoNUL /FAs /Fa<ASSEMBLY_SOURCE> /c <SOURCE>${CMAKE_END_TEMP_FILE}")
233
234 set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
235 set(CMAKE_${lang}_LINK_EXECUTABLE
236 "${_CMAKE_VS_LINK_EXE}<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /pdb:<TARGET_PDB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
237
238 set(CMAKE_${lang}_FLAGS_INIT "")
239 set(CMAKE_${lang}_FLAGS_DEBUG_INIT "")
240 set(CMAKE_${lang}_FLAGS_RELEASE_INIT "/MD /O2 /Ob2 /D NDEBUG")
241 set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "/MD /Zi /O2 /Ob1 /D NDEBUG")
242 set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG")
243 endmacro()