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