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