From 00ed72d7e850a5bfec98023ad3821a81a5f77ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Mon, 21 Sep 2020 12:16:02 +0200 Subject: [PATCH] [CMAKE] Get rid of add_compile_flags Use add_compile_options and the like instead --- CMakeLists.txt | 2 +- base/services/tftpd/CMakeLists.txt | 8 +-- boot/freeldr/freeldr/CMakeLists.txt | 2 +- dll/3rdparty/libxslt/CMakeLists.txt | 11 ++-- dll/win32/comctl32/CMakeLists.txt | 6 +- dll/win32/framedyn/CMakeLists.txt | 6 +- dll/win32/msxml3/CMakeLists.txt | 9 +-- dll/win32/windowscodecs/CMakeLists.txt | 9 +-- .../devutils/createspec/CMakeLists.txt | 7 +- .../applications/net/roshttpd/CMakeLists.txt | 2 +- modules/rostests/apitests/crt/CMakeLists.txt | 4 +- .../rostests/tests/dllexport/CMakeLists.txt | 8 +-- .../rostests/winetests/advpack/CMakeLists.txt | 14 ++-- .../rostests/winetests/fusion/CMakeLists.txt | 13 ++-- modules/rostests/winetests/msi/CMakeLists.txt | 24 ++++--- .../rostests/winetests/msvcrt/CMakeLists.txt | 21 +++--- .../winetests/services/CMakeLists.txt | 8 +-- .../winetests/setupapi/CMakeLists.txt | 8 +-- .../rostests/winetests/shell32/CMakeLists.txt | 6 +- .../rostests/winetests/version/CMakeLists.txt | 12 ++-- sdk/cmake/compilerflags.cmake | 16 ----- sdk/cmake/gcc.cmake | 65 +++++++++---------- sdk/cmake/msvc.cmake | 63 ++++++++---------- sdk/lib/crt/msvcrtex.cmake | 17 ++--- sdk/lib/drivers/lwip/CMakeLists.txt | 6 +- sdk/tools/wpp/CMakeLists.txt | 9 ++- 26 files changed, 158 insertions(+), 198 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3de95fe75c1..ed703c8145c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ else() endif() if(MSVC_IDE) - add_compile_flags("/MP") + add_compile_options("/MP") endif() # Bison and Flex support diff --git a/base/services/tftpd/CMakeLists.txt b/base/services/tftpd/CMakeLists.txt index f4bd0cb6d7d..218464d28ae 100644 --- a/base/services/tftpd/CMakeLists.txt +++ b/base/services/tftpd/CMakeLists.txt @@ -1,9 +1,9 @@ -if(NOT MSVC) - add_compile_flags("-Wno-format-overflow") -endif() - add_executable(tftpd tftpd.cpp) set_module_type(tftpd win32cui) add_importlibs(tftpd advapi32 ws2_32 iphlpapi msvcrt kernel32) add_cd_file(TARGET tftpd DESTINATION reactos/system32 FOR all) + +if ((NOT MSVC) OR USE_CLANG_CL) + target_compile_options(tftpd PRIVATE -Wno-format-overflow) +endif() diff --git a/boot/freeldr/freeldr/CMakeLists.txt b/boot/freeldr/freeldr/CMakeLists.txt index 80bea8f1f41..a401a5b1a66 100644 --- a/boot/freeldr/freeldr/CMakeLists.txt +++ b/boot/freeldr/freeldr/CMakeLists.txt @@ -8,7 +8,7 @@ endif() if(MSVC) # Explicitly use string pooling - add_compile_flags("/GF") + add_compile_options("/GF") endif() spec2def(freeldr_pe.exe freeldr.spec) diff --git a/dll/3rdparty/libxslt/CMakeLists.txt b/dll/3rdparty/libxslt/CMakeLists.txt index d5e2d3b9eb8..5247b3efb7a 100644 --- a/dll/3rdparty/libxslt/CMakeLists.txt +++ b/dll/3rdparty/libxslt/CMakeLists.txt @@ -1,8 +1,4 @@ -if(NOT MSVC) - add_compile_flags("-Wno-misleading-indentation") -endif() - include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libxslt ${REACTOS_SOURCE_DIR}/sdk/lib/3rdparty/libwin-iconv) @@ -47,9 +43,10 @@ if(MSVC) add_importlibs(libxslt ntdll) endif() +if ((NOT MSVC) OR USE_CLANG_CL) + target_compile_options(libxslt PRIVATE -Wno-misleading-indentation -Wno-pointer-sign -Wno-unused-function) +endif() + add_pch(libxslt precomp.h SOURCE) add_cd_file(TARGET libxslt DESTINATION reactos/system32 FOR all) -if(USE_CLANG_CL OR (NOT MSVC)) - target_compile_options(libxslt PRIVATE -Wno-pointer-sign -Wno-unused-function) -endif() diff --git a/dll/win32/comctl32/CMakeLists.txt b/dll/win32/comctl32/CMakeLists.txt index 4d70e28eecc..60c571c58ed 100644 --- a/dll/win32/comctl32/CMakeLists.txt +++ b/dll/win32/comctl32/CMakeLists.txt @@ -64,8 +64,10 @@ add_library(comctl32 MODULE rsrc.rc ${CMAKE_CURRENT_BINARY_DIR}/comctl32.def) -# Disable warning C4477 (printf format warnings) -target_compile_options(comctl32 PRIVATE $<$:/wd4477>) +if (MSVC) + # Disable warning C4477 (printf format warnings) + target_compile_options(comctl32 PRIVATE /wd4477) +endif() set_module_type(comctl32 win32dll UNICODE) target_link_libraries(comctl32 uuid wine ${PSEH_LIB}) diff --git a/dll/win32/framedyn/CMakeLists.txt b/dll/win32/framedyn/CMakeLists.txt index 922ead719e9..837fea881fa 100644 --- a/dll/win32/framedyn/CMakeLists.txt +++ b/dll/win32/framedyn/CMakeLists.txt @@ -7,10 +7,6 @@ list(APPEND SOURCE provider.cpp ${CMAKE_CURRENT_BINARY_DIR}/framedyn.def) -if(MSVC) - add_compile_flags("/Zc:wchar_t-") -endif() - add_library(framedyn MODULE ${SOURCE}) target_link_libraries(framedyn cpprt) set_target_cpp_properties(framedyn WITH_EXCEPTIONS) @@ -22,4 +18,6 @@ if(NOT MSVC) add_asm_files(framedynex_asm alias_gcc.s) add_library(framedynex ${framedynex_asm}) set_target_properties(framedynex PROPERTIES LINKER_LANGUAGE ASM) +else() + target_compile_options(framedyn PRIVATE /Zc:wchar_t-) endif() diff --git a/dll/win32/msxml3/CMakeLists.txt b/dll/win32/msxml3/CMakeLists.txt index b11bdf3f8ed..953b615d573 100644 --- a/dll/win32/msxml3/CMakeLists.txt +++ b/dll/win32/msxml3/CMakeLists.txt @@ -6,10 +6,6 @@ add_definitions( -DLIBXML_STATIC -DCOM_NO_WINDOWS_H) -if(MSVC) - add_compile_flags("/FIwine/typeof.h /FImsvc.h") -endif() - include_directories( ${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine ${REACTOS_SOURCE_DIR}/sdk/lib/3rdparty/libwin-iconv) @@ -76,6 +72,11 @@ add_library(msxml3 MODULE add_idl_headers(xmlparser_idlheader xmlparser.idl) set_module_type(msxml3 win32dll) target_link_libraries(msxml3 libxml2 iconv-static uuid wine zlib) + +if (MSVC) + target_compile_options(msxml3 PRIVATE /FIwine/typeof.h /FImsvc.h) +endif() + add_importlibs(msxml3 urlmon ws2_32 shlwapi oleaut32 ole32 user32 msvcrt kernel32 ntdll) add_dependencies(msxml3 xmlparser_idlheader stdole2) # msxml3_v1.tlb needs stdole2.tlb add_pch(msxml3 precomp.h "${PCH_SKIP_SOURCE}") diff --git a/dll/win32/windowscodecs/CMakeLists.txt b/dll/win32/windowscodecs/CMakeLists.txt index fd29c68ad48..c9f0e9ecdbd 100644 --- a/dll/win32/windowscodecs/CMakeLists.txt +++ b/dll/win32/windowscodecs/CMakeLists.txt @@ -16,10 +16,6 @@ include_directories( ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libpng ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libtiff) -if(MSVC) - add_compile_flags("/FItypeof.h") -endif() - spec2def(windowscodecs.dll windowscodecs.spec ADD_IMPORTLIB) add_rpcproxy_files(windowscodecs_wincodec.idl) @@ -75,8 +71,9 @@ add_library(windowscodecs MODULE ${CMAKE_CURRENT_BINARY_DIR}/windowscodecs.def) if(MSVC) - # error C4133: 'function': incompatible types - from 'WICPixelFormatNumericRepresentation *' to 'DWORD *' - remove_target_compile_option(windowscodecs "/we4133") + target_compile_options(windowscodecs PRIVATE + /wd4133 # error C4133: 'function': incompatible types - from 'WICPixelFormatNumericRepresentation *' to 'DWORD *' + /FItypeof.h) endif() set_module_type(windowscodecs win32dll) diff --git a/modules/rosapps/applications/devutils/createspec/CMakeLists.txt b/modules/rosapps/applications/devutils/createspec/CMakeLists.txt index fbd6692604c..1cb52624ccf 100644 --- a/modules/rosapps/applications/devutils/createspec/CMakeLists.txt +++ b/modules/rosapps/applications/devutils/createspec/CMakeLists.txt @@ -1,10 +1,9 @@ -if(GCC) - add_compile_flags("-Wno-stringop-overflow") -endif() - add_executable(createspec createspec.c) set_module_type(createspec win32cui) target_link_libraries(createspec wine) +if (NOT MSVC) + target_compile_options(createspec PRIVATE -Wno-stringop-overflow) +endif() add_importlibs(createspec dbghelp msvcrt kernel32) add_cd_file(TARGET createspec DESTINATION reactos/system32 FOR all) diff --git a/modules/rosapps/applications/net/roshttpd/CMakeLists.txt b/modules/rosapps/applications/net/roshttpd/CMakeLists.txt index 3cb22768855..938212c2016 100644 --- a/modules/rosapps/applications/net/roshttpd/CMakeLists.txt +++ b/modules/rosapps/applications/net/roshttpd/CMakeLists.txt @@ -1,6 +1,5 @@ include_directories(BEFORE include) -add_compile_flags("-D__USE_W32_SOCKETS") list(APPEND SOURCE config.cpp @@ -15,6 +14,7 @@ list(APPEND SOURCE add_executable(roshttpd ${SOURCE} common/roshttpd.rc) target_link_libraries(roshttpd cppstl) set_target_cpp_properties(roshttpd WITH_EXCEPTIONS) +target_compile_definitions(roshttpd PRIVATE __USE_W32_SOCKETS) set_module_type(roshttpd win32cui) add_importlibs(roshttpd user32 ws2_32 msvcrt kernel32) add_cd_file(TARGET roshttpd DESTINATION reactos/system32 FOR all) diff --git a/modules/rostests/apitests/crt/CMakeLists.txt b/modules/rostests/apitests/crt/CMakeLists.txt index 8b253d21f66..3b71f777bc6 100644 --- a/modules/rostests/apitests/crt/CMakeLists.txt +++ b/modules/rostests/apitests/crt/CMakeLists.txt @@ -1,6 +1,6 @@ -if(GCC) - add_compile_flags("-fno-builtin") +if (GCC) + add_compile_options(-fno-builtin) endif() include(ntdll_crt_apitest.cmake) diff --git a/modules/rostests/tests/dllexport/CMakeLists.txt b/modules/rostests/tests/dllexport/CMakeLists.txt index 741477d2c6e..65e87cec3bb 100644 --- a/modules/rostests/tests/dllexport/CMakeLists.txt +++ b/modules/rostests/tests/dllexport/CMakeLists.txt @@ -23,10 +23,6 @@ add_executable(dllexport_test dllexport_test.c) set_module_type(dllexport_test win32cui) add_importlibs(dllexport_test dllexport_test_dll1 msvcrt kernel32 ntdll) -if(MSVC) - add_compile_flags("/Zc:wchar_t-") -endif() - # framedyn is skipped in the clang-cl build if(NOT USE_CLANG_CL) @@ -34,7 +30,9 @@ add_library(dllimport_test MODULE dllimport_framedyn.cpp) set_module_type(dllimport_test module) add_importlibs(dllimport_test framedyn) -if(NOT MSVC) +if (MSVC) + target_compile_options(dllimport_test PRIVATE /Zc:wchar_t-) +else() target_link_libraries(dllimport_test framedynex) endif() diff --git a/modules/rostests/winetests/advpack/CMakeLists.txt b/modules/rostests/winetests/advpack/CMakeLists.txt index a920eda6d06..9eebedf7ba0 100644 --- a/modules/rostests/winetests/advpack/CMakeLists.txt +++ b/modules/rostests/winetests/advpack/CMakeLists.txt @@ -1,10 +1,4 @@ -add_definitions(-DUSE_WINE_TODOS) - -if(GCC) - add_compile_flags("-Wno-format-overflow") -endif() - list(APPEND SOURCE advpack.c files.c @@ -12,7 +6,13 @@ list(APPEND SOURCE testlist.c) add_executable(advpack_winetest ${SOURCE}) -target_link_libraries(advpack_winetest) + +target_compile_definitions(advpack_winetest PRIVATE USE_WINE_TODOS) + +if (NOT MSVC) + target_compile_options(advpack_winetest PRIVATE -Wno-format-overflow) +endif() + set_module_type(advpack_winetest win32cui) add_importlibs(advpack_winetest advpack cabinet advapi32 msvcrt kernel32) add_rostests_file(TARGET advpack_winetest) diff --git a/modules/rostests/winetests/fusion/CMakeLists.txt b/modules/rostests/winetests/fusion/CMakeLists.txt index faca708e42e..f3600c383d0 100644 --- a/modules/rostests/winetests/fusion/CMakeLists.txt +++ b/modules/rostests/winetests/fusion/CMakeLists.txt @@ -1,10 +1,4 @@ -add_definitions(-DUSE_WINE_TODOS) - -if(GCC) - add_compile_flags("-Wno-format-overflow") -endif() - list(APPEND SOURCE asmcache.c asmenum.c @@ -13,6 +7,13 @@ list(APPEND SOURCE testlist.c) add_executable(fusion_winetest ${SOURCE}) + +target_compile_definitions(fusion_winetest PRIVATE USE_WINE_TODOS) + +if (NOT MSVC) + target_compile_options(fusion_winetest PRIVATE -Wno-format-overflow) +endif() + set_module_type(fusion_winetest win32cui) add_importlibs(fusion_winetest user32 msvcrt kernel32) add_rostests_file(TARGET fusion_winetest) diff --git a/modules/rostests/winetests/msi/CMakeLists.txt b/modules/rostests/winetests/msi/CMakeLists.txt index 2c71551a024..815c2cfc2cc 100644 --- a/modules/rostests/winetests/msi/CMakeLists.txt +++ b/modules/rostests/winetests/msi/CMakeLists.txt @@ -1,17 +1,4 @@ -add_definitions( - -DUSE_WINE_TODOS - -D__WINESRC__) - -if(MSVC_IDE) - # msi_winetest.rc: let rc.exe find custom.dll in its subdirectory, i.e. Debug. - include_directories($) -endif() - -if(GCC) - add_compile_flags("-Wno-format-overflow") -endif() - spec2def(custom.dll custom.spec) add_library(custom MODULE custom.c ${CMAKE_CURRENT_BINARY_DIR}/custom.def) target_link_libraries(custom uuid) @@ -43,6 +30,17 @@ add_executable(msi_winetest ${PCH_SKIP_SOURCE} msi_winetest.rc) +target_compile_definitions(msi_winetest PRIVATE __WINESRC__ USE_WINE_TODOS) + +if (NOT MSVC) + target_compile_options(msi_winetest PRIVATE -Wno-format-overflow) +endif() + +# msi_winetest.rc: let rc.exe find custom.dll in its subdirectory, i.e. Debug. +if (MSVC_IDE) + target_include_directories(msi_winetest PRIVATE $<$:$>) +endif() + target_link_libraries(msi_winetest uuid) set_module_type(msi_winetest win32cui) add_importlibs(msi_winetest cabinet msi shell32 ole32 oleaut32 user32 advapi32 version msvcrt kernel32) diff --git a/modules/rostests/winetests/msvcrt/CMakeLists.txt b/modules/rostests/winetests/msvcrt/CMakeLists.txt index 9b9ab157cc7..0574e646adf 100644 --- a/modules/rostests/winetests/msvcrt/CMakeLists.txt +++ b/modules/rostests/winetests/msvcrt/CMakeLists.txt @@ -1,13 +1,4 @@ -add_definitions( - -DWINETEST_USE_DBGSTR_LONGLONG - -D_CRT_NONSTDC_NO_DEPRECATE - -D__msvcrt_ulong=ULONG) - -if(GCC) - add_compile_flags("-Wno-stringop-truncation") -endif() - list(APPEND SOURCE cpp.c data.c @@ -31,8 +22,16 @@ add_executable(msvcrt_winetest ${SOURCE} ${PCH_SKIP_SOURCE}) -if(USE_CLANG_CL OR (NOT MSVC)) - target_compile_options(msvcrt_winetest PRIVATE "-Wno-format") +target_compile_definitions(msvcrt_winetest PRIVATE + WINETEST_USE_DBGSTR_LONGLONG + _CRT_NONSTDC_NO_DEPRECATE + __msvcrt_ulong=ULONG) + +if ((NOT MSVC) OR USE_CLANG_CL) + if (NOT USE_CLANG_CL) + target_compile_options(msvcrt_winetest PRIVATE -Wno-stringop-truncation) + endif() + target_compile_options(msvcrt_winetest PRIVATE -Wno-format) endif() set_module_type(msvcrt_winetest win32cui) diff --git a/modules/rostests/winetests/services/CMakeLists.txt b/modules/rostests/winetests/services/CMakeLists.txt index 01141885072..b6313f4d2e8 100644 --- a/modules/rostests/winetests/services/CMakeLists.txt +++ b/modules/rostests/winetests/services/CMakeLists.txt @@ -1,9 +1,9 @@ -if(GCC) - add_compile_flags("-Wno-format-overflow") -endif() - add_executable(services_winetest service.c testlist.c) set_module_type(services_winetest win32cui) add_importlibs(services_winetest user32 advapi32 msvcrt kernel32) add_rostests_file(TARGET services_winetest) + +if (NOT MSVC) + target_compile_options(services_winetest PRIVATE -Wno-format-overflow) +endif() diff --git a/modules/rostests/winetests/setupapi/CMakeLists.txt b/modules/rostests/winetests/setupapi/CMakeLists.txt index d47b7f1c282..60ba1fef77b 100644 --- a/modules/rostests/winetests/setupapi/CMakeLists.txt +++ b/modules/rostests/winetests/setupapi/CMakeLists.txt @@ -1,8 +1,4 @@ -if(GCC) - add_compile_flags("-Wno-format-overflow") -endif() - list(APPEND SOURCE devinst.c dialog.c @@ -20,3 +16,7 @@ set_module_type(setupapi_winetest win32cui) target_link_libraries(setupapi_winetest uuid) add_importlibs(setupapi_winetest advapi32 setupapi user32 shell32 msvcrt kernel32 ntdll) add_rostests_file(TARGET setupapi_winetest) + +if (NOT MSVC) + target_compile_options(setupapi_winetest PRIVATE -Wno-format-overflow) +endif() diff --git a/modules/rostests/winetests/shell32/CMakeLists.txt b/modules/rostests/winetests/shell32/CMakeLists.txt index 3b3451c8343..a9816a60be4 100644 --- a/modules/rostests/winetests/shell32/CMakeLists.txt +++ b/modules/rostests/winetests/shell32/CMakeLists.txt @@ -3,10 +3,6 @@ add_definitions(-DWINETEST_USE_DBGSTR_LONGLONG) remove_definitions(-DWINVER=0x502 -D_WIN32_IE=0x600 -D_WIN32_WINNT=0x502) -if(GCC) - add_compile_flags("-Wno-format-overflow") -endif() - list(APPEND SOURCE appbar.c assoc.c @@ -42,6 +38,8 @@ add_importlibs(shell32_winetest shell32 shlwapi ole32 oleaut32 user32 gdi32 adva if(MSVC) add_importlibs(shell32_winetest ntdll) +else() + target_compile_options(shell32_winetest PRIVATE -Wno-format-overflow) endif() add_pch(shell32_winetest precomp.h "${PCH_SKIP_SOURCE}") diff --git a/modules/rostests/winetests/version/CMakeLists.txt b/modules/rostests/winetests/version/CMakeLists.txt index ccc7efa6d8d..a4d8a7901e2 100644 --- a/modules/rostests/winetests/version/CMakeLists.txt +++ b/modules/rostests/winetests/version/CMakeLists.txt @@ -1,10 +1,4 @@ -add_definitions(-DUSE_WINE_TODOS) - -if(GCC) - add_compile_flags("-Wno-format-overflow") -endif() - list(APPEND SOURCE info.c install.c @@ -14,7 +8,11 @@ add_executable(version_winetest ${SOURCE} version.rc) set_module_type(version_winetest win32cui) add_importlibs(version_winetest shell32 version msvcrt kernel32) -if(MSVC) +target_compile_definitions(version_winetest PRIVATE USE_WINE_TODOS) + +if (NOT MSVC) + target_compile_options(version_winetest PRIVATE -Wno-format-overflow) +else() add_importlibs(version_winetest ntdll) endif() diff --git a/sdk/cmake/compilerflags.cmake b/sdk/cmake/compilerflags.cmake index d42b57cbb05..3ebbc049e91 100644 --- a/sdk/cmake/compilerflags.cmake +++ b/sdk/cmake/compilerflags.cmake @@ -48,19 +48,3 @@ function(add_target_link_flags _module _flags) endif() add_target_property(${_module} LINK_FLAGS ${_flags}) endfunction() - -# add_compile_flags -# Add or replace compiler flags in the global scope for either all source -# files or only those of the specified language. -# -# Examples: -# add_compile_flags("-pedantic -O5") -function(add_compile_flags _flags) - if(${ARGC} GREATER 1) - message(FATAL_ERROR "Excess arguments to add_compile_flags! Args ${ARGN}") - endif() - # Adds the compiler flag for all code files: C, C++, and assembly - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flags}" PARENT_SCOPE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE) - set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${_flags}" PARENT_SCOPE) -endfunction() diff --git a/sdk/cmake/gcc.cmake b/sdk/cmake/gcc.cmake index d5a20cba42e..d20abb20473 100644 --- a/sdk/cmake/gcc.cmake +++ b/sdk/cmake/gcc.cmake @@ -35,18 +35,17 @@ if(USE_DUMMY_PSEH) endif() if(STACK_PROTECTOR) - add_compile_flags(${MODULE} "-fstack-protector-all") + add_compile_options(-fstack-protector-all) endif() # Compiler Core -add_compile_flags("-pipe -fms-extensions -fno-strict-aliasing") +add_compile_options(-pipe -fms-extensions -fno-strict-aliasing) # Prevent GCC from searching any of the default directories. # The case for C++ is handled through the reactos_c++ INTERFACE library add_compile_options("$<$>:-nostdinc>") -add_compile_flags("-mstackrealign") -add_compile_flags("-fno-aggressive-loop-optimizations") +add_compile_options(-mstackrealign -fno-aggressive-loop-optimizations) if(CMAKE_C_COMPILER_ID STREQUAL "Clang") add_compile_options("$<$:-std=gnu99;-Wno-microsoft>") @@ -72,81 +71,81 @@ endif() # Debugging if(NOT CMAKE_BUILD_TYPE STREQUAL "Release") if(SEPARATE_DBG) - add_compile_flags("-gdwarf-2 -ggdb") + add_compile_options(-gdwarf-2 -ggdb) else() - add_compile_flags("-gdwarf-2 -gstrict-dwarf") - if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") - add_compile_flags("-femit-struct-debug-detailed=none -feliminate-unused-debug-symbols") + add_compile_options(-gdwarf-2 -gstrict-dwarf) + if(NOT CMAKE_C_COMPILER_ID STREQUAL Clang) + add_compile_options(-femit-struct-debug-detailed=none -feliminate-unused-debug-symbols) endif() endif() endif() # Tuning if(ARCH STREQUAL "i386") - add_compile_flags("-march=${OARCH} -mtune=${TUNE}") + add_compile_options(-march=${OARCH} -mtune=${TUNE}) else() - add_compile_flags("-march=${OARCH}") + add_compile_options(-march=${OARCH}) endif() # Warnings, errors -if((NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")) - add_compile_flags("-Werror") +if((NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND (NOT CMAKE_C_COMPILER_ID STREQUAL Clang)) + add_compile_options(-Werror) endif() -add_compile_flags("-Wall -Wpointer-arith") -add_compile_flags("-Wno-char-subscripts -Wno-multichar -Wno-unused-value") -add_compile_flags("-Wno-unused-const-variable") -add_compile_flags("-Wno-unused-local-typedefs") -add_compile_flags("-Wno-deprecated") +add_compile_options(-Wall -Wpointer-arith) +add_compile_options(-Wno-char-subscripts -Wno-multichar -Wno-unused-value) +add_compile_options(-Wno-unused-const-variable) +add_compile_options(-Wno-unused-local-typedefs) +add_compile_options(-Wno-deprecated) if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") - add_compile_flags("-Wno-maybe-uninitialized") + add_compile_options(-Wno-maybe-uninitialized) endif() if(ARCH STREQUAL "amd64") - add_compile_flags("-Wno-format") + add_compile_options(-Wno-format) elseif(ARCH STREQUAL "arm") - add_compile_flags("-Wno-attributes") + add_compile_options(-Wno-attributes) endif() # Optimizations # FIXME: Revisit this to see if we even need these levels if(CMAKE_BUILD_TYPE STREQUAL "Release") - add_compile_flags("-O2 -DNDEBUG") + add_compile_options(-O2 -DNDEBUG) else() if(OPTIMIZE STREQUAL "1") - add_compile_flags("-Os -ftracer") + add_compile_options(-Os -ftracer) elseif(OPTIMIZE STREQUAL "2") - add_compile_flags("-Os") + add_compile_options(-Os) elseif(OPTIMIZE STREQUAL "3") - add_compile_flags("-Og") + add_compile_options(-Og) elseif(OPTIMIZE STREQUAL "4") - add_compile_flags("-O1") + add_compile_options(-O1) elseif(OPTIMIZE STREQUAL "5") - add_compile_flags("-O2") + add_compile_options(-O2) elseif(OPTIMIZE STREQUAL "6") - add_compile_flags("-O3") + add_compile_options(-O3) elseif(OPTIMIZE STREQUAL "7") - add_compile_flags("-Ofast") + add_compile_options(-Ofast) endif() endif() # Link-time code generation if(LTCG) - add_compile_flags("-flto -fno-fat-lto-objects") + add_compile_options(-flto -fno-fat-lto-objects) endif() if(ARCH STREQUAL "i386") - add_compile_flags("-fno-optimize-sibling-calls -fno-omit-frame-pointer") + add_compile_options(-fno-optimize-sibling-calls -fno-omit-frame-pointer) if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") - add_compile_flags("-mpreferred-stack-boundary=3 -fno-set-stack-executable") + add_compile_options(-mpreferred-stack-boundary=3 -fno-set-stack-executable) endif() # FIXME: this doesn't work. CMAKE_BUILD_TYPE is always "Debug" if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - add_compile_flags("-momit-leaf-frame-pointer") + add_compile_options(-momit-leaf-frame-pointer) endif() elseif(ARCH STREQUAL "amd64") - add_compile_flags("-mpreferred-stack-boundary=4") + add_compile_options(-mpreferred-stack-boundary=4) endif() # Other diff --git a/sdk/cmake/msvc.cmake b/sdk/cmake/msvc.cmake index f44af850478..8af5b6094c1 100644 --- a/sdk/cmake/msvc.cmake +++ b/sdk/cmake/msvc.cmake @@ -2,32 +2,29 @@ #if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug") # no optimization - add_compile_flags("/Ob0 /Od") + add_compile_options(/Ob0 /Od) elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - add_compile_flags("/Ox /Ob2 /Ot /Oy /GT") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF") + add_compile_options(/Ox /Ob2 /Ot /Oy /GT) elseif(OPTIMIZE STREQUAL "1") - add_compile_flags("/O1") + add_compile_options(/O1) elseif(OPTIMIZE STREQUAL "2") - add_compile_flags("/O2") + add_compile_options(/O2) elseif(OPTIMIZE STREQUAL "3") - add_compile_flags("/Ot /Ox /GS-") + add_compile_options(/Ot /Ox /GS-) elseif(OPTIMIZE STREQUAL "4") - add_compile_flags("/Os /Ox /GS-") + add_compile_options(/Os /Ox /GS-) elseif(OPTIMIZE STREQUAL "5") - add_compile_flags("/Gy /Ob2 /Os /Ox /GS-") + add_compile_options(/Gy /Ob2 /Os /Ox /GS-) endif() # Always use string pooling: this helps reducing the binaries size since a lot # of redundancy come from the usage of __FILE__ / __RELFILE__ in the debugging # helper macros. Note also that GCC builds use string pooling by default. -add_compile_flags("/GF") +add_compile_options(/GF) # Enable function level linking and comdat folding -add_compile_flags("/Gy") -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF /OPT:ICF") -set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /OPT:REF /OPT:ICF") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF") +add_compile_options(/Gy) +add_link_options(/OPT:REF /OPT:ICF) if(ARCH STREQUAL "i386") add_definitions(/DWIN32 /D_WINDOWS) @@ -37,12 +34,11 @@ add_definitions(/Dinline=__inline /D__STDC__=1) # Ignore any "standard" include paths, and do not use any default CRT library. if(NOT USE_CLANG_CL) - add_compile_flags("/X /Zl") + add_compile_options(/X /Zl) endif() -# Disable RTTI, exception handling and buffer security checks by default. -# These require run-time support that may not always be available. -add_compile_flags("/GS-") +# Disable buffer security checks by default. +add_compile_options(/GS-) if(USE_CLANG_CL) set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: ") @@ -53,29 +49,29 @@ endif() if(ARCH STREQUAL "i386") # Clang's IA32 means i386, which doesn't have cmpxchg8b if(USE_CLANG_CL) - add_compile_flags("-march=${OARCH}") + add_compile_options(-march=${OARCH}) else() - add_compile_flags("/arch:IA32") + add_compile_options(/arch:IA32) endif() endif() # VS 12+ requires /FS when used in parallel compilations if(NOT MSVC_IDE) - add_compile_flags("/FS") + add_compile_options(/FS) endif() # VS14+ tries to use thread-safe initialization -add_compile_flags("/Zc:threadSafeInit-") +add_compile_options(/Zc:threadSafeInit-) # HACK: Disable use of __CxxFrameHandler4 on VS 16.3+ (x64 only) # See https://developercommunity.visualstudio.com/content/problem/746534/visual-c-163-runtime-uses-an-unsupported-api-for-u.html if(ARCH STREQUAL "amd64" AND MSVC_VERSION GREATER 1922) - add_compile_flags("/d2FH4-") - add_link_options("/d2:-FH4-") + add_compile_options(/d2FH4-) + add_link_options(/d2:-FH4-) endif() # Generate Warnings Level 3 -add_compile_flags("/W3") +add_compile_options(/W3) # Disable overly sensitive warnings as well as those that generally aren't # useful to us. @@ -84,10 +80,10 @@ add_compile_flags("/W3") # - C4800: forcing value to bool 'true' or 'false' (performance warning) # - C4200: nonstandard extension used : zero-sized array in struct/union # - C4214: nonstandard extension used : bit field types other than int -add_compile_flags("/wd4244 /wd4290 /wd4800 /wd4200 /wd4214") +add_compile_options(/wd4244 /wd4290 /wd4800 /wd4200 /wd4214) # FIXME: Temporarily disable C4018 until we fix more of the others. CORE-10113 -add_compile_flags("/wd4018") +add_compile_options(/wd4018) # The following warnings are treated as errors: # - C4013: implicit function declaration @@ -122,19 +118,17 @@ endif() # Enable warnings above the default level, but don't treat them as errors: # - C4115: named type definition in parentheses -add_compile_flags("/w14115") +add_compile_options(/w14115) if(USE_CLANG_CL) add_compile_options("$<$:-nostdinc;-Wno-multichar;-Wno-char-subscripts;-Wno-microsoft-enum-forward-reference;-Wno-pragma-pack;-Wno-microsoft-anon-tag;-Wno-parentheses-equality;-Wno-unknown-pragmas>") endif() # Debugging -#if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(NOT (_PREFAST_ OR _VS_ANALYZE_)) - add_compile_flags("/Zi") + add_compile_options(/Zi) endif() -#elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release") elseif(CMAKE_BUILD_TYPE STREQUAL "Release") add_definitions("/D NDEBUG") endif() @@ -155,12 +149,11 @@ endif() if(RUNTIME_CHECKS) add_definitions(-D__RUNTIME_CHECKS__) - add_compile_flags("/RTC1") + add_compile_options(/RTC1) endif() -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4039") -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4104 /IGNORE:4039") -set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4039") +add_link_options(/MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4039) + set(CMAKE_MSVC_RUNTIME_LIBRARY "") # HACK: Remove the /implib argument, implibs are generated separately @@ -202,7 +195,7 @@ endif() if(_VS_ANALYZE_) message("VS static analysis enabled!") - add_compile_flags("/analyze") + add_compile_options(/analyze) elseif(_PREFAST_) message("PREFAST enabled!") set(CMAKE_C_COMPILE_OBJECT "prefast ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} /Fo -c ${CMAKE_END_TEMP_FILE}" diff --git a/sdk/lib/crt/msvcrtex.cmake b/sdk/lib/crt/msvcrtex.cmake index 66b90d47ed8..b55f53ce659 100644 --- a/sdk/lib/crt/msvcrtex.cmake +++ b/sdk/lib/crt/msvcrtex.cmake @@ -1,13 +1,6 @@ include_directories(include/internal/mingw-w64) -if(NOT MSVC) - add_compile_flags("-Wno-main") - if(LTCG) - add_compile_flags("-fno-lto") - endif() -endif() - list(APPEND MSVCRTEX_SOURCE startup/crtexe.c startup/wcrtexe.c @@ -102,11 +95,19 @@ add_asm_files(msvcrtex_asm ${MSVCRTEX_ASM_SOURCE}) add_library(msvcrtex ${MSVCRTEX_SOURCE} ${msvcrtex_asm}) target_compile_definitions(msvcrtex PRIVATE _DLL _MSVCRTEX_) + +if ((NOT MSVC) OR USE_CLANG_CL) + target_compile_options(msvcrtex PRIVATE $<$:-Wno-main>) + if (LTCG) + target_compile_options(msvcrtex PRIVATE -fno-lto) + endif() +endif() + set_source_files_properties(startup/crtdll.c PROPERTIES COMPILE_DEFINITIONS CRTDLL) set_source_files_properties(startup/crtexe.c startup/wcrtexe.c PROPERTIES COMPILE_DEFINITIONS _M_CEE_PURE) -if(NOT MSVC) +if (NOT MSVC) target_link_libraries(msvcrtex oldnames) endif() diff --git a/sdk/lib/drivers/lwip/CMakeLists.txt b/sdk/lib/drivers/lwip/CMakeLists.txt index a0ea078abed..4b70c3c472c 100644 --- a/sdk/lib/drivers/lwip/CMakeLists.txt +++ b/sdk/lib/drivers/lwip/CMakeLists.txt @@ -62,8 +62,6 @@ add_library(lwip ${SOURCE}) add_dependencies(lwip bugcodes xdk) add_pch(lwip precomp.h SOURCE) -if(NOT MSVC) - if(LTCG) - add_compile_flags("-fno-builtin-malloc -fno-builtin-free") - endif() +if((NOT MSVC) AND LTCG) + target_compile_options(lwip PRIVATE -fno-builtin-malloc -fno-builtin-free) endif() diff --git a/sdk/tools/wpp/CMakeLists.txt b/sdk/tools/wpp/CMakeLists.txt index 4eef72c5231..0b68ae806cc 100644 --- a/sdk/tools/wpp/CMakeLists.txt +++ b/sdk/tools/wpp/CMakeLists.txt @@ -12,11 +12,10 @@ if(MSVC) endif() endif() - # Disable warning " unary minus operator applied to unsigned type, result still unsigned" - add_compile_flags("/wd4146") - - # Disable warning "'=': conversion from 'a' to 'b', possible loss of data" - add_compile_flags("/wd4244") + # Disable warnings + add_compile_options( + /wd4146 # " unary minus operator applied to unsigned type, result still unsigned" + /wd4244) # "'=': conversion from 'a' to 'b', possible loss of data" endif()