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