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