dcceae51e96ddbd0ec1403b98d545c51dbffb4bd
[reactos.git] / cmake / Platform / Windows-cl.cmake
1 # try to load any previously computed information for C on this platform
2 INCLUDE( ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake OPTIONAL)
3 # try to load any previously computed information for CXX on this platform
4 INCLUDE( ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake OPTIONAL)
5
6 SET(WIN32 1)
7
8 INCLUDE(Platform/cl)
9
10 ############
11 # Detect WDK build environment
12 IF($ENV{DDKBUILDENV} MATCHES "chk")
13 MESSAGE(STATUS "DDK/WDK checked build environment detected.")
14 SET(CMAKE_USE_WDK_ENV 1)
15 ENDIF()
16
17 IF($ENV{DDKBUILDENV} MATCHES "fre")
18 MESSAGE(STATUS "DDK/WDK free build environment detected.")
19 SET(CMAKE_USE_WDK_ENV 1)
20 ENDIF()
21
22 IF(CMAKE_USE_WDK_ENV)
23
24 # Detect output architecture
25 IF(NOT ARCH)
26 IF($ENV{AMD64} MATCHES 1)
27 SET(ARCH amd64)
28 ELSE()
29 SET(ARCH i386)
30 ENDIF()
31 ENDIF()
32
33 # Add library directories
34 STRING(REPLACE * ${ARCH} ATL_LIB_PATH $ENV{ATL_LIB_PATH})
35 STRING(REPLACE * ${ARCH} CRT_LIB_PATH $ENV{CRT_LIB_PATH})
36 STRING(REPLACE * ${ARCH} DDK_LIB_PATH $ENV{DDK_LIB_PATH})
37 STRING(REPLACE * ${ARCH} KMDF_LIB_PATH $ENV{KMDF_LIB_PATH})
38 STRING(REPLACE * ${ARCH} MFC_LIB_PATH $ENV{MFC_LIB_PATH})
39 STRING(REPLACE * ${ARCH} SDK_LIB_PATH $ENV{SDK_LIB_PATH})
40 LINK_DIRECTORIES(${ATL_LIB_PATH}
41 ${CRT_LIB_PATH}
42 ${DDK_LIB_PATH}
43 ${IFSKIT_LIB_PATH}
44 ${KMDF_LIB_PATH}
45 ${MFC_LIB_PATH}
46 ${SDK_LIB_PATH})
47
48 # Add environment variables
49 IF(NOT CMAKE_CROSSCOMPILING)
50 SET(ENV{INCLUDE} "$ENV{CRT_INC_PATH};$ENV{SDK_INC_PATH};$ENV{SDK_INC_PATH}\\crt\\stl60")
51 include_directories($ENV{INCLUDE})
52 SET(ENV{LIBPATH} "${CRT_LIB_PATH};${SDK_LIB_PATH}")
53
54 SET(ENV{USE_MSVCRT} 1)
55 SET(ENV{USE_STL} 1)
56 SET(ENV{STL_VER} 60)
57
58 ENDIF()
59 ENDIF()
60
61 ############
62
63 SET(CMAKE_CREATE_WIN32_EXE /subsystem:windows)
64 SET(CMAKE_CREATE_CONSOLE_EXE /subsystem:console)
65
66 IF(CMAKE_GENERATOR MATCHES "Visual Studio 6")
67 SET (CMAKE_NO_BUILD_TYPE 1)
68 ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 6")
69 IF(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio")
70 SET (CMAKE_NO_BUILD_TYPE 1)
71 SET (CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING
72 "Semicolon separated list of supported configuration types, only supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything else will be ignored.")
73 MARK_AS_ADVANCED(CMAKE_CONFIGURATION_TYPES)
74 ENDIF(NOT CMAKE_NO_BUILD_TYPE AND CMAKE_GENERATOR MATCHES "Visual Studio")
75 # does the compiler support pdbtype and is it the newer compiler
76 IF(CMAKE_GENERATOR MATCHES "Visual Studio 8")
77 SET(CMAKE_COMPILER_2005 1)
78 ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 8")
79
80 # make sure to enable languages after setting configuration types
81 ENABLE_LANGUAGE(RC)
82 SET(CMAKE_COMPILE_RESOURCE "rc <FLAGS> /fo<OBJECT> <SOURCE>")
83
84 # for nmake we need to compute some information about the compiler
85 # that is being used.
86 # the compiler may be free command line, 6, 7, or 71, and
87 # each have properties that must be determined.
88 # to avoid running these tests with each cmake run, the
89 # test results are saved in CMakeCPlatform.cmake, a file
90 # that is automatically copied into try_compile directories
91 # by the global generator.
92 SET(MSVC_IDE 1)
93 IF(CMAKE_GENERATOR MATCHES "Makefiles")
94 SET(MSVC_IDE 0)
95 IF(NOT CMAKE_VC_COMPILER_TESTS_RUN)
96 SET(CMAKE_VC_COMPILER_TESTS 1)
97 SET(testNmakeCLVersionFile
98 "${CMAKE_ROOT}/Modules/CMakeTestNMakeCLVersion.c")
99 STRING(REGEX REPLACE "/" "\\\\" testNmakeCLVersionFile "${testNmakeCLVersionFile}")
100 MESSAGE(STATUS "Check for CL compiler version")
101 SET(CMAKE_TEST_COMPILER ${CMAKE_C_COMPILER})
102 IF (NOT CMAKE_C_COMPILER)
103 SET(CMAKE_TEST_COMPILER ${CMAKE_CXX_COMPILER})
104 ENDIF(NOT CMAKE_C_COMPILER)
105 EXEC_PROGRAM(${CMAKE_TEST_COMPILER}
106 ARGS /nologo -EP \"${testNmakeCLVersionFile}\"
107 OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT
108 RETURN_VALUE CMAKE_COMPILER_RETURN
109 )
110 IF(NOT CMAKE_COMPILER_RETURN)
111 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
112 "Determining the version of compiler passed with the following output:\n"
113 "${CMAKE_COMPILER_OUTPUT}\n\n")
114 STRING(REGEX REPLACE "\n" " " compilerVersion "${CMAKE_COMPILER_OUTPUT}")
115 STRING(REGEX REPLACE ".*VERSION=(.*)" "\\1"
116 compilerVersion "${compilerVersion}")
117 MESSAGE(STATUS "Check for CL compiler version - ${compilerVersion}")
118 SET(MSVC60)
119 SET(MSVC70)
120 SET(MSVC71)
121 SET(MSVC80)
122 SET(CMAKE_COMPILER_2005)
123 IF("${compilerVersion}" LESS 1300)
124 SET(MSVC60 1)
125 SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 1)
126 ENDIF("${compilerVersion}" LESS 1300)
127 IF("${compilerVersion}" EQUAL 1300)
128 SET(MSVC70 1)
129 SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 0)
130 ENDIF("${compilerVersion}" EQUAL 1300)
131 IF("${compilerVersion}" EQUAL 1310)
132 SET(MSVC71 1)
133 SET(CMAKE_COMPILER_SUPPORTS_PDBTYPE 0)
134 ENDIF("${compilerVersion}" EQUAL 1310)
135 IF("${compilerVersion}" EQUAL 1400)
136 SET(MSVC80 1)
137 SET(CMAKE_COMPILER_2005 1)
138 ENDIF("${compilerVersion}" EQUAL 1400)
139 IF("${compilerVersion}" EQUAL 1500)
140 SET(MSVC90 1)
141 ENDIF("${compilerVersion}" EQUAL 1500)
142 IF("${compilerVersion}" EQUAL 1600)
143 SET(MSVC10 1)
144 ENDIF("${compilerVersion}" EQUAL 1600)
145 SET(MSVC_VERSION "${compilerVersion}")
146 ELSE(NOT CMAKE_COMPILER_RETURN)
147 MESSAGE(STATUS "Check for CL compiler version - failed")
148 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
149 "Determining the version of compiler failed with the following output:\n"
150 "${CMAKE_COMPILER_OUTPUT}\n\n")
151 ENDIF(NOT CMAKE_COMPILER_RETURN)
152 # try to figure out if we are running the free command line
153 # tools from Microsoft. These tools do not provide debug libraries,
154 # so the link flags used have to be different.
155 MAKE_DIRECTORY("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp2")
156 SET(testForFreeVCFile
157 "${CMAKE_ROOT}/Modules/CMakeTestForFreeVC.cxx")
158 STRING(REGEX REPLACE "/" "\\\\" testForFreeVCFile "${testForFreeVCFile}")
159 MESSAGE(STATUS "Check if this is a free VC compiler")
160 EXEC_PROGRAM(${CMAKE_TEST_COMPILER} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp2
161 ARGS /nologo /EHsc
162 \"${testForFreeVCFile}\"
163 OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT
164 RETURN_VALUE CMAKE_COMPILER_RETURN
165 )
166 IF(CMAKE_COMPILER_RETURN)
167 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
168 "Determining if this is a free VC compiler failed with the following output:\n"
169 "${CMAKE_COMPILER_OUTPUT}\n\n")
170 MESSAGE(STATUS "Check if this is a free VC compiler - yes1")
171 SET(CMAKE_USING_VC_FREE_TOOLS 1)
172 ELSE(CMAKE_COMPILER_RETURN)
173 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
174 "Determining if this is a free VC compiler passed with the following output:\n"
175 "${CMAKE_COMPILER_OUTPUT}\n\n")
176 MESSAGE(STATUS "Check if this is a free VC compiler - no")
177 SET(CMAKE_USING_VC_FREE_TOOLS 0)
178 ENDIF(CMAKE_COMPILER_RETURN)
179 MAKE_DIRECTORY("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp3")
180 ENDIF(NOT CMAKE_VC_COMPILER_TESTS_RUN)
181 ENDIF(CMAKE_GENERATOR MATCHES "Makefiles")
182
183 IF(MSVC_C_ARCHITECTURE_ID MATCHES 64)
184 SET(CMAKE_CL_64 1)
185 ELSE(MSVC_C_ARCHITECTURE_ID MATCHES 64)
186 SET(CMAKE_CL_64 0)
187 ENDIF(MSVC_C_ARCHITECTURE_ID MATCHES 64)
188 IF(CMAKE_FORCE_WIN64)
189 SET(CMAKE_CL_64 1)
190 ENDIF(CMAKE_FORCE_WIN64)
191
192 IF("${MSVC_VERSION}" GREATER 1599)
193 SET(MSVC_INCREMENTAL_DEFAULT ON)
194 ENDIF()
195
196 # default to Debug builds
197 IF(MSVC_VERSION GREATER 1310)
198 # for 2005 make sure the manifest is put in the dll with mt
199 SET(CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_COMMAND> -E vs_link_dll ${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
200 SET(CMAKE_CXX_CREATE_SHARED_MODULE "<CMAKE_COMMAND> -E vs_link_dll ${CMAKE_CXX_CREATE_SHARED_MODULE}")
201 # create a C shared library
202 SET(CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
203 # create a C shared module just copy the shared library rule
204 SET(CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE}")
205 SET(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_COMMAND> -E vs_link_exe ${CMAKE_CXX_LINK_EXECUTABLE}")
206 SET(CMAKE_C_LINK_EXECUTABLE "<CMAKE_COMMAND> -E vs_link_exe ${CMAKE_C_LINK_EXECUTABLE}")
207
208 SET(CMAKE_BUILD_TYPE_INIT Debug)
209
210 IF(ENV{DDKBUILDENV} OR NOT CMAKE_CROSSCOMPILING)
211 SET (CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od")
212 SET (CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /Zi /Ob0 /Od")
213 ELSE()
214 SET (CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /Zi /Ob0 /Od")
215 SET (CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /Zi /Ob0 /Od")
216 ENDIF()
217
218 SET (CMAKE_CXX_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000 /EHsc /GR")
219 SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/O1 /Ob1 /D NDEBUG")
220 SET (CMAKE_CXX_FLAGS_RELEASE_INIT "/O2 /Ob2 /D NDEBUG")
221 SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/Zi /O2 /Ob1")
222 SET (CMAKE_C_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000")
223 SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "/O1 /Ob1 /D NDEBUG")
224 SET (CMAKE_C_FLAGS_RELEASE_INIT "/O2 /Ob2 /D NDEBUG")
225 SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/Zi /O2 /Ob1")
226 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 ")
227 SET (CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT}")
228 ELSE(MSVC_VERSION GREATER 1310)
229 IF(CMAKE_USING_VC_FREE_TOOLS)
230 MESSAGE(STATUS "Using FREE VC TOOLS, NO DEBUG available")
231 SET(CMAKE_BUILD_TYPE_INIT Release)
232 SET (CMAKE_CXX_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000 /GX /GR")
233 SET (CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /GZ")
234 SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
235 SET (CMAKE_CXX_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
236 SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
237 SET (CMAKE_C_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000")
238 SET (CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /GZ")
239 SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
240 SET (CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
241 SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
242 ELSE(CMAKE_USING_VC_FREE_TOOLS)
243 SET(CMAKE_BUILD_TYPE_INIT Debug)
244 SET (CMAKE_CXX_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000 /GX /GR")
245 SET (CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /GZ")
246 SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/O1 /Ob1 /D NDEBUG")
247 SET (CMAKE_CXX_FLAGS_RELEASE_INIT "/O2 /Ob2 /D NDEBUG")
248 SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/Zi /O2 /Ob1 /D NDEBUG")
249 SET (CMAKE_C_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000")
250 SET (CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /Zi /Ob0 /Od /GZ")
251 SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "/O1 /Ob1 /D NDEBUG")
252 SET (CMAKE_C_FLAGS_RELEASE_INIT "/O2 /Ob2 /D NDEBUG")
253 SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/Zi /O2 /Ob1 /D NDEBUG")
254 ENDIF(CMAKE_USING_VC_FREE_TOOLS)
255 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")
256 ENDIF(MSVC_VERSION GREATER 1310)
257
258 SET(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")
259
260 # executable linker flags
261 SET (CMAKE_LINK_DEF_FILE_FLAG "/DEF:")
262 # set the stack size and the machine type
263 SET(_MACHINE_ARCH_FLAG ${MSVC_C_ARCHITECTURE_ID})
264 IF(NOT _MACHINE_ARCH_FLAG)
265 SET(_MACHINE_ARCH_FLAG ${MSVC_CXX_ARCHITECTURE_ID})
266 ENDIF(NOT _MACHINE_ARCH_FLAG)
267 SET (CMAKE_EXE_LINKER_FLAGS_INIT
268 "${CMAKE_EXE_LINKER_FLAGS_INIT} /STACK:10000000 /machine:${_MACHINE_ARCH_FLAG}")
269
270 # add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype
271 # on versions that support it
272 SET( MSVC_INCREMENTAL_YES_FLAG "")
273 IF(NOT MSVC_INCREMENTAL_DEFAULT)
274 SET( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES")
275 ENDIF()
276
277 IF (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
278 SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}")
279 SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}")
280 ELSE (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
281 SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}")
282 SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}")
283 ENDIF (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
284 # for release and minsize release default to no incremental linking
285 SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT "/INCREMENTAL:NO")
286 SET(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:NO")
287
288 # copy the EXE_LINKER flags to SHARED and MODULE linker flags
289 # shared linker flags
290 SET (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT})
291 SET (CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
292 SET (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT})
293 SET (CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT})
294 SET (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
295 # module linker flags
296 SET (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT})
297 SET (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT})
298 SET (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT})
299 SET (CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT})
300 SET (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
301
302 # save computed information for this platform
303 IF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake")
304 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake.in
305 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCPlatform.cmake IMMEDIATE)
306 ENDIF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake")
307
308 IF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake")
309 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake.in
310 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXPlatform.cmake IMMEDIATE)
311 ENDIF(NOT EXISTS "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake")