4705b3cae99f7e260bc78df678878b84d30919ba
[reactos.git] / sdk / cmake / msvc.cmake
1
2 #if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
3 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
4 # no optimization
5 add_compile_flags("/Ob0 /Od")
6 elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
7 add_compile_flags("/Ox /Ob2 /Ot /Oy /GT /GF")
8 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF")
9 elseif(OPTIMIZE STREQUAL "1")
10 add_definitions(/O1)
11 elseif(OPTIMIZE STREQUAL "2")
12 add_definitions(/O2)
13 elseif(OPTIMIZE STREQUAL "3")
14 add_definitions(/Ot /Ox /GS-)
15 elseif(OPTIMIZE STREQUAL "4")
16 add_definitions(/Os /Ox /GS-)
17 elseif(OPTIMIZE STREQUAL "5")
18 add_definitions(/GF /Gy /Ob2 /Os /Ox /GS-)
19 endif()
20
21 # Enable function level linking and comdat folding
22 add_compile_flags("/Gy")
23 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF /OPT:ICF")
24 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF")
25
26 if(ARCH STREQUAL "i386")
27 add_definitions(/DWIN32 /D_WINDOWS)
28 endif()
29
30 add_definitions(/Dinline=__inline /D__STDC__=1)
31
32 add_compile_flags("/X /GR- /EHs-c- /GS- /Zl /W3")
33
34 # HACK: for VS 11+ we need to explicitly disable SSE, which is off by
35 # default for older compilers. See CORE-6507
36 if(MSVC_VERSION GREATER 1699 AND ARCH STREQUAL "i386")
37 add_compile_flags("/arch:IA32")
38 endif ()
39
40 # VS 12+ requires /FS when used in parallel compilations
41 if(MSVC_VERSION GREATER 1799 AND NOT MSVC_IDE)
42 add_compile_flags("/FS")
43 endif ()
44
45 # VS14+ tries to use thread-safe initialization
46 if(MSVC_VERSION GREATER 1899)
47 add_compile_flags("/Zc:threadSafeInit-")
48 endif ()
49
50 # Disable overly sensitive warnings as well as those that generally aren't
51 # useful to us.
52 # - C4244: implicit integer truncation
53 # - C4290: C++ exception specification ignored
54 # - C4800: forcing value to bool 'true' or 'false' (performance warning)
55 # - C4200: nonstandard extension used : zero-sized array in struct/union
56 # - C4214: nonstandard extension used : bit field types other than int
57 add_compile_flags("/wd4244 /wd4290 /wd4800 /wd4200 /wd4214")
58
59 # FIXME: Temporarily disable C4018 until we fix more of the others. CORE-10113
60 add_compile_flags("/wd4018")
61
62 # The following warnings are treated as errors:
63 # - C4013: implicit function declaration
64 # - C4020: too many actual parameters
65 # - C4022: pointer type mismatch for parameter
66 # - TODO: C4028: formal parameter different from declaration
67 # - C4047: different level of indirection
68 # - TODO: C4090: different 'modifier' qualifiers (for C programs only;
69 # for C++ programs, the compiler error C2440 is issued)
70 # - C4098: void function returning a value
71 # - C4113: parameter lists differ
72 # - C4129: unrecognized escape sequence
73 # - TODO: C4133: incompatible types
74 # - C4163: 'identifier': not available as an intrinsic function
75 # - C4229: modifiers on data are ignored
76 # - C4700: uninitialized variable usage
77 # - C4603: macro is not defined or definition is different after precompiled header use
78 # - C4716: function must return a value
79 add_compile_flags("/we4013 /we4020 /we4022 /we4047 /we4098 /we4113 /we4129 /we4163 /we4229 /we4700 /we4603 /we4716")
80
81 # - C4189: local variable initialized but not referenced
82 # Not in Release mode and not with MSVC 2010
83 if((NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND (NOT MSVC_VERSION LESS 1700))
84 add_compile_flags("/we4189")
85 endif()
86
87 # Enable warnings above the default level, but don't treat them as errors:
88 # - C4115: named type definition in parentheses
89 add_compile_flags("/w14115")
90
91 # Debugging
92 #if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
93 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
94 if(NOT (_PREFAST_ OR _VS_ANALYZE_))
95 add_compile_flags("/Zi")
96 endif()
97 #elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
98 elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
99 add_definitions("/D NDEBUG")
100 endif()
101
102 # Hotpatchable images
103 if(ARCH STREQUAL "i386")
104 add_compile_flags("/hotpatch")
105 set(_hotpatch_link_flag "/FUNCTIONPADMIN:5")
106 elseif(ARCH STREQUAL "amd64")
107 set(_hotpatch_link_flag "/FUNCTIONPADMIN:6")
108 endif()
109
110 if(MSVC_IDE AND (NOT DEFINED USE_FOLDER_STRUCTURE))
111 set(USE_FOLDER_STRUCTURE TRUE)
112 endif()
113
114 if(NOT DEFINED RUNTIME_CHECKS)
115 set(RUNTIME_CHECKS FALSE)
116 endif()
117
118 if(RUNTIME_CHECKS)
119 add_definitions(-D__RUNTIME_CHECKS__)
120 add_compile_flags("/RTC1")
121 endif()
122
123 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag}")
124 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE /IGNORE:4104 ${_hotpatch_link_flag}")
125 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag}")
126
127 if(CMAKE_DISABLE_NINJA_DEPSLOG)
128 set(cl_includes_flag "")
129 else()
130 set(cl_includes_flag "/showIncludes")
131 endif()
132
133 if(MSVC_IDE AND (CMAKE_VERSION MATCHES "ReactOS"))
134 # For VS builds we'll only have en-US in resource files
135 add_definitions(/DLANGUAGE_EN_US)
136 else()
137 # Only VS 10+ resource compiler supports /nologo
138 if(MSVC_VERSION GREATER 1599)
139 set(rc_nologo_flag "/nologo")
140 else()
141 set(rc_nologo_flag)
142 endif()
143 if(CMAKE_VERSION VERSION_LESS 3.4.0)
144 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_nologo_flag} <FLAGS> <DEFINES> ${I18N_DEFS} /fo<OBJECT> <SOURCE>")
145 if(ARCH STREQUAL "arm")
146 set(CMAKE_ASM_COMPILE_OBJECT
147 "cl ${cl_includes_flag} /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm <FLAGS> <DEFINES> /D__ASM__ /D_USE_ML /EP /c <SOURCE> > <OBJECT>.tmp"
148 "<CMAKE_ASM_COMPILER> -nologo -o <OBJECT> <OBJECT>.tmp")
149 else()
150 set(CMAKE_ASM_COMPILE_OBJECT
151 "cl ${cl_includes_flag} /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm <FLAGS> <DEFINES> /D__ASM__ /D_USE_ML /EP /c <SOURCE> > <OBJECT>.tmp"
152 "<CMAKE_ASM_COMPILER> /nologo /Cp /Fo<OBJECT> /c /Ta <OBJECT>.tmp")
153 endif()
154 else()
155 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_nologo_flag} <INCLUDES> <FLAGS> <DEFINES> ${I18N_DEFS} /fo<OBJECT> <SOURCE>")
156 if(ARCH STREQUAL "arm")
157 set(CMAKE_ASM_COMPILE_OBJECT
158 "cl ${cl_includes_flag} /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm <INCLUDES> <FLAGS> <DEFINES> /D__ASM__ /D_USE_ML /EP /c <SOURCE> > <OBJECT>.tmp"
159 "<CMAKE_ASM_COMPILER> -nologo -o <OBJECT> <OBJECT>.tmp")
160 else()
161 set(CMAKE_ASM_COMPILE_OBJECT
162 "cl ${cl_includes_flag} /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm <INCLUDES> <FLAGS> <DEFINES> /D__ASM__ /D_USE_ML /EP /c <SOURCE> > <OBJECT>.tmp"
163 "<CMAKE_ASM_COMPILER> /nologo /Cp /Fo<OBJECT> /c /Ta <OBJECT>.tmp")
164 endif()
165 endif()
166 endif()
167
168 if(_VS_ANALYZE_)
169 message("VS static analysis enabled!")
170 add_compile_flags("/analyze")
171 elseif(_PREFAST_)
172 message("PREFAST enabled!")
173 if(CMAKE_VERSION VERSION_LESS 3.4.0)
174 set(CMAKE_C_COMPILE_OBJECT "prefast <CMAKE_C_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} <FLAGS> <DEFINES> /Fo<OBJECT> -c <SOURCE>${CMAKE_END_TEMP_FILE}"
175 "prefast LIST")
176 set(CMAKE_CXX_COMPILE_OBJECT "prefast <CMAKE_CXX_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} <FLAGS> <DEFINES> /TP /Fo<OBJECT> -c <SOURCE>${CMAKE_END_TEMP_FILE}"
177 "prefast LIST")
178 set(CMAKE_C_LINK_EXECUTABLE
179 "<CMAKE_C_COMPILER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} <FLAGS> /Fe<TARGET> -link /implib:<TARGET_IMPLIB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
180 set(CMAKE_CXX_LINK_EXECUTABLE
181 "<CMAKE_CXX_COMPILER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} <FLAGS> /Fe<TARGET> -link /implib:<TARGET_IMPLIB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
182 else()
183 set(CMAKE_C_COMPILE_OBJECT "prefast <CMAKE_C_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} <INCLUDES> <FLAGS> <DEFINES> /Fo<OBJECT> -c <SOURCE>${CMAKE_END_TEMP_FILE}"
184 "prefast LIST")
185 set(CMAKE_CXX_COMPILE_OBJECT "prefast <CMAKE_CXX_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} <INCLUDES> <FLAGS> <DEFINES> /TP /Fo<OBJECT> -c <SOURCE>${CMAKE_END_TEMP_FILE}"
186 "prefast LIST")
187 set(CMAKE_C_LINK_EXECUTABLE
188 "<CMAKE_C_COMPILER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} <INCLUDES> <FLAGS> /Fe<TARGET> -link /implib:<TARGET_IMPLIB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
189 set(CMAKE_CXX_LINK_EXECUTABLE
190 "<CMAKE_CXX_COMPILER> ${CMAKE_CL_NOLOGO} <OBJECTS> ${CMAKE_START_TEMP_FILE} <INCLUDES> <FLAGS> /Fe<TARGET> -link /implib:<TARGET_IMPLIB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${CMAKE_END_TEMP_FILE}")
191 endif()
192 endif()
193
194 set(CMAKE_RC_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY})
195 set(CMAKE_ASM_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY})
196 set(CMAKE_ASM_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY})
197
198 if(PCH)
199 macro(add_pch _target _pch _sources)
200
201 # Workaround for the MSVC toolchain (MSBUILD) /MP bug
202 set(_temp_gch ${CMAKE_CURRENT_BINARY_DIR}/${_target}.pch)
203 if(MSVC_IDE)
204 file(TO_NATIVE_PATH ${_temp_gch} _gch)
205 else()
206 set(_gch ${_temp_gch})
207 endif()
208
209 if(IS_CPP)
210 set(_pch_language CXX)
211 set(_cl_lang_flag "/TP")
212 else()
213 set(_pch_language C)
214 set(_cl_lang_flag "/TC")
215 endif()
216
217 if(MSVC_IDE)
218 set(_pch_path_name_flag "/Fp${_gch}")
219 endif()
220
221 # Build the precompiled header
222 # HEADER_FILE_ONLY FALSE: force compiling the header
223 set_source_files_properties(${_pch} PROPERTIES
224 HEADER_FILE_ONLY FALSE
225 LANGUAGE ${_pch_language}
226 COMPILE_FLAGS "${_cl_lang_flag} /Yc /Fp${_gch}"
227 OBJECT_OUTPUTS ${_gch})
228
229 # Prevent a race condition related to writing to the PDB files between the PCH and the excluded list of source files
230 get_target_property(_target_sources ${_target} SOURCES)
231 list(REMOVE_ITEM _target_sources ${_pch})
232 foreach(_target_src ${_target_sources})
233 set_property(SOURCE ${_target_src} APPEND PROPERTY OBJECT_DEPENDS ${_gch})
234 endforeach()
235
236 # Use the precompiled header with the specified source files, skipping the pch itself
237 list(REMOVE_ITEM ${_sources} ${_pch})
238 foreach(_src ${${_sources}})
239 set_property(SOURCE ${_src} APPEND_STRING PROPERTY COMPILE_FLAGS " /FI${_gch} /Yu${_gch} ${_pch_path_name_flag}")
240 endforeach()
241 endmacro()
242 else()
243 macro(add_pch _target _pch _sources)
244 endmacro()
245 endif()
246
247 function(set_entrypoint _module _entrypoint)
248 if(${_entrypoint} STREQUAL "0")
249 add_target_link_flags(${_module} "/NOENTRY")
250 elseif(ARCH STREQUAL "i386")
251 set(_entrysymbol ${_entrypoint})
252 if(${ARGC} GREATER 2)
253 set(_entrysymbol ${_entrysymbol}@${ARGV2})
254 endif()
255 add_target_link_flags(${_module} "/ENTRY:${_entrysymbol}")
256 else()
257 add_target_link_flags(${_module} "/ENTRY:${_entrypoint}")
258 endif()
259 endfunction()
260
261 function(set_subsystem MODULE SUBSYSTEM)
262 string(TOUPPER ${SUBSYSTEM} _subsystem)
263 if(ARCH STREQUAL "amd64")
264 add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},5.02")
265 elseif(ARCH STREQUAL "arm")
266 add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},6.02")
267 else()
268 add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},5.01")
269 endif()
270 endfunction()
271
272 function(set_image_base MODULE IMAGE_BASE)
273 add_target_link_flags(${MODULE} "/BASE:${IMAGE_BASE}")
274 endfunction()
275
276 function(set_module_type_toolchain MODULE TYPE)
277 if(CPP_USE_STL)
278 if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver"))
279 message(FATAL_ERROR "Use of STL in kernelmodedriver or wdmdriver type module prohibited")
280 endif()
281 target_link_libraries(${MODULE} cpprt stlport oldnames)
282 elseif(CPP_USE_RT)
283 target_link_libraries(${MODULE} cpprt)
284 endif()
285 if((${TYPE} STREQUAL "win32dll") OR (${TYPE} STREQUAL "win32ocx") OR (${TYPE} STREQUAL "cpl"))
286 add_target_link_flags(${MODULE} "/DLL")
287 elseif(${TYPE} STREQUAL "kernelmodedriver")
288 # Disable linker warning 4078 (multiple sections found with different attributes) for INIT section use
289 add_target_link_flags(${MODULE} "/DRIVER /IGNORE:4078")
290 elseif(${TYPE} STREQUAL "wdmdriver")
291 add_target_link_flags(${MODULE} "/DRIVER:WDM /IGNORE:4078")
292 endif()
293
294 if(RUNTIME_CHECKS)
295 target_link_libraries(${MODULE} runtmchk)
296 endif()
297
298 endfunction()
299
300 # Define those for having real libraries
301 set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "LINK /LIB /NOLOGO <LINK_FLAGS> /OUT:<TARGET> <OBJECTS>")
302
303 if(ARCH STREQUAL "arm")
304 set(CMAKE_STUB_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -nologo -o <OBJECT> <SOURCE>")
305 else()
306 set(CMAKE_STUB_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> /nologo /Cp /Fo<OBJECT> /c /Ta <SOURCE>")
307 endif()
308
309 function(add_delay_importlibs _module)
310 get_target_property(_module_type ${_module} TYPE)
311 if(_module_type STREQUAL "STATIC_LIBRARY")
312 message(FATAL_ERROR "Cannot add delay imports to a static library")
313 endif()
314 foreach(_lib ${ARGN})
315 add_target_link_flags(${_module} "/DELAYLOAD:${_lib}.dll")
316 target_link_libraries(${_module} lib${_lib})
317 endforeach()
318 target_link_libraries(${_module} delayimp)
319 endfunction()
320
321 function(generate_import_lib _libname _dllname _spec_file)
322
323 set(_def_file ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_exp.def)
324 set(_asm_stubs_file ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_stubs.asm)
325
326 # Generate the asm stub file and the def file for import library
327 add_custom_command(
328 OUTPUT ${_asm_stubs_file} ${_def_file}
329 COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} --implib -n=${_dllname} -d=${_def_file} -l=${_asm_stubs_file} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
330 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
331
332 if(MSVC_IDE)
333 # Compile the generated asm stub file
334 if(ARCH STREQUAL "arm")
335 set(_asm_stub_command ${CMAKE_ASM_COMPILER} -nologo -o ${_asm_stubs_file}.obj ${_asm_stubs_file})
336 else()
337 set(_asm_stub_command ${CMAKE_ASM_COMPILER} /Cp /Fo${_asm_stubs_file}.obj /c /Ta ${_asm_stubs_file})
338 endif()
339 add_custom_command(
340 OUTPUT ${_asm_stubs_file}.obj
341 COMMAND ${_asm_stub_command}
342 DEPENDS ${_asm_stubs_file})
343 else()
344 # Be clear about the "language"
345 # Thanks MS for creating a stupid linker
346 set_source_files_properties(${_asm_stubs_file} PROPERTIES LANGUAGE "STUB_ASM")
347 endif()
348
349 # Add our library
350 if(MSVC_IDE)
351 add_library(${_libname} STATIC EXCLUDE_FROM_ALL ${_asm_stubs_file}.obj)
352 set_source_files_properties(${_asm_stubs_file}.obj PROPERTIES EXTERNAL_OBJECT 1)
353 set_target_properties(${_libname} PROPERTIES LINKER_LANGUAGE "C")
354 else()
355 # NOTE: as stub file and def file are generated in one pass, depending on one is like depending on the other
356 add_library(${_libname} STATIC EXCLUDE_FROM_ALL ${_asm_stubs_file})
357 # set correct "link rule"
358 set_target_properties(${_libname} PROPERTIES LINKER_LANGUAGE "IMPLIB")
359 endif()
360 set_target_properties(${_libname} PROPERTIES STATIC_LIBRARY_FLAGS "/DEF:${_def_file}")
361 endfunction()
362
363 if(ARCH STREQUAL "amd64")
364 # This is NOT a typo.
365 # See https://software.intel.com/en-us/forums/topic/404643
366 add_definitions(/D__x86_64)
367 set(SPEC2DEF_ARCH x86_64)
368 elseif(ARCH STREQUAL "arm")
369 add_definitions(/D__arm__)
370 set(SPEC2DEF_ARCH arm)
371 else()
372 set(SPEC2DEF_ARCH i386)
373 endif()
374 function(spec2def _dllname _spec_file)
375
376 cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS" "" "" ${ARGN})
377
378 # Get library basename
379 get_filename_component(_file ${_dllname} NAME_WE)
380
381 # Error out on anything else than spec
382 if(NOT ${_spec_file} MATCHES ".*\\.spec")
383 message(FATAL_ERROR "spec2def only takes spec files as input.")
384 endif()
385
386 # Generate exports def and C stubs file for the DLL
387 add_custom_command(
388 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
389 COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
390 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
391
392 if(__spec2def_ADD_IMPORTLIB)
393 generate_import_lib(lib${_file} ${_dllname} ${_spec_file})
394 if(__spec2def_NO_PRIVATE_WARNINGS)
395 add_target_property(lib${_file} STATIC_LIBRARY_FLAGS "/ignore:4104")
396 endif()
397 endif()
398 endfunction()
399
400 macro(macro_mc FLAG FILE)
401 set(COMMAND_MC ${CMAKE_MC_COMPILER} -u ${FLAG} -b -h ${CMAKE_CURRENT_BINARY_DIR}/ -r ${CMAKE_CURRENT_BINARY_DIR}/ ${FILE})
402 endmacro()
403
404 # PSEH workaround
405 set(PSEH_LIB "pseh")
406
407 # Use a full path for the x86 version of ml when using x64 VS.
408 # It's not a problem when using the DDK/WDK because, in x64 mode,
409 # both the x86 and x64 versions of ml are available.
410 if((ARCH STREQUAL "amd64") AND (DEFINED ENV{VCToolsInstallDir}))
411 set(CMAKE_ASM16_COMPILER $ENV{VCToolsInstallDir}/bin/HostX86/x86/ml.exe)
412 elseif((ARCH STREQUAL "amd64") AND (DEFINED ENV{VCINSTALLDIR}))
413 set(CMAKE_ASM16_COMPILER $ENV{VCINSTALLDIR}/bin/ml.exe)
414 elseif(ARCH STREQUAL "arm")
415 set(CMAKE_ASM16_COMPILER armasm.exe)
416 else()
417 set(CMAKE_ASM16_COMPILER ml.exe)
418 endif()
419
420 function(CreateBootSectorTarget _target_name _asm_file _binary_file _base_address)
421 set(_object_file ${_binary_file}.obj)
422 set(_temp_file ${_binary_file}.tmp)
423
424 add_custom_command(
425 OUTPUT ${_temp_file}
426 COMMAND ${CMAKE_C_COMPILER} /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm /I${REACTOS_SOURCE_DIR}/boot/freeldr /D__ASM__ /D_USE_ML /EP /c ${_asm_file} > ${_temp_file}
427 DEPENDS ${_asm_file})
428
429 if(ARCH STREQUAL "arm")
430 set(_asm16_command ${CMAKE_ASM16_COMPILER} -nologo -o ${_object_file} ${_temp_file})
431 else()
432 set(_asm16_command ${CMAKE_ASM16_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_temp_file})
433 endif()
434
435 add_custom_command(
436 OUTPUT ${_object_file}
437 COMMAND ${_asm16_command}
438 DEPENDS ${_temp_file})
439
440 add_custom_command(
441 OUTPUT ${_binary_file}
442 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
443 DEPENDS ${_object_file} native-obj2bin)
444
445 set_source_files_properties(${_object_file} ${_temp_file} ${_binary_file} PROPERTIES GENERATED TRUE)
446
447 add_custom_target(${_target_name} ALL DEPENDS ${_binary_file})
448 endfunction()
449
450 function(allow_warnings __module)
451 endfunction()
452
453 macro(add_asm_files _target)
454 if(MSVC_IDE AND (CMAKE_VERSION MATCHES "ReactOS"))
455 get_defines(_directory_defines)
456 get_includes(_directory_includes)
457 get_directory_property(_defines COMPILE_DEFINITIONS)
458 foreach(_source_file ${ARGN})
459 get_filename_component(_source_file_base_name ${_source_file} NAME_WE)
460 get_filename_component(_source_file_full_path ${_source_file} ABSOLUTE)
461 set(_preprocessed_asm_file ${CMAKE_CURRENT_BINARY_DIR}/asm/${_source_file_base_name}_${_target}.tmp)
462 set(_object_file ${CMAKE_CURRENT_BINARY_DIR}/asm/${_source_file_base_name}_${_target}.obj)
463 get_source_file_property(_defines_semicolon_list ${_source_file_full_path} COMPILE_DEFINITIONS)
464 unset(_source_file_defines)
465 foreach(_define ${_defines_semicolon_list})
466 if(NOT ${_define} STREQUAL "NOTFOUND")
467 list(APPEND _source_file_defines -D${_define})
468 endif()
469 endforeach()
470 if(ARCH STREQUAL "arm")
471 set(_pp_asm_compile_command ${CMAKE_ASM_COMPILER} -nologo -o ${_object_file} ${_preprocessed_asm_file})
472 else()
473 set(_pp_asm_compile_command ${CMAKE_ASM_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_preprocessed_asm_file})
474 endif()
475 add_custom_command(
476 OUTPUT ${_preprocessed_asm_file} ${_object_file}
477 COMMAND cl /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} /D__ASM__ /D_USE_ML /EP /c ${_source_file_full_path} > ${_preprocessed_asm_file} && ${_pp_asm_compile_command}
478 DEPENDS ${_source_file_full_path})
479 set_source_files_properties(${_object_file} PROPERTIES EXTERNAL_OBJECT 1)
480 list(APPEND ${_target} ${_object_file})
481 endforeach()
482 else()
483 list(APPEND ${_target} ${ARGN})
484 endif()
485 endmacro()