[CMAKE]
[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 else()
45 set(CMAKE_CREATE_WIN32_EXE "/subsystem:windows")
46 set(CMAKE_CREATE_CONSOLE_EXE "/subsystem:console")
47 endif()
48
49 if(CMAKE_GENERATOR MATCHES "Visual Studio 6")
50 set (CMAKE_NO_BUILD_TYPE 1)
51 endif()
52 if(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio")
53 set (CMAKE_NO_BUILD_TYPE 1)
54 set (CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING
55 "Semicolon separated list of supported configuration types, only supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything else will be ignored.")
56 mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
57 endif()
58
59 # make sure to enable languages after setting configuration types
60 enable_language(RC)
61 set(CMAKE_COMPILE_RESOURCE "rc <FLAGS> /fo<OBJECT> <SOURCE>")
62
63 if("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
64 set(MSVC_IDE 1)
65 else()
66 set(MSVC_IDE 0)
67 endif()
68
69 if(NOT MSVC_VERSION)
70 if(CMAKE_C_COMPILER_VERSION)
71 set(_compiler_version ${CMAKE_C_COMPILER_VERSION})
72 else()
73 set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION})
74 endif()
75 if("${_compiler_version}" MATCHES "^([0-9]+)\\.([0-9]+)")
76 math(EXPR MSVC_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
77 else()
78 message(FATAL_ERROR "MSVC compiler version not detected properly: ${_compiler_version}")
79 endif()
80
81 set(MSVC10)
82 set(MSVC11)
83 set(MSVC60)
84 set(MSVC70)
85 set(MSVC71)
86 set(MSVC80)
87 set(MSVC90)
88 set(CMAKE_COMPILER_2005)
89 set(CMAKE_COMPILER_SUPPORTS_PDBTYPE)
90 if(NOT "${_compiler_version}" VERSION_LESS 17)
91 set(MSVC11 1)
92 elseif(NOT "${_compiler_version}" VERSION_LESS 16)
93 set(MSVC10 1)
94 elseif(NOT "${_compiler_version}" VERSION_LESS 15)
95 set(MSVC90 1)
96 elseif(NOT "${_compiler_version}" VERSION_LESS 14)
97 set(MSVC80 1)
98 set(CMAKE_COMPILER_2005 1)
99 elseif(NOT "${_compiler_version}" VERSION_LESS 13.10)
100 set(MSVC71 1)
101 elseif(NOT "${_compiler_version}" VERSION_LESS 13)
102 set(MSVC70 1)
103 else()
104 set(MSVC60 1)
105 set(CMAKE_COMPILER_SUPPORTS_PDBTYPE 1)
106 endif()
107 endif()
108
109 if(MSVC_C_ARCHITECTURE_ID MATCHES 64)
110 set(CMAKE_CL_64 1)
111 else()
112 set(CMAKE_CL_64 0)
113 endif()
114 if(CMAKE_FORCE_WIN64 OR CMAKE_FORCE_IA64)
115 set(CMAKE_CL_64 1)
116 endif()
117
118 if("${MSVC_VERSION}" GREATER 1599)
119 set(MSVC_INCREMENTAL_DEFAULT ON)
120 endif()
121
122 # default to Debug builds
123 set(CMAKE_BUILD_TYPE_INIT Debug)
124
125 if(CMAKE_SYSTEM_NAME MATCHES "WindowsCE")
126 string(TOUPPER "${MSVC_C_ARCHITECTURE_ID}" _MSVC_C_ARCHITECTURE_ID_UPPER)
127 string(TOUPPER "${MSVC_CXX_ARCHITECTURE_ID}" _MSVC_CXX_ARCHITECTURE_ID_UPPER)
128
129 if("${CMAKE_SYSTEM_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)")
130 math(EXPR _CE_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
131 elseif("${CMAKE_SYSTEM_VERSION}" STREQUAL "")
132 set(_CE_VERSION "500")
133 else()
134 message(FATAL_ERROR "Invalid Windows CE version: ${CMAKE_SYSTEM_VERSION}")
135 endif()
136
137 set(_PLATFORM_DEFINES "/D_WIN32_WCE=0x${_CE_VERSION} /DUNDER_CE")
138 set(_PLATFORM_DEFINES_C " /D${MSVC_C_ARCHITECTURE_ID} /D_${_MSVC_C_ARCHITECTURE_ID_UPPER}_")
139 set(_PLATFORM_DEFINES_CXX " /D${MSVC_CXX_ARCHITECTURE_ID} /D_${_MSVC_CXX_ARCHITECTURE_ID_UPPER}_")
140
141 set(_RTC1 "")
142 set(_FLAGS_CXX " /GR /EHsc")
143 set(CMAKE_C_STANDARD_LIBRARIES_INIT "coredll.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib")
144 set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:oldnames.lib")
145 else()
146 set(_PLATFORM_DEFINES "/DWIN32")
147
148 if(MSVC_VERSION GREATER 1310)
149 set(_RTC1 "/RTC1")
150 set(_FLAGS_CXX " /GR /EHsc")
151 set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib")
152 else()
153 set(_RTC1 "/GZ")
154 set(_FLAGS_CXX " /GR /GX")
155 set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib")
156 endif()
157 endif()
158
159 set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")
160
161 # executable linker flags
162 set (CMAKE_LINK_DEF_FILE_FLAG "/DEF:")
163 # set the stack size and the machine type
164 set(_MACHINE_ARCH_FLAG ${MSVC_C_ARCHITECTURE_ID})
165 if(NOT _MACHINE_ARCH_FLAG)
166 set(_MACHINE_ARCH_FLAG ${MSVC_CXX_ARCHITECTURE_ID})
167 endif()
168 if(CMAKE_SYSTEM_NAME MATCHES "WindowsCE")
169 if(_MACHINE_ARCH_FLAG MATCHES "ARM")
170 set(_MACHINE_ARCH_FLAG "THUMB")
171 elseif(_MACHINE_ARCH_FLAG MATCHES "SH")
172 set(_MACHINE_ARCH_FLAG "SH4")
173 endif()
174 endif()
175 set (CMAKE_EXE_LINKER_FLAGS_INIT
176 "${CMAKE_EXE_LINKER_FLAGS_INIT} /STACK:10000000 /machine:${_MACHINE_ARCH_FLAG}")
177
178 # add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype
179 # on versions that support it
180 set( MSVC_INCREMENTAL_YES_FLAG "")
181 if(NOT MSVC_INCREMENTAL_DEFAULT)
182 set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES")
183 else()
184 set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL" )
185 endif()
186
187 if (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
188 set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept")
189 set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}")
190 else ()
191 set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug")
192 set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}")
193 endif ()
194 # for release and minsize release default to no incremental linking
195 set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO")
196 set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO")
197
198 # copy the EXE_LINKER flags to SHARED and MODULE linker flags
199 # shared linker flags
200 set (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT})
201 set (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
202 set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
203 set (CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT})
204 set (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
205 # module linker flags
206 set (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT})
207 set (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT})
208 set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT})
209 set (CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT})
210 set (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
211
212 macro(__windows_compiler_msvc lang)
213 if(NOT "${CMAKE_${lang}_COMPILER_VERSION}" VERSION_LESS 14)
214 # for 2005 make sure the manifest is put in the dll with mt
215 set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll ")
216 set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe ")
217 endif()
218 set(CMAKE_${lang}_CREATE_SHARED_LIBRARY "<CMAKE_LINKER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /dll /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <LINK_FLAGS> <LINK_LIBRARIES> ${CMAKE_END_TEMP_FILE}")
219
220 set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY})
221 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_LINKER> /lib ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ")
222
223 set(CMAKE_${lang}_COMPILE_OBJECT
224 "<CMAKE_${lang}_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> /Fo<OBJECT> /Fd<TARGET_PDB> -c <SOURCE>${CMAKE_END_TEMP_FILE}")
225 set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE
226 "<CMAKE_${lang}_COMPILER> > <PREPROCESSED_SOURCE> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO}${_COMPILE_${lang}} <FLAGS> <DEFINES> -E <SOURCE>${CMAKE_END_TEMP_FILE}")
227 set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE
228 "<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}")
229
230 set(CMAKE_${lang}_COMPILER_LINKER_OPTION_FLAG_EXECUTABLE "/link")
231 set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
232 set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_${lang}_COMPILER> ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} <FLAGS> /Fe<TARGET> /Fd<TARGET_PDB> <OBJECTS> /link /implib:<TARGET_IMPLIB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
233
234 set(CMAKE_${lang}_FLAGS_INIT "")
235 set(CMAKE_${lang}_FLAGS_DEBUG_INIT "")
236 set(CMAKE_${lang}_FLAGS_RELEASE_INIT "/MD /O2 /Ob2 /D NDEBUG")
237 set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "/MD /Zi /O2 /Ob1 /D NDEBUG")
238 set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG")
239 endmacro()