xref: /reactos/sdk/cmake/msvc.cmake (revision aea948a7)
1
2#if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
3if(CMAKE_BUILD_TYPE STREQUAL "Debug")
4    # no optimization
5    add_compile_options(/Ob0 /Od)
6elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
7    add_compile_options(/Ox /Ob2 /Ot /Oy /GT)
8elseif(OPTIMIZE STREQUAL "1")
9    add_compile_options(/O1)
10elseif(OPTIMIZE STREQUAL "2")
11    add_compile_options(/O2)
12elseif(OPTIMIZE STREQUAL "3")
13    add_compile_options(/Ot /Ox /GS-)
14elseif(OPTIMIZE STREQUAL "4")
15    add_compile_options(/Os /Ox /GS-)
16elseif(OPTIMIZE STREQUAL "5")
17    add_compile_options(/Gy /Ob2 /Os /Ox /GS-)
18endif()
19
20# Always use string pooling: this helps reducing the binaries size since a lot
21# of redundancy come from the usage of __FILE__ / __RELFILE__ in the debugging
22# helper macros. Note also that GCC builds use string pooling by default.
23add_compile_options(/GF)
24
25# Enable function level linking and comdat folding
26add_compile_options(/Gy)
27add_link_options(/OPT:REF /OPT:ICF)
28
29if(ARCH STREQUAL "i386")
30    add_definitions(/DWIN32 /D_WINDOWS)
31endif()
32
33add_definitions(/Dinline=__inline /D__STDC__=1)
34
35# Ignore any "standard" include paths, and do not use any default CRT library.
36if(NOT USE_CLANG_CL)
37    add_compile_options(/X /Zl)
38endif()
39
40# Disable buffer security checks by default.
41add_compile_options(/GS-)
42
43if(USE_CLANG_CL)
44    set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: ")
45endif()
46
47# HACK: for VS 11+ we need to explicitly disable SSE, which is off by
48# default for older compilers. See CORE-6507
49if(ARCH STREQUAL "i386")
50    # Clang's IA32 means i386, which doesn't have cmpxchg8b
51    if(USE_CLANG_CL)
52        add_compile_options(-march=${OARCH})
53    else()
54        add_compile_options(/arch:IA32)
55    endif()
56endif()
57
58# CLang default to -fno-common from version 11 onward. We are not rady for this now
59if (USE_CLANG_CL)
60    add_compile_options(-fcommon)
61endif()
62
63# VS 12+ requires /FS when used in parallel compilations
64if(NOT MSVC_IDE)
65    add_compile_options(/FS)
66endif()
67
68# VS14+ tries to use thread-safe initialization
69add_compile_options(/Zc:threadSafeInit-)
70
71# HACK: Disable use of __CxxFrameHandler4 on VS 16.3+ (x64 only)
72# See https://developercommunity.visualstudio.com/content/problem/746534/visual-c-163-runtime-uses-an-unsupported-api-for-u.html
73if(ARCH STREQUAL "amd64" AND MSVC_VERSION GREATER 1922)
74    add_compile_options(/d2FH4-)
75    add_link_options(/d2:-FH4-)
76endif()
77
78# Generate Warnings Level 3
79add_compile_options(/W3)
80
81# Disable overly sensitive warnings as well as those that generally aren't
82# useful to us.
83# - C4244: implicit integer truncation
84# - C4290: C++ exception specification ignored
85# - C4800: forcing value to bool 'true' or 'false' (performance warning)
86# - C4200: nonstandard extension used : zero-sized array in struct/union
87# - C4214: nonstandard extension used : bit field types other than int
88add_compile_options(/wd4244 /wd4290 /wd4800 /wd4200 /wd4214)
89
90# FIXME: Temporarily disable C4018 until we fix more of the others. CORE-10113
91add_compile_options(/wd4018)
92
93# The following warnings are treated as errors:
94# - C4013: implicit function declaration
95# - C4020: too many actual parameters
96# - C4022: pointer type mismatch for parameter
97# - C4028: formal parameter different from declaration
98# - C4047: different level of indirection
99# - TODO: C4090: different 'modifier' qualifiers (for C programs only;
100#          for C++ programs, the compiler error C2440 is issued)
101# - C4098: void function returning a value
102# - C4101: unreferenced local variable
103# - C4113: parameter lists differ
104# - C4129: unrecognized escape sequence
105# - C4133: incompatible types - from '<x> *' to '<y> *'
106# - C4163: 'identifier': not available as an intrinsic function
107# - C4229: modifiers on data are ignored
108# - C4311: pointer truncation from '<pointer>' to '<integer>'
109# - C4312: conversion from '<integer>' to '<pointer>' of greater size
110# - C4313: 'fprintf': '%x' in format string conflicts with argument n of type 'HANDLE'
111# - C4477: '_snprintf' : format string '%ld' requires an argument of type 'long', but variadic argument 1 has type 'DWORD_PTR'
112# - C4603: macro is not defined or definition is different after precompiled header use
113# - C4700: uninitialized variable usage
114# - C4715: 'function': not all control paths return a value
115# - C4716: function must return a value
116add_compile_options(/we4013 /we4020 /we4022 /we4028 /we4047 /we4098 /we4101 /we4113 /we4129 /we4133 /we4163 /we4229 /we4311 /we4312 /we4313 /we4477 /we4603 /we4700 /we4715 /we4716)
117
118# - C4189: local variable initialized but not referenced
119# Not in Release mode
120if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
121    add_compile_options(/we4189)
122endif()
123
124# Enable warnings above the default level, but don't treat them as errors:
125# - C4115: named type definition in parentheses
126add_compile_options(/w14115)
127
128if(USE_CLANG_CL)
129    add_compile_options("$<$<COMPILE_LANGUAGE:C,CXX>:-nostdinc;-Wno-multichar;-Wno-char-subscripts;-Wno-microsoft-enum-forward-reference;-Wno-pragma-pack;-Wno-microsoft-anon-tag;-Wno-parentheses-equality;-Wno-unknown-pragmas>")
130endif()
131
132# Debugging
133if(CMAKE_BUILD_TYPE STREQUAL "Debug")
134    if(NOT (_PREFAST_ OR _VS_ANALYZE_))
135        add_compile_options(/Zi)
136    endif()
137elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
138    add_definitions("/D NDEBUG")
139endif()
140
141# Hotpatchable images
142if(ARCH STREQUAL "i386")
143    if(NOT USE_CLANG_CL)
144        add_compile_options(/hotpatch)
145    endif()
146    set(_hotpatch_link_flag "/FUNCTIONPADMIN:5")
147elseif(ARCH STREQUAL "amd64")
148    set(_hotpatch_link_flag "/FUNCTIONPADMIN:6")
149endif()
150
151if(MSVC_IDE AND (NOT DEFINED USE_FOLDER_STRUCTURE))
152    set(USE_FOLDER_STRUCTURE TRUE)
153endif()
154
155if(RUNTIME_CHECKS)
156    add_definitions(-D__RUNTIME_CHECKS__)
157    add_compile_options(/RTC1)
158endif()
159
160add_link_options(/MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4039)
161
162set(CMAKE_MSVC_RUNTIME_LIBRARY "")
163
164# HACK: Remove the /implib argument, implibs are generated separately
165string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
166string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE}")
167string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}")
168string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
169string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE}")
170string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE}")
171
172# HACK2: CMake lacks the ability to completely remove the 'implib' argument for solution files...
173# To work around this, we just let it create a dummy file
174if(MSVC_IDE)
175    set(CMAKE_IMPORT_LIBRARY_SUFFIX ".dummy")
176endif()
177
178
179if(CMAKE_DISABLE_NINJA_DEPSLOG)
180    set(cl_includes_flag "")
181else()
182    set(cl_includes_flag "/showIncludes")
183endif()
184
185if(MSVC_IDE)
186    # For VS builds we'll only have en-US in resource files
187    add_definitions(/DLANGUAGE_EN_US)
188else()
189    set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> /nologo <INCLUDES> <FLAGS> <DEFINES> ${I18N_DEFS} /fo <OBJECT> <SOURCE>")
190endif()
191
192# We don't put <INCLUDES> <DEFINES> <FLAGS> because this is handled in add_asm_files macro
193if (NOT MSVC_IDE)
194    if(ARCH STREQUAL "arm")
195        set(CMAKE_ASM_MASM_COMPILE_OBJECT "<CMAKE_ASM_MASM_COMPILER> -nologo -o <OBJECT> <SOURCE>")
196    else()
197        set(CMAKE_ASM_MASM_COMPILE_OBJECT "<CMAKE_ASM_MASM_COMPILER> /nologo /Cp /Fo <OBJECT> /c /Ta <SOURCE>")
198    endif()
199endif()
200
201if(_VS_ANALYZE_)
202    message("VS static analysis enabled!")
203    add_compile_options(/analyze)
204elseif(_PREFAST_)
205    message("PREFAST enabled!")
206    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}"
207    "prefast LIST")
208    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}"
209    "prefast LIST")
210    set(CMAKE_C_LINK_EXECUTABLE
211    "<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}")
212    set(CMAKE_CXX_LINK_EXECUTABLE
213    "<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}")
214endif()
215
216set(CMAKE_RC_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY})
217set(CMAKE_ASM_MASM_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY})
218set(CMAKE_RC_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_MODULE})
219set(CMAKE_ASM_MASM_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_MODULE})
220set(CMAKE_ASM_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY})
221
222function(set_entrypoint _module _entrypoint)
223    if(${_entrypoint} STREQUAL "0")
224        add_target_link_flags(${_module} "/NOENTRY")
225    elseif(ARCH STREQUAL "i386")
226        set(_entrysymbol ${_entrypoint})
227        if(${ARGC} GREATER 2)
228            set(_entrysymbol ${_entrysymbol}@${ARGV2})
229        endif()
230        add_target_link_flags(${_module} "/ENTRY:${_entrysymbol}")
231    else()
232        add_target_link_flags(${_module} "/ENTRY:${_entrypoint}")
233    endif()
234endfunction()
235
236function(set_subsystem MODULE SUBSYSTEM)
237    string(TOUPPER ${SUBSYSTEM} _subsystem)
238    if(ARCH STREQUAL "amd64")
239        add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},5.02")
240    elseif(ARCH STREQUAL "arm")
241        add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},6.02")
242    else()
243        add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},5.01")
244    endif()
245endfunction()
246
247function(set_image_base MODULE IMAGE_BASE)
248    add_target_link_flags(${MODULE} "/BASE:${IMAGE_BASE}")
249endfunction()
250
251function(set_module_type_toolchain MODULE TYPE)
252    # Set the PE image version numbers from the NT OS version ReactOS is based on
253    target_link_options(${MODULE} PRIVATE "/VERSION:5.01")
254
255    if((TYPE STREQUAL win32dll) OR (TYPE STREQUAL win32ocx) OR (TYPE STREQUAL cpl))
256        target_link_options(${MODULE} PRIVATE /DLL)
257    elseif(TYPE IN_LIST KERNEL_MODULE_TYPES)
258        # Mark INIT section as Executable Read Write Discardable
259        target_link_options(${MODULE} PRIVATE /SECTION:INIT,ERWD)
260
261        if(TYPE STREQUAL kernelmodedriver)
262            target_link_options(${MODULE} PRIVATE /DRIVER)
263        elseif(TYPE STREQUAL wdmdriver)
264            target_link_options(${MODULE} PRIVATE /DRIVER:WDM)
265        elseif (TYPE STREQUAL kernel)
266            # Mark .rsrc section as non-disposable non-pageable, as bugcheck code needs to access it
267            target_link_options(${MODULE} PRIVATE /SECTION:.rsrc,!DP)
268        endif()
269    endif()
270
271    if(RUNTIME_CHECKS)
272        target_link_libraries(${MODULE} runtmchk)
273    endif()
274
275endfunction()
276
277function(add_delay_importlibs _module)
278    get_target_property(_module_type ${_module} TYPE)
279    if(_module_type STREQUAL "STATIC_LIBRARY")
280        message(FATAL_ERROR "Cannot add delay imports to a static library")
281    endif()
282    foreach(_lib ${ARGN})
283        get_filename_component(_basename "${_lib}" NAME_WE)
284        get_filename_component(_ext "${_lib}" EXT)
285        if(NOT _ext)
286            set(_ext ".dll")
287        endif()
288        add_target_link_flags(${_module} "/DELAYLOAD:${_basename}${_ext}")
289        target_link_libraries(${_module} "lib${_basename}")
290    endforeach()
291    target_link_libraries(${_module} delayimp)
292endfunction()
293
294function(fixup_load_config _target)
295    # msvc knows how to generate a load_config so no hacks here
296endfunction()
297
298function(generate_import_lib _libname _dllname _spec_file)
299
300    set(_def_file ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
301    set(_asm_stubs_file ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_stubs.asm)
302
303    # Generate the def and asm stub files
304    add_custom_command(
305        OUTPUT ${_asm_stubs_file} ${_def_file}
306        COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} --implib -n=${_dllname} -d=${_def_file} -l=${_asm_stubs_file} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
307        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
308
309    # Compile the generated asm stub file
310    if(ARCH STREQUAL "arm")
311        set(_asm_stub_command ${CMAKE_ASM_MASM_COMPILER} -nologo -o ${_asm_stubs_file}.obj ${_asm_stubs_file})
312    else()
313        set(_asm_stub_command ${CMAKE_ASM_MASM_COMPILER} /nologo /Cp /Fo${_asm_stubs_file}.obj /c /Ta ${_asm_stubs_file})
314    endif()
315    add_custom_command(
316        OUTPUT ${_asm_stubs_file}.obj
317        COMMAND ${_asm_stub_command}
318        DEPENDS ${_asm_stubs_file})
319
320    # generate the intermediate import lib
321    set(_libfile_tmp ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_tmp.lib)
322    set(_static_lib_options )
323
324    set(_implib_command ${CMAKE_LINKER} /LIB /NOLOGO /MACHINE:${WINARCH}
325        $<TARGET_PROPERTY:${_libname},STATIC_LIBRARY_FLAGS> $<TARGET_PROPERTY:${_libname},STATIC_LIBRARY_OPTIONS>
326        /DEF:${_def_file} /OUT:${_libfile_tmp} ${_asm_stubs_file}.obj)
327
328    add_custom_command(
329        OUTPUT ${_libfile_tmp}
330        COMMAND ${_implib_command}
331        DEPENDS ${_asm_stubs_file}.obj ${_def_file})
332
333    # By giving the import lib as an object input, LIB extracts the relevant object files and make a new library.
334    # This allows us to treat the implib as a regular static library
335    set_source_files_properties(${_libfile_tmp} PROPERTIES EXTERNAL_OBJECT TRUE)
336    add_library(${_libname} STATIC ${_libfile_tmp})
337
338    set_target_properties(${_libname} PROPERTIES LINKER_LANGUAGE "C")
339endfunction()
340
341if(ARCH STREQUAL "amd64")
342    # This is NOT a typo.
343    # See https://software.intel.com/en-us/forums/topic/404643
344    add_definitions(/D__x86_64)
345    set(SPEC2DEF_ARCH x86_64)
346elseif(ARCH STREQUAL "arm")
347    add_definitions(/D__arm__)
348    set(SPEC2DEF_ARCH arm)
349else()
350    set(SPEC2DEF_ARCH i386)
351endif()
352function(spec2def _dllname _spec_file)
353
354    cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY" "VERSION" "" ${ARGN})
355
356    # Get library basename
357    get_filename_component(_file ${_dllname} NAME_WE)
358
359    # Error out on anything else than spec
360    if(NOT ${_spec_file} MATCHES ".*\\.spec")
361        message(FATAL_ERROR "spec2def only takes spec files as input.")
362    endif()
363
364    if(__spec2def_WITH_RELAY)
365        set(__with_relay_arg "--with-tracing")
366    endif()
367
368    if(__spec2def_VERSION)
369        set(__version_arg "--version=0x${__spec2def_VERSION}")
370    endif()
371
372    # Generate exports def and C stubs file for the DLL
373    add_custom_command(
374        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
375        COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
376        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
377
378    if(__spec2def_ADD_IMPORTLIB)
379        generate_import_lib(lib${_file} ${_dllname} ${_spec_file})
380        if(__spec2def_NO_PRIVATE_WARNINGS)
381            set_property(TARGET lib${_file} APPEND PROPERTY STATIC_LIBRARY_OPTIONS /ignore:4104)
382        endif()
383    endif()
384endfunction()
385
386macro(macro_mc FLAG FILE)
387    set(COMMAND_MC ${CMAKE_MC_COMPILER} -u ${FLAG} -b -h ${CMAKE_CURRENT_BINARY_DIR}/ -r ${CMAKE_CURRENT_BINARY_DIR}/ ${FILE})
388endmacro()
389
390# PSEH workaround
391set(PSEH_LIB "pseh")
392
393# Use a full path for the x86 version of ml when using x64 VS.
394# It's not a problem when using the DDK/WDK because, in x64 mode,
395# both the x86 and x64 versions of ml are available.
396if((ARCH STREQUAL "amd64") AND (DEFINED ENV{VCToolsInstallDir}))
397    set(CMAKE_ASM16_COMPILER $ENV{VCToolsInstallDir}/bin/HostX86/x86/ml.exe)
398elseif((ARCH STREQUAL "amd64") AND (DEFINED ENV{VCINSTALLDIR}))
399    set(CMAKE_ASM16_COMPILER $ENV{VCINSTALLDIR}/bin/ml.exe)
400elseif(ARCH STREQUAL "arm")
401    set(CMAKE_ASM16_COMPILER armasm.exe)
402else()
403    set(CMAKE_ASM16_COMPILER ml.exe)
404endif()
405
406function(CreateBootSectorTarget _target_name _asm_file _binary_file _base_address)
407    set(_object_file ${_binary_file}.obj)
408    set(_temp_file ${_binary_file}.tmp)
409
410    get_defines(_defines)
411    get_includes(_includes)
412
413    if(USE_CLANG_CL)
414        set(_no_std_includes_flag "-nostdinc")
415    else()
416        set(_no_std_includes_flag "/X")
417    endif()
418
419    add_custom_command(
420        OUTPUT ${_temp_file}
421        COMMAND ${CMAKE_C_COMPILER} /nologo ${_no_std_includes_flag} /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm ${_includes} ${_defines} /D__ASM__ /D_USE_ML /EP /c ${_asm_file} > ${_temp_file}
422        DEPENDS ${_asm_file})
423
424    if(ARCH STREQUAL "arm")
425        set(_asm16_command ${CMAKE_ASM16_COMPILER} -nologo -o ${_object_file} ${_temp_file})
426    else()
427        set(_asm16_command ${CMAKE_ASM16_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_temp_file})
428    endif()
429
430    add_custom_command(
431        OUTPUT ${_object_file}
432        COMMAND ${_asm16_command}
433        DEPENDS ${_temp_file})
434
435    add_custom_command(
436        OUTPUT ${_binary_file}
437        COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
438        DEPENDS ${_object_file} native-obj2bin)
439
440    set_source_files_properties(${_object_file} ${_temp_file} ${_binary_file} PROPERTIES GENERATED TRUE)
441
442    add_custom_target(${_target_name} ALL DEPENDS ${_binary_file})
443endfunction()
444
445function(allow_warnings __module)
446endfunction()
447
448macro(add_asm_files _target)
449    get_defines(_directory_defines)
450    get_includes(_directory_includes)
451    get_directory_property(_defines COMPILE_DEFINITIONS)
452    foreach(_source_file ${ARGN})
453        get_filename_component(_source_file_base_name ${_source_file} NAME_WE)
454        get_filename_component(_source_file_full_path ${_source_file} ABSOLUTE)
455        set(_preprocessed_asm_file ${CMAKE_CURRENT_BINARY_DIR}/asm/${_source_file_base_name}_${_target}.asm)
456        get_source_file_property(_defines_semicolon_list ${_source_file_full_path} COMPILE_DEFINITIONS)
457        unset(_source_file_defines)
458        foreach(_define ${_defines_semicolon_list})
459            if(NOT ${_define} STREQUAL "NOTFOUND")
460                list(APPEND _source_file_defines -D${_define})
461            endif()
462        endforeach()
463        add_custom_command(
464            OUTPUT ${_preprocessed_asm_file}
465            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}
466            DEPENDS ${_source_file_full_path})
467        list(APPEND ${_target} ${_preprocessed_asm_file})
468    endforeach()
469endmacro()
470
471function(add_linker_script _target _linker_script_file)
472    get_filename_component(_file_full_path ${_linker_script_file} ABSOLUTE)
473    get_filename_component(_file_name ${_linker_script_file} NAME)
474    set(_generated_file_path_prefix "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_target}.dir/${_file_name}")
475
476    # Generate the ASM module containing sections specifications and layout.
477    set(_generated_file "${_generated_file_path_prefix}.S")
478    add_custom_command(
479        OUTPUT ${_generated_file}
480        COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${_file_full_path}" "${_generated_file}"
481        DEPENDS ${_file_full_path})
482    set_source_files_properties(${_generated_file} PROPERTIES LANGUAGE "ASM_MASM" GENERATED TRUE)
483    add_asm_files(${_target}_linker_file ${_generated_file})
484
485    # Generate the C module containing extra sections specifications and layout,
486    # as well as comment-type linker #pragma directives.
487    set(_generated_file "${_generated_file_path_prefix}.c")
488    add_custom_command(
489        OUTPUT ${_generated_file}
490        COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${_file_full_path}" "${_generated_file}"
491        DEPENDS ${_file_full_path})
492    set_source_files_properties(${_generated_file} PROPERTIES LANGUAGE "C" GENERATED TRUE)
493    list(APPEND ${_target}_linker_file ${_generated_file})
494
495    # Add both files to the sources of the target.
496    target_sources(${_target} PRIVATE "${${_target}_linker_file}")
497
498    # Create the additional linker response file.
499    set(_generated_file "${_generated_file_path_prefix}.rsp")
500    if(USE_CLANG_CL)
501        set(_no_std_includes_flag "-nostdinc")
502    else()
503        set(_no_std_includes_flag "/X")
504    endif()
505    if(MSVC_IDE)
506        # MSBuild, via the VS IDE, uses response files when calling CL or LINK.
507        # We cannot specify a custom response file on the linker command-line,
508        # since specifying response files from within response files is forbidden.
509        # We therefore have to pre-process, at configuration time, the linker
510        # script so as to retrieve the custom linker options to be appended
511        # to the linker command-line.
512        execute_process(
513            COMMAND ${CMAKE_C_COMPILER} /nologo ${_no_std_includes_flag} /D__LINKER__ /EP /c "${_file_full_path}"
514            # OUTPUT_FILE "${_generated_file}"
515            OUTPUT_VARIABLE linker_options
516            ERROR_QUIET
517            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
518            RESULT_VARIABLE linker_rsp_result
519            OUTPUT_STRIP_TRAILING_WHITESPACE)
520        if(NOT linker_rsp_result EQUAL 0)
521            message(FATAL_ERROR "Generating pre-processed linker options for target '${_target}' failed with error ${linker_rsp_result}.")
522        endif()
523        # file(STRINGS ${_generated_file} linker_options NEWLINE_CONSUME)
524        string(REGEX REPLACE "[\r\n]+" " " linker_options "${linker_options}")
525        add_target_link_flags(${_target} ${linker_options})
526    else()
527        # Generate at compile-time a linker response file and append it
528        # to the linker command-line.
529        add_custom_command(
530            # OUTPUT ${_generated_file}
531            TARGET ${_target} PRE_LINK # PRE_BUILD
532            COMMAND ${CMAKE_C_COMPILER} /nologo ${_no_std_includes_flag} /D__LINKER__ /EP /c "${_file_full_path}" > "${_generated_file}"
533            DEPENDS ${_file_full_path}
534            VERBATIM)
535        set_source_files_properties(${_generated_file} PROPERTIES GENERATED TRUE)
536        # add_custom_target("${_target}_${_file_name}" ALL DEPENDS ${_generated_file})
537        # add_dependencies(${_target} "${_target}_${_file_name}")
538        add_target_link_flags(${_target} "@${_generated_file}")
539        add_target_property(${_target} LINK_DEPENDS ${_file_full_path})
540    endif()
541endfunction()
542
543# handle C++ options
544# disable RTTI unless said so
545add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<IF:$<BOOL:$<TARGET_PROPERTY:WITH_CXX_RTTI>>,/GR,/GR->>")
546# disable exceptions unless said so
547add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<IF:$<BOOL:$<TARGET_PROPERTY:WITH_CXX_EXCEPTIONS>>,/EHsc,/EHs-c->>")
548
549# Create our interface libraries wrapping the needed library for this compiler
550add_library(cppstl INTERFACE)
551target_link_libraries(cppstl INTERFACE cpprt stlport oldnames)
552# We set this properties through our INTERFACE library
553set_target_properties(cppstl PROPERTIES INTERFACE_WITH_CXX_STL TRUE)
554# add_library(cpprt INTERFACE)
555# Our runtime library is already called cpprt
556