https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7e116f0ef368e8fbd7e87a1ae13f69c4cc8b58c1

commit 7e116f0ef368e8fbd7e87a1ae13f69c4cc8b58c1
Author:     Jérôme Gardou <[email protected]>
AuthorDate: Fri Sep 18 11:49:18 2020 +0200
Commit:     Jérôme Gardou <[email protected]>
CommitDate: Tue Oct 20 21:44:54 2020 +0200

    [CMAKE] Get rid of replace_compile_flags
    
    Introduce a finer-grained remove_target_compile_option instead
---
 base/applications/wordpad/CMakeLists.txt           | 10 +++++-----
 base/services/nfsd/CMakeLists.txt                  |  9 +++------
 boot/freeldr/freeldr/CMakeLists.txt                |  7 ++++---
 dll/3rdparty/libtiff/CMakeLists.txt                | 16 +++++++---------
 dll/3rdparty/libtirpc/CMakeLists.txt               | 20 +++++++++-----------
 dll/win32/clusapi/CMakeLists.txt                   | 11 ++++++-----
 dll/win32/comctl32/CMakeLists.txt                  |  6 ++++--
 dll/win32/crypt32/CMakeLists.txt                   | 10 +++++-----
 dll/win32/dbghelp/CMakeLists.txt                   |  8 +++-----
 dll/win32/mshtml/CMakeLists.txt                    | 10 +++++-----
 dll/win32/msi/CMakeLists.txt                       | 16 ++++++++--------
 dll/win32/msrle32/CMakeLists.txt                   | 11 ++++++-----
 dll/win32/shell32/CMakeLists.txt                   | 10 +++++-----
 dll/win32/windowscodecs/CMakeLists.txt             | 10 +++++-----
 dll/win32/winmm/CMakeLists.txt                     | 11 ++++++-----
 dll/win32/winmm/midimap/CMakeLists.txt             | 11 ++++++-----
 drivers/filesystems/ext2/CMakeLists.txt            |  4 ++--
 drivers/filesystems/reiserfs/CMakeLists.txt        |  4 ++--
 modules/rostests/winetests/CMakeLists.txt          | 20 +++++++++++---------
 modules/rostests/winetests/comctl32/CMakeLists.txt |  4 +---
 modules/rostests/winetests/gdiplus/CMakeLists.txt  | 10 +++++-----
 modules/rostests/winetests/kernel32/CMakeLists.txt | 10 +++++-----
 modules/rostests/winetests/user32/CMakeLists.txt   | 14 +++++++-------
 sdk/cmake/compilerflags.cmake                      | 20 +++++++++-----------
 sdk/cmake/msvc.cmake                               |  6 +++---
 sdk/lib/3rdparty/freetype/CMakeLists.txt           | 10 ++++------
 sdk/lib/3rdparty/libxml2/CMakeLists.txt            |  4 ++--
 27 files changed, 138 insertions(+), 144 deletions(-)

diff --git a/base/applications/wordpad/CMakeLists.txt 
b/base/applications/wordpad/CMakeLists.txt
index 4953dd84bbc..759331f3546 100644
--- a/base/applications/wordpad/CMakeLists.txt
+++ b/base/applications/wordpad/CMakeLists.txt
@@ -4,11 +4,6 @@ remove_definitions(-D_WIN32_IE=0x600)
 add_definitions(-D__ROS_LONG64__)
 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 
-if(MSVC)
-    # Disable warning C4477 (printf format warnings)
-    add_compile_flags("/wd4477")
-endif()
-
 list(APPEND SOURCE
     olecallback.c
     print.c
@@ -22,3 +17,8 @@ set_module_type(wordpad win32gui)
 target_link_libraries(wordpad wine uuid)
 add_importlibs(wordpad comdlg32 ole32 shell32 user32 gdi32 advapi32 comctl32 
msvcrt kernel32 ntdll)
 add_cd_file(TARGET wordpad DESTINATION reactos/system32 FOR all)
+
+if(MSVC)
+    # Disable warning C4477 (printf format warnings)
+    target_compile_options(wordpad PRIVATE /wd4477)
+endif()
diff --git a/base/services/nfsd/CMakeLists.txt 
b/base/services/nfsd/CMakeLists.txt
index 0da38928297..5726c898cb6 100644
--- a/base/services/nfsd/CMakeLists.txt
+++ b/base/services/nfsd/CMakeLists.txt
@@ -7,12 +7,7 @@ include_directories(
     ${REACTOS_SOURCE_DIR}/drivers/filesystems/nfs
     ${REACTOS_SOURCE_DIR}/dll/np/nfs)
 
-if(MSVC)
-    # Disable warning C4477 (printf format warnings)
-    add_compile_flags("/wd4477")
-endif()
-
-list(APPEND SOURCE 
+list(APPEND SOURCE
     acl.c
     callback_server.c
     callback_xdr.c
@@ -54,6 +49,8 @@ list(APPEND SOURCE
 add_executable(nfsd ${SOURCE} nfsd.rc)
 
 if(MSVC AND (NOT USE_CLANG_CL))
+    # Disable warning C4477 (printf format warnings)
+    target_compile_options(nfsd PRIVATE "/wd4477")
 else()
     # FIXME: Tons of warnings.
     target_compile_options(nfsd PRIVATE "-w")
diff --git a/boot/freeldr/freeldr/CMakeLists.txt 
b/boot/freeldr/freeldr/CMakeLists.txt
index 41d4ab68c86..80bea8f1f41 100644
--- a/boot/freeldr/freeldr/CMakeLists.txt
+++ b/boot/freeldr/freeldr/CMakeLists.txt
@@ -7,9 +7,6 @@ if(SEPARATE_DBG)
 endif()
 
 if(MSVC)
-    # We don't need hotpatching
-    replace_compile_flags("/hotpatch" " ")
-
     # Explicitly use string pooling
     add_compile_flags("/GF")
 endif()
@@ -285,6 +282,10 @@ if(MSVC)
         add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 
/DRIVER /FIXED /FILEALIGN:0x200 /ALIGN:0x200")
         add_linker_script(freeldr_pe_dbg freeldr_i386.msvc.lds)
     endif()
+    # We don't need hotpatching
+    remove_target_compile_option(freeldr_pe "/hotpatch")
+    remove_target_compile_option(freeldr_pe_dbg "/hotpatch")
+    remove_target_compile_option(freeldr_common "/hotpatch")
 else()
     add_target_link_flags(freeldr_pe 
"-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x200,--section-alignment,0x200")
     add_linker_script(freeldr_pe freeldr_i386.lds)
diff --git a/dll/3rdparty/libtiff/CMakeLists.txt 
b/dll/3rdparty/libtiff/CMakeLists.txt
index c8c388ba702..470cbba14c8 100644
--- a/dll/3rdparty/libtiff/CMakeLists.txt
+++ b/dll/3rdparty/libtiff/CMakeLists.txt
@@ -5,14 +5,6 @@ add_definitions(
     -DUSE_WIN32_FILEIO
     -DTIF_PLATFORM_CONSOLE)
 
-if(MSVC)
-    # error C4311: 'type cast': pointer truncation from 'thandle_t' to 'int'
-    replace_compile_flags("/we4311" " ")
-
-    # error C4312: 'type cast': conversion from 'int' to 'thandle_t' of 
greater size
-    replace_compile_flags("/we4312" " ")
-endif()
-
 include_directories(
     ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libtiff
     ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
@@ -63,12 +55,18 @@ list(APPEND SOURCE
     precomp.h)
 
 add_library(libtiff MODULE ${SOURCE} libtiff.def)
+
 set_module_type(libtiff win32dll)
 target_link_libraries(libtiff zlib getopt)
 add_importlibs(libtiff user32 msvcrt kernel32 ntdll)
 add_pch(libtiff precomp.h SOURCE)
 add_cd_file(TARGET libtiff DESTINATION reactos/system32 FOR all)
 
-if(NOT MSVC)
+if (MSVC)
+    # error C4311: 'type cast': pointer truncation from 'thandle_t' to 'int'
+    remove_target_compile_option(libtiff "/we4311")
+    # error C4312: 'type cast': conversion from 'int' to 'thandle_t' of 
greater size
+    remove_target_compile_option(libtiff "/we4312")
+else()
     target_compile_options(libtiff PRIVATE "-Wno-unused-but-set-variable")
 endif()
diff --git a/dll/3rdparty/libtirpc/CMakeLists.txt 
b/dll/3rdparty/libtirpc/CMakeLists.txt
index 207ccb87a98..0ef4cc49132 100644
--- a/dll/3rdparty/libtirpc/CMakeLists.txt
+++ b/dll/3rdparty/libtirpc/CMakeLists.txt
@@ -6,14 +6,6 @@ add_definitions(-DUNICODE -D_WIN32 -DPORTMAP -Dstrdup=_strdup 
-D_CRT_NONSTDC_NO_
 
 include_directories(${REACTOS_SOURCE_DIR}/dll/3rdparty/libtirpc/tirpc)
 
-if(MSVC)
-    # error C4133: '=': incompatible types - from 'char *' to 'int32_t *'
-    replace_compile_flags("/we4133" " ")
-
-    # Disable warning C4477 (printf format warnings)
-    add_compile_flags("/wd4313")
-endif()
-
 list(APPEND SOURCE
     src/asprintf.c
 #    src/auth_des.c
@@ -101,9 +93,15 @@ add_library(libtirpc MODULE
     libtirpc/libtirpc_ros.rc
     ${CMAKE_CURRENT_BINARY_DIR}/libtirpc.def)
 
-if(MSVC AND (NOT USE_CLANG_CL))
-    replace_compile_flags("/we4101" " ")
-    target_compile_options(libtirpc PRIVATE /wd4101 /wd4133 /wd4473 /wd4477)
+if(MSVC)
+    # error C4133: '=': incompatible types - from 'char *' to 'int32_t *'
+    remove_target_compile_option(libtirpc "/we4133")
+    # Disable warning C4477 (printf format warnings)
+    target_compile_options(libtirpc PRIVATE /wd4313)
+    if (NOT USE_CLANG_CL)
+        remove_target_compile_option(libtirpc "/we4101")
+        target_compile_options(libtirpc PRIVATE /wd4101 /wd4133 /wd4473 
/wd4477)
+    endif()
 else()
     # FIXME: Tons of warnings.
     target_compile_options(libtirpc PRIVATE "-w")
diff --git a/dll/win32/clusapi/CMakeLists.txt b/dll/win32/clusapi/CMakeLists.txt
index 40cfdd21f24..b060e4b94df 100644
--- a/dll/win32/clusapi/CMakeLists.txt
+++ b/dll/win32/clusapi/CMakeLists.txt
@@ -3,17 +3,18 @@ add_definitions(-D__WINESRC__)
 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 spec2def(clusapi.dll clusapi.spec)
 
-if(MSVC)
-    # error C4312: 'type cast': conversion from 'unsigned int' to 'HCLUSTER' 
of greater size
-    replace_compile_flags("/we4312" " ")
-endif()
-
 list(APPEND SOURCE
     clusapi.c
     ${CMAKE_CURRENT_BINARY_DIR}/clusapi_stubs.c
     ${CMAKE_CURRENT_BINARY_DIR}/clusapi.def)
 
 add_library(clusapi MODULE ${SOURCE})
+
+if(MSVC)
+    # error C4312: 'type cast': conversion from 'unsigned int' to 'HCLUSTER' 
of greater size
+    remove_target_compile_option(clusapi "/we4312")
+endif()
+
 set_module_type(clusapi win32dll)
 target_link_libraries(clusapi wine)
 add_importlibs(clusapi msvcrt kernel32 ntdll)
diff --git a/dll/win32/comctl32/CMakeLists.txt 
b/dll/win32/comctl32/CMakeLists.txt
index d60f18a1696..4d70e28eecc 100644
--- a/dll/win32/comctl32/CMakeLists.txt
+++ b/dll/win32/comctl32/CMakeLists.txt
@@ -12,8 +12,7 @@ include_directories(BEFORE 
${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 spec2def(comctl32.dll comctl32.spec ADD_IMPORTLIB)
 
 if(MSVC)
-    # Disable warning C4477 (printf format warnings)
-    add_compile_flags("/wd4477")
+
 endif()
 
 list(APPEND SOURCE
@@ -65,6 +64,9 @@ add_library(comctl32 MODULE
     rsrc.rc
     ${CMAKE_CURRENT_BINARY_DIR}/comctl32.def)
 
+# Disable warning C4477 (printf format warnings)
+target_compile_options(comctl32 PRIVATE $<$<BOOL:${MSVC}>:/wd4477>)
+
 set_module_type(comctl32 win32dll UNICODE)
 target_link_libraries(comctl32 uuid wine ${PSEH_LIB})
 add_delay_importlibs(comctl32 winmm uxtheme)
diff --git a/dll/win32/crypt32/CMakeLists.txt b/dll/win32/crypt32/CMakeLists.txt
index b9ccf7b85dc..6bb17abc850 100644
--- a/dll/win32/crypt32/CMakeLists.txt
+++ b/dll/win32/crypt32/CMakeLists.txt
@@ -11,11 +11,6 @@ add_definitions(
 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 spec2def(crypt32.dll crypt32.spec ADD_IMPORTLIB)
 
-if(MSVC)
-    # error C4312: 'type cast': conversion from 'unsigned int' to 'void *' of 
greater size
-    replace_compile_flags("/we4312" " ")
-endif()
-
 list(APPEND SOURCE
     base64.c
     cert.c
@@ -51,6 +46,11 @@ add_library(crypt32 MODULE
     crypt32.rc
     ${CMAKE_CURRENT_BINARY_DIR}/crypt32.def)
 
+if(MSVC)
+    # error C4312: 'type cast': conversion from 'unsigned int' to 'void *' of 
greater size
+    remove_target_compile_option(crypt32 "/we4312")
+endif()
+
 set_module_type(crypt32 win32dll)
 target_link_libraries(crypt32 wine ${PSEH_LIB} oldnames)
 add_delay_importlibs(crypt32 cryptnet)
diff --git a/dll/win32/dbghelp/CMakeLists.txt b/dll/win32/dbghelp/CMakeLists.txt
index 508a9692842..b72e79e7584 100644
--- a/dll/win32/dbghelp/CMakeLists.txt
+++ b/dll/win32/dbghelp/CMakeLists.txt
@@ -1,9 +1,4 @@
 
-if(MSVC)
-    # Disable warning C4477 (printf format warnings)
-    add_compile_flags("/wd4477")
-endif()
-
 if(NOT CMAKE_CROSSCOMPILING)
     add_definitions(-DDBGHELP_STATIC_LIB)
 
@@ -85,4 +80,7 @@ else()
     add_pch(dbghelp precomp.h SOURCE)
     add_cd_file(TARGET dbghelp DESTINATION reactos/system32 FOR all)
 
+    if (MSVC)
+        target_compile_options(dbghelp PRIVATE /wd4477)
+    endif()
 endif()
diff --git a/dll/win32/mshtml/CMakeLists.txt b/dll/win32/mshtml/CMakeLists.txt
index a225f25d64f..327e719aa0c 100644
--- a/dll/win32/mshtml/CMakeLists.txt
+++ b/dll/win32/mshtml/CMakeLists.txt
@@ -11,11 +11,6 @@ 
include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 add_idl_headers(mshtml_nsiface_header nsiface.idl)
 spec2def(mshtml.dll mshtml.spec ADD_IMPORTLIB)
 
-if(MSVC)
-    # error C4028: formal parameter 3 different from declaration
-    replace_compile_flags("/we4028" " ")
-endif()
-
 list(APPEND SOURCE
     conpoint.c
     dispex.c
@@ -105,6 +100,11 @@ add_library(mshtml MODULE
     rsrc.rc
     ${CMAKE_CURRENT_BINARY_DIR}/mshtml.def)
 
+if(MSVC)
+    # error C4028: formal parameter 3 different from declaration
+    remove_target_compile_option(mshtml "/we4028")
+endif()
+
 list(APPEND mshtml_rc_deps
     ${CMAKE_CURRENT_SOURCE_DIR}/blank.htm
     ${CMAKE_CURRENT_SOURCE_DIR}/mshtml.inf
diff --git a/dll/win32/msi/CMakeLists.txt b/dll/win32/msi/CMakeLists.txt
index 106f6817851..73600cf4c6b 100644
--- a/dll/win32/msi/CMakeLists.txt
+++ b/dll/win32/msi/CMakeLists.txt
@@ -7,14 +7,6 @@ add_definitions(-D__WINESRC__ -D__ROS_LONG64__ 
-DMSIRUNMODE=MSIRUNMODE_T)
 spec2def(msi.dll msi.spec ADD_IMPORTLIB)
 generate_idl_iids(msiserver.idl)
 
-if(MSVC)
-    #  error C4133: 'function': incompatible types - from 'UINT *' to 
'MSIINSTALLCONTEXT *'
-    replace_compile_flags("/we4133" " ")
-
-    # error C4312: 'type cast': conversion from 'unsigned int' to 'HANDLE' of 
greater size
-    replace_compile_flags("/we4312" " ")
-endif()
-
 list(APPEND SOURCE
     action.c
     alter.c
@@ -71,6 +63,14 @@ add_library(msi MODULE
     msi.rc
     ${CMAKE_CURRENT_BINARY_DIR}/msi.def)
 
+if(MSVC)
+    #  error C4133: 'function': incompatible types - from 'UINT *' to 
'MSIINSTALLCONTEXT *'
+    remove_target_compile_option(msi "/we4133")
+
+    # error C4312: 'type cast': conversion from 'unsigned int' to 'HANDLE' of 
greater size
+    remove_target_compile_option(msi "/we4312")
+endif()
+
 add_idl_headers(msi_idlheader msiserver.idl)
 add_typelib(msiserver.idl)
 set_source_files_properties(msi.rc PROPERTIES OBJECT_DEPENDS 
${CMAKE_CURRENT_BINARY_DIR}/msiserver.tlb)
diff --git a/dll/win32/msrle32/CMakeLists.txt b/dll/win32/msrle32/CMakeLists.txt
index 04706201560..85311b2fad5 100644
--- a/dll/win32/msrle32/CMakeLists.txt
+++ b/dll/win32/msrle32/CMakeLists.txt
@@ -3,16 +3,17 @@ add_definitions(-D__WINESRC__)
 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 spec2def(msrle32.dll msrle32.spec)
 
-if(MSVC)
-    # error C4312: 'type cast': conversion from 'unsigned int' to 'LPVOID' of 
greater size
-    replace_compile_flags("/we4312" " ")
-endif()
-
 list(APPEND SOURCE
     msrle32.c
     ${CMAKE_CURRENT_BINARY_DIR}/msrle32.def)
 
 add_library(msrle32 MODULE ${SOURCE} rsrc.rc)
+
+if(MSVC)
+    # error C4312: 'type cast': conversion from 'unsigned int' to 'LPVOID' of 
greater size
+    remove_target_compile_option(msrle32 "/we4312")
+endif()
+
 set_module_type(msrle32 win32dll)
 target_link_libraries(msrle32 wine)
 add_importlibs(msrle32 winmm user32 msvcrt kernel32 ntdll)
diff --git a/dll/win32/shell32/CMakeLists.txt b/dll/win32/shell32/CMakeLists.txt
index 88a11e013c8..464ef62774b 100644
--- a/dll/win32/shell32/CMakeLists.txt
+++ b/dll/win32/shell32/CMakeLists.txt
@@ -11,11 +11,6 @@ if(NOT MSVC)
     add_compile_flags_language("-std=c++11" "CXX")
 endif()
 
-if(MSVC)
-    # error C4311: 'type cast': pointer truncation from 'HANDLE' to 'INT'
-    replace_compile_flags("/we4311" " ")
-endif()
-
 remove_definitions(-D_WIN32_WINNT=0x502)
 add_definitions(-D_WIN32_WINNT=0x600)
 
@@ -112,6 +107,11 @@ add_library(shell32 MODULE
     shell32.rc
     ${CMAKE_CURRENT_BINARY_DIR}/shell32.def)
 
+if (MSVC)
+    # error C4311: 'type cast': pointer truncation from 'HANDLE' to 'INT'
+    remove_target_compile_option(shell32 "/we4311")
+endif()
+
 add_typelib(shell32_shldisp.idl)
 set_source_files_properties(shell32.rc PROPERTIES OBJECT_DEPENDS 
${CMAKE_CURRENT_BINARY_DIR}/shell32_shldisp.tlb)
 
diff --git a/dll/win32/windowscodecs/CMakeLists.txt 
b/dll/win32/windowscodecs/CMakeLists.txt
index ff726c88162..fd29c68ad48 100644
--- a/dll/win32/windowscodecs/CMakeLists.txt
+++ b/dll/win32/windowscodecs/CMakeLists.txt
@@ -9,11 +9,6 @@ add_definitions(
 remove_definitions(-D_WIN32_WINNT=0x502)
 add_definitions(-D_WIN32_WINNT=0x600)
 
-if(MSVC)
-    # error C4133: 'function': incompatible types - from 
'WICPixelFormatNumericRepresentation *' to 'DWORD *'
-    replace_compile_flags("/we4133" " ")
-endif()
-
 include_directories(
     BEFORE ${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine
     ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/libjpeg
@@ -79,6 +74,11 @@ add_library(windowscodecs MODULE
     version.rc
     ${CMAKE_CURRENT_BINARY_DIR}/windowscodecs.def)
 
+if(MSVC)
+    # error C4133: 'function': incompatible types - from 
'WICPixelFormatNumericRepresentation *' to 'DWORD *'
+    remove_target_compile_option(windowscodecs "/we4133")
+endif()
+
 set_module_type(windowscodecs win32dll)
 target_link_libraries(windowscodecs wine uuid ${PSEH_LIB})
 add_importlibs(windowscodecs ole32 oleaut32 rpcrt4 shlwapi user32 gdi32 
advapi32 advapi32_vista propsys msvcrt kernel32 ntdll)
diff --git a/dll/win32/winmm/CMakeLists.txt b/dll/win32/winmm/CMakeLists.txt
index fd746a2bafb..640ebf63081 100644
--- a/dll/win32/winmm/CMakeLists.txt
+++ b/dll/win32/winmm/CMakeLists.txt
@@ -3,11 +3,6 @@ add_definitions(-D_WINE)
 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 spec2def(winmm.dll winmm.spec ADD_IMPORTLIB)
 
-if(MSVC)
-    # error C4312: 'type cast': conversion from 'DWORD' to 'HTASK' of greater 
size
-    replace_compile_flags("/we4312" " ")
-endif()
-
 list(APPEND SOURCE
     driver.c
     joystick.c
@@ -26,6 +21,12 @@ add_library(winmm MODULE
     winmm_res.rc
     ${CMAKE_CURRENT_BINARY_DIR}/winmm.def)
 
+
+if(MSVC)
+    # error C4312: 'type cast': conversion from 'DWORD' to 'HTASK' of greater 
size
+    remove_target_compile_option(winmm "/we4312")
+endif()
+
 set_module_type(winmm win32dll)
 target_link_libraries(winmm wine ${PSEH_LIB})
 add_importlibs(winmm advapi32 user32 msvcrt kernel32 ntdll)
diff --git a/dll/win32/winmm/midimap/CMakeLists.txt 
b/dll/win32/winmm/midimap/CMakeLists.txt
index cc35e2b0809..2e4aaa22403 100644
--- a/dll/win32/winmm/midimap/CMakeLists.txt
+++ b/dll/win32/winmm/midimap/CMakeLists.txt
@@ -1,17 +1,18 @@
 
 spec2def(midimap.dll midimap.spec)
 
-if(MSVC)
-    # error C4133: 'function': incompatible types - from 'LPDWORD' to 
'DWORD_PTR *'
-    replace_compile_flags("/we4133" " ")
-endif()
-
 add_library(midimap MODULE
     midimap.c
     midimap.rc
     ${CMAKE_CURRENT_BINARY_DIR}/midimap.def)
 
 set_module_type(midimap win32dll UNICODE)
+
+if(MSVC)
+    # error C4133: 'function': incompatible types - from 'LPDWORD' to 
'DWORD_PTR *'
+    remove_target_compile_option(midimap "/we4133")
+endif()
+
 target_link_libraries(midimap uuid wine)
 add_importlibs(midimap advapi32 user32 winmm msvcrt kernel32 ntdll)
 add_cd_file(TARGET midimap DESTINATION reactos/system32 FOR all)
diff --git a/drivers/filesystems/ext2/CMakeLists.txt 
b/drivers/filesystems/ext2/CMakeLists.txt
index b362a60f56d..38851437730 100644
--- a/drivers/filesystems/ext2/CMakeLists.txt
+++ b/drivers/filesystems/ext2/CMakeLists.txt
@@ -94,8 +94,8 @@ endif()
 
 if(MSVC AND (NOT USE_CLANG_CL))
     # Disable warnings: "unreferenced local variable", "initialized, but not 
used variable", "benign include"
-    replace_compile_flags("/we4101" " ")
-    replace_compile_flags("/we4189" " ")
+    remove_target_compile_option(ext2fs "/we4101")
+    remove_target_compile_option(ext2fs "/we4189")
     target_compile_options(ext2fs PRIVATE /wd4189 /wd4142 /wd4101)
 else()
     target_compile_options(ext2fs PRIVATE -Wno-pointer-sign 
-Wno-unused-function)
diff --git a/drivers/filesystems/reiserfs/CMakeLists.txt 
b/drivers/filesystems/reiserfs/CMakeLists.txt
index cd939d40b85..b921bbfa250 100644
--- a/drivers/filesystems/reiserfs/CMakeLists.txt
+++ b/drivers/filesystems/reiserfs/CMakeLists.txt
@@ -87,8 +87,8 @@ if(USE_CLANG_CL OR (NOT MSVC))
     endif()
 else()
     #disable warnings: "unreferenced local variable", "initialized, but not 
used variable", "benign include"
-    replace_compile_flags("/we4101" " ")
-    replace_compile_flags("/we4189" " ")
+    remove_target_compile_option(reiserfs "/we4101")
+    remove_target_compile_option(reiserfs "/we4189")
     target_compile_options(reiserfs PRIVATE /wd4189 /wd4142 /wd4101)
 endif()
 
diff --git a/modules/rostests/winetests/CMakeLists.txt 
b/modules/rostests/winetests/CMakeLists.txt
index 45a146c75d9..abf5f5efe4b 100644
--- a/modules/rostests/winetests/CMakeLists.txt
+++ b/modules/rostests/winetests/CMakeLists.txt
@@ -2,16 +2,18 @@
 add_definitions(-D__ROS_LONG64__)
 
 if(MSVC)
-    add_compile_flags("/wd4090") # C4090: 'function': different 'const' 
qualifiers
-    add_compile_flags("/wd4133") # C4133: 'function': incompatible types - 
from '<enum> *' to 'UINT *'
-    add_compile_flags("/wd4146") # C4146: unary minus operator applied to 
unsigned type, result still unsigned
-    add_compile_flags("/wd4189") # C4189: 'x': local variable is initialized 
but not referenced
-    add_compile_flags("/wd4267") # C4267: '=': conversion from 'size_t' to 
'int', possible loss of data
-    add_compile_flags("/wd4305") # C4305: '=': truncation from 'double' to 
'FLOAT'
+    add_compile_options(
+        /wd4090 # C4090: 'function': different 'const' qualifiers
+        /wd4133 # C4133: 'function': incompatible types - from '<enum> *' to 
'UINT *'
+        /wd4146 # C4146: unary minus operator applied to unsigned type, result 
still unsigned
+        /wd4189 # C4189: 'x': local variable is initialized but not referenced
+        /wd4267 # C4267: '=': conversion from 'size_t' to 'int', possible loss 
of data
+        /wd4305) # C4305: '=': truncation from 'double' to 'FLOAT'
     if(ARCH STREQUAL "amd64")
-        add_compile_flags("/wd4101") # C4101: 'x': unreferenced local variable
-        add_compile_flags("/wd4312") # C4312: 'type cast': conversion from 
'unsigned int' to 'char *' of greater size
-        add_compile_flags("/wd4334") # C4334: '<<': result of 32-bit shift 
implicitly converted to 64 bits (was 64-bit shift intended?)
+        add_compile_options(
+            /wd4101 # C4101: 'x': unreferenced local variable
+            /wd4312 # C4312: 'type cast': conversion from 'unsigned int' to 
'char *' of greater size
+            /wd4334) # C4334: '<<': result of 32-bit shift implicitly 
converted to 64 bits (was 64-bit shift intended?)
     endif()
 endif()
 
diff --git a/modules/rostests/winetests/comctl32/CMakeLists.txt 
b/modules/rostests/winetests/comctl32/CMakeLists.txt
index ddc4caf0dc9..604e0509bba 100644
--- a/modules/rostests/winetests/comctl32/CMakeLists.txt
+++ b/modules/rostests/winetests/comctl32/CMakeLists.txt
@@ -42,9 +42,7 @@ add_executable(comctl32_winetest
     ${PCH_SKIP_SOURCE}
     rsrc.rc)
 
-if(USE_CLANG_CL OR (NOT MSVC))
-    target_compile_options(comctl32_winetest PRIVATE "-Wno-format")
-endif()
+target_compile_options(comctl32_winetest PRIVATE 
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wno-format>)
 
 set_module_type(comctl32_winetest win32cui)
 add_importlibs(comctl32_winetest comctl32 ole32 user32 gdi32 advapi32 msvcrt 
kernel32)
diff --git a/modules/rostests/winetests/gdiplus/CMakeLists.txt 
b/modules/rostests/winetests/gdiplus/CMakeLists.txt
index 73a04034472..df3cbc98e07 100644
--- a/modules/rostests/winetests/gdiplus/CMakeLists.txt
+++ b/modules/rostests/winetests/gdiplus/CMakeLists.txt
@@ -1,11 +1,6 @@
 
 add_definitions(-DUSE_WINE_TODOS)
 
-if(MSVC)
-    # error C4133: 'function': incompatible types - from 'ImageFlags *' to 
'UINT *'
-    replace_compile_flags("/we4133" " ")
-endif()
-
 list(APPEND SOURCE
     brush.c
     customlinecap.c
@@ -33,3 +28,8 @@ set_module_type(gdiplus_winetest win32cui)
 add_importlibs(gdiplus_winetest gdiplus user32 gdi32 ole32 msvcrt kernel32)
 add_pch(gdiplus_winetest precomp.h "${PCH_SKIP_SOURCE}")
 add_rostests_file(TARGET gdiplus_winetest)
+
+if(MSVC)
+    # error C4133: 'function': incompatible types - from 'ImageFlags *' to 
'UINT *'
+    remove_target_compile_option(gdiplus_winetest "/we4133")
+endif()
diff --git a/modules/rostests/winetests/kernel32/CMakeLists.txt 
b/modules/rostests/winetests/kernel32/CMakeLists.txt
index f61fe3cd9fb..6720ce33df7 100644
--- a/modules/rostests/winetests/kernel32/CMakeLists.txt
+++ b/modules/rostests/winetests/kernel32/CMakeLists.txt
@@ -3,11 +3,6 @@ include_directories(BEFORE 
${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 remove_definitions(-DWINVER=0x502 -D_WIN32_IE=0x600 -D_WIN32_WINNT=0x502)
 add_definitions(-DWINVER=0x600 -D_WIN32_WINNT=0x601)
 
-if(MSVC)
-    # Disable warning C4477 (printf format warnings)
-    add_compile_flags("/wd4477")
-endif()
-
 list(APPEND SOURCE
     actctx.c
     atom.c
@@ -50,6 +45,11 @@ add_executable(kernel32_winetest
     ${PCH_SKIP_SOURCE}
     resource.rc)
 
+if(MSVC)
+    # Disable warning C4477 (printf format warnings)
+    target_compile_options(kernel32_winetest PRIVATE /wd4477)
+endif()
+
 if(USE_CLANG_CL OR (NOT MSVC))
     target_compile_options(kernel32_winetest PRIVATE "-Wno-format")
 endif()
diff --git a/modules/rostests/winetests/user32/CMakeLists.txt 
b/modules/rostests/winetests/user32/CMakeLists.txt
index dd7bdac6051..226edab9690 100644
--- a/modules/rostests/winetests/user32/CMakeLists.txt
+++ b/modules/rostests/winetests/user32/CMakeLists.txt
@@ -2,13 +2,6 @@
 remove_definitions(-DWINVER=0x502 -D_WIN32_WINNT=0x502)
 add_definitions(-DWINVER=0x602 -D_WIN32_WINNT=0x602)
 
-if(MSVC)
-    # Disable warning C4477 (printf format warnings)
-    add_compile_flags("/wd4477")
-elseif(GCC)
-    add_compile_flags("-Wno-format-overflow")
-endif()
-
 list(APPEND SOURCE
     broadcast.c
     class.c
@@ -44,6 +37,13 @@ add_executable(user32_winetest
     ${PCH_SKIP_SOURCE}
     resource.rc)
 
+if(MSVC)
+    # Disable warning C4477 (printf format warnings)
+    target_compile_options(user32_winetest PRIVATE /wd4477)
+elseif(GCC)
+    target_compile_options(user32_winetest PRIVATE -Wno-format-overflow)
+endif()
+
 add_pch(user32_winetest precomp.h "${PCH_SKIP_SOURCE}")
 # some tests need to be run from an app compiled as GUI
 set_module_type(user32_winetest win32gui)
diff --git a/sdk/cmake/compilerflags.cmake b/sdk/cmake/compilerflags.cmake
index f229d34c70d..c644ee21fc4 100644
--- a/sdk/cmake/compilerflags.cmake
+++ b/sdk/cmake/compilerflags.cmake
@@ -24,6 +24,15 @@ function(add_target_property _module _propname)
     set_property(TARGET ${_module} PROPERTY ${_propname} ${_newvalue})
 endfunction()
 
+# remove_target_compile_options
+#  Remove one option from the target COMPILE_OPTIONS property,
+#  previously added through add_compile_options
+function(remove_target_compile_option _module _option)
+    get_target_property(_options ${_module} COMPILE_OPTIONS)
+    list(REMOVE_ITEM _options ${_option})
+    set_target_properties(${_module} PROPERTIES COMPILE_OPTIONS "${_options}")
+endfunction()
+
 # Wrapper functions for the important properties, using add_target_property
 # where appropriate.
 # Note that the functions for string properties take a single string
@@ -63,14 +72,12 @@ endmacro(replace_compiler_option)
 
 # add_compile_flags
 # add_compile_flags_language
-# replace_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")
 #  add_compile_flags_language("-std=gnu99" "C")
-#  replace_compile_flags("-O5" "-O3")
 function(add_compile_flags _flags)
     if(${ARGC} GREATER 1)
         message(FATAL_ERROR "Excess arguments to add_compile_flags! Args 
${ARGN}")
@@ -89,12 +96,3 @@ function(add_compile_flags_language _flags _lang)
     set(CMAKE_${_lang}_FLAGS "${CMAKE_${_lang}_FLAGS} ${_flags}" PARENT_SCOPE)
 endfunction()
 
-macro(replace_compile_flags _oldflags _newflags)
-    if(NOT ${ARGC} EQUAL 2)
-        message(FATAL_ERROR "Wrong arguments to replace_compile_flags! Args 
${ARGN}")
-    endif()
-    replace_compiler_option(CMAKE_C_FLAGS ${_oldflags} ${_newflags})
-    replace_compiler_option(CMAKE_CXX_FLAGS ${_oldflags} ${_newflags})
-    replace_compiler_option(CMAKE_ASM_FLAGS ${_oldflags} ${_newflags})
-endmacro()
-
diff --git a/sdk/cmake/msvc.cmake b/sdk/cmake/msvc.cmake
index 3731ca4d500..92d5bf41053 100644
--- a/sdk/cmake/msvc.cmake
+++ b/sdk/cmake/msvc.cmake
@@ -112,12 +112,12 @@ add_compile_flags("/wd4018")
 # - C4700: uninitialized variable usage
 # - C4715: 'function': not all control paths return a value
 # - C4716: function must return a value
-add_compile_flags("/we4013 /we4020 /we4022 /we4028 /we4047 /we4098 /we4101 
/we4113 /we4129 /we4133 /we4163 /we4229 /we4311 /we4312 /we4313 /we4477 /we4603 
/we4700 /we4715 /we4716")
+add_compile_options(/we4013 /we4020 /we4022 /we4028 /we4047 /we4098 /we4101 
/we4113 /we4129 /we4133 /we4163 /we4229 /we4311 /we4312 /we4313 /we4477 /we4603 
/we4700 /we4715 /we4716)
 
 # - C4189: local variable initialized but not referenced
 # Not in Release mode
 if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
-    add_compile_flags("/we4189")
+    add_compile_options(/we4189)
 endif()
 
 # Enable warnings above the default level, but don't treat them as errors:
@@ -143,7 +143,7 @@ endif()
 # Hotpatchable images
 if(ARCH STREQUAL "i386")
     if(NOT USE_CLANG_CL)
-        add_compile_flags("/hotpatch")
+        add_compile_options(/hotpatch)
     endif()
     set(_hotpatch_link_flag "/FUNCTIONPADMIN:5")
 elseif(ARCH STREQUAL "amd64")
diff --git a/sdk/lib/3rdparty/freetype/CMakeLists.txt 
b/sdk/lib/3rdparty/freetype/CMakeLists.txt
index d2d87133831..e2d7b3108ca 100644
--- a/sdk/lib/3rdparty/freetype/CMakeLists.txt
+++ b/sdk/lib/3rdparty/freetype/CMakeLists.txt
@@ -5,11 +5,6 @@ add_definitions(
 
 include_directories(include)
 
-if(MSVC)
-    # error C4312: 'type cast': conversion from 'unsigned long' to 'void *' of 
greater size
-    replace_compile_flags("/we4312" " ")
-endif()
-
 list(APPEND SOURCE
     src/autofit/autofit.c
     src/base/ftadvanc.c
@@ -60,7 +55,10 @@ list(APPEND SOURCE
 
 add_library(freetype ${SOURCE})
 
-if(GCC)
+if (MSVC)
+    # error C4312: 'type cast': conversion from 'unsigned long' to 'void *' of 
greater size
+    remove_target_compile_option(freetype "/we4312")
+elseif(GCC)
     target_compile_options(freetype PRIVATE -fno-builtin-malloc)
 elseif(CLANG)
     target_compile_options(freetype PRIVATE -Wno-tautological-constant-compare)
diff --git a/sdk/lib/3rdparty/libxml2/CMakeLists.txt 
b/sdk/lib/3rdparty/libxml2/CMakeLists.txt
index 855d45ff9cd..5d7186e69b4 100644
--- a/sdk/lib/3rdparty/libxml2/CMakeLists.txt
+++ b/sdk/lib/3rdparty/libxml2/CMakeLists.txt
@@ -66,10 +66,10 @@ add_library(libxml2 ${SOURCE})
 
 if(MSVC AND (NOT USE_CLANG_CL))
     # Unreferenced local variable
-    replace_compile_flags("/we4101" " ")
+    remove_target_compile_option(libxml2 "/we4101")
     target_compile_options(libxml2 PRIVATE "/wd4101")
     # Local variable initialized but not referenced
-    replace_compile_flags("/we4189" " ")
+    remove_target_compile_option(libxml2 "/we4189")
 else()
     target_compile_options(libxml2 PRIVATE "-w")
 endif()

Reply via email to