[CMAKE] Get rid of add_compile_flags_language macro
authorJérôme Gardou <jerome.gardou@reactos.org>
Fri, 18 Sep 2020 14:18:24 +0000 (16:18 +0200)
committerJérôme Gardou <zefklop@users.noreply.github.com>
Tue, 20 Oct 2020 19:44:54 +0000 (21:44 +0200)
in favor of add_compile_options and the like with generator expressions
Also take this as an opportunity to remove the C++11 standard hack, GCC 8 now defaults to C++14

19 files changed:
base/applications/charmap_new/CMakeLists.txt
base/applications/network/telnet/CMakeLists.txt
dll/shellext/acppage/CMakeLists.txt
dll/shellext/mydocs/CMakeLists.txt
dll/shellext/netshell/CMakeLists.txt
dll/shellext/ntobjshex/CMakeLists.txt
dll/shellext/sendmail/CMakeLists.txt
dll/shellext/shellbtrfs/CMakeLists.txt
dll/shellext/stobject/CMakeLists.txt
dll/shellext/zipfldr/CMakeLists.txt
dll/win32/devmgr/CMakeLists.txt
dll/win32/shell32/CMakeLists.txt
drivers/network/dd/netkvm/CMakeLists.txt
modules/rostests/apitests/browseui/CMakeLists.txt
sdk/cmake/compilerflags.cmake
sdk/cmake/gcc.cmake
sdk/cmake/msvc.cmake
sdk/tools/CMakeLists.txt
win32ss/CMakeLists.txt

index 06616bf..c9198f5 100644 (file)
@@ -1,10 +1,5 @@
 PROJECT(CHARMAP)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 include_directories(
     includes)
 
index acd2aa0..d77a95c 100644 (file)
@@ -1,10 +1,4 @@
 
-add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
-
-if(NOT MSVC)
-    add_compile_flags("-Wno-restrict")
-endif()
-
 list(APPEND SOURCE
     src/ansiprsr.cpp
     src/keytrans.cpp
@@ -27,13 +21,13 @@ list(APPEND SOURCE
     src/ttelhndl.cpp
     precomp.h)
 
-if(NOT MSVC)
-    add_compile_flags_language("-Wno-narrowing" "CXX")
-endif()
-
 add_executable(telnet ${SOURCE} telnet.rc)
 target_link_libraries(telnet cppstl)
 set_target_cpp_properties(telnet WITH_EXCEPTIONS)
+if (NOT MSVC)
+    target_compile_options(telnet PRIVATE -Wno-restrict $<$<COMPILE_LANGUAGE:CXX>:-Wno-narrowing>)
+    target_compile_definitions(telnet PRIVATE _CRT_NONSTDC_NO_DEPRECATE)
+endif()
 set_module_type(telnet win32cui)
 add_importlibs(telnet ws2_32 user32 msvcrt kernel32 ntdll)
 add_pch(telnet precomp.h SOURCE)
index fe694f8..f38c77c 100644 (file)
@@ -1,11 +1,6 @@
 
 project(appcompat)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 include_directories(
     ${REACTOS_SOURCE_DIR}/dll/appcompat/apphelp
     ${REACTOS_SOURCE_DIR})
index b74998e..5c1b170 100644 (file)
@@ -3,11 +3,6 @@ spec2def(mydocs.dll mydocs.spec)
 add_definitions(
     -D_WINE)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 file(GLOB_RECURSE mydocs_rc_deps res/*.*)
 add_rc_deps(mydocs.rc ${mydocs_rc_deps})
 
index 48ce800..30efec7 100644 (file)
@@ -1,12 +1,6 @@
 
 project(SHELL)
 
-
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11 -Wshadow" "CXX")
-endif()
-
 remove_definitions(-D_WIN32_WINNT=0x502)
 add_definitions(-D_WIN32_WINNT=0x600)
 
index 3ecdae1..f5ce057 100644 (file)
@@ -1,11 +1,6 @@
 
 project(SHELL)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 spec2def(ntobjshex.dll ntobjshex.spec)
 
 file(GLOB_RECURSE ntobjshex_rc_deps resources/*.*)
index 5adbf3a..5271729 100644 (file)
@@ -3,11 +3,6 @@ spec2def(sendmail.dll sendmail.spec)
 add_definitions(
     -D_WINE)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 file(GLOB_RECURSE sendmail_rc_deps res/*.*)
 add_rc_deps(sendmail.rc ${sendmail_rc_deps})
 
index 7a21c8a..6cbd3b0 100644 (file)
@@ -2,10 +2,6 @@
 remove_definitions(-D_WIN32_WINNT=0x502)
 add_definitions(-D_WIN32_WINNT=0x603)
 
-if(NOT MSVC)
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 include_directories(${REACTOS_SOURCE_DIR}/drivers/filesystems/btrfs)
 
 spec2def(shellbtrfs.dll shellbtrfs.spec)
index f5c67cc..b8b1891 100644 (file)
@@ -1,11 +1,6 @@
 
 project(SHELL)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 spec2def(stobject.dll stobject.spec)
 
 file(GLOB_RECURSE stobject_rc_deps resources/*.*)
index 106a886..1706cdd 100644 (file)
@@ -1,9 +1,4 @@
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 remove_definitions(-D_WIN32_WINNT=0x502)
 add_definitions(-D_WIN32_WINNT=0x600)
 
@@ -13,7 +8,6 @@ include_directories(
 
 spec2def(zipfldr.dll zipfldr.spec ADD_IMPORTLIB)
 
-
 list(APPEND SOURCE
     zipfldr.cpp
     zippidl.cpp
@@ -40,7 +34,6 @@ add_library(zipfldr MODULE
     zipfldr.rc
     ${CMAKE_CURRENT_BINARY_DIR}/zipfldr.def)
 
-
 set_module_type(zipfldr win32dll UNICODE)
 target_link_libraries(zipfldr minizip zlib uuid cpprt atl_classes)
 set_target_cpp_properties(zipfldr WITH_EXCEPTIONS)
index e86615f..c4833ca 100644 (file)
@@ -2,11 +2,6 @@ PROJECT(DEVMGR)
 
 spec2def(devmgr.dll devmgr.spec ADD_IMPORTLIB)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 include_directories(
     ${REACTOS_SOURCE_DIR}/sdk/include/reactos/dll
     includes)
index 464ef62..4525db4 100644 (file)
@@ -6,11 +6,6 @@ add_subdirectory(shellrecyclebin)
 
 spec2def(shell32.dll shell32.spec ADD_IMPORTLIB)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 remove_definitions(-D_WIN32_WINNT=0x502)
 add_definitions(-D_WIN32_WINNT=0x600)
 
index 73a4a2f..ac916e9 100644 (file)
@@ -27,12 +27,13 @@ add_cd_file(TARGET netkvm DESTINATION reactos/system32/drivers FOR all)
 add_driver_inf(netkvm netkvm.inf)
 
 if(NOT MSVC)
-    add_compile_flags("-Wno-unused-function")
-    add_compile_flags("-Wno-old-style-declaration")
-    add_compile_flags("-Wno-unknown-pragmas")
-    add_compile_flags("-Wno-unused-but-set-variable")
-    add_compile_flags("-Wno-pointer-sign")
-    add_compile_flags("-Wno-pointer-to-int-cast")
-    add_compile_flags("-Wno-int-to-pointer-cast")
-    add_compile_flags("-Wno-attributes")
+    target_compile_options(netkvm PRIVATE
+        -Wno-unused-function
+        -Wno-old-style-declaration
+        -Wno-unknown-pragmas
+        -Wno-unused-but-set-variable
+        -Wno-pointer-sign
+        -Wno-pointer-to-int-cast
+        -Wno-int-to-pointer-cast
+        -Wno-attributes)
 endif()
index f1875d3..efae63c 100644 (file)
@@ -1,9 +1,4 @@
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 include_directories(
     includes)
 
@@ -15,6 +10,7 @@ list(APPEND SOURCE
     testlist.c)
 
 add_executable(browseui_apitest ${SOURCE})
+
 target_link_libraries(browseui_apitest uuid wine cpprt atl_classes)
 set_target_cpp_properties(browseui_apitest WITH_EXCEPTIONS WITH_RTTI)
 set_module_type(browseui_apitest win32cui)
index c644ee2..5da48e6 100644 (file)
@@ -71,13 +71,11 @@ macro(replace_compiler_option _var _old _new)
 endmacro(replace_compiler_option)
 
 # add_compile_flags
-# add_compile_flags_language
 #  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")
 function(add_compile_flags _flags)
     if(${ARGC} GREATER 1)
         message(FATAL_ERROR "Excess arguments to add_compile_flags! Args ${ARGN}")
@@ -87,12 +85,3 @@ function(add_compile_flags _flags)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE)
     set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${_flags}" PARENT_SCOPE)
 endfunction()
-
-function(add_compile_flags_language _flags _lang)
-    if(NOT ${ARGC} EQUAL 2)
-        message(FATAL_ERROR "Wrong arguments to add_compile_flags_language! Args ${ARGN}")
-    endif()
-    # Adds the compiler flag for the specified language only, e.g. CMAKE_C_FLAGS
-    set(CMAKE_${_lang}_FLAGS "${CMAKE_${_lang}_FLAGS} ${_flags}" PARENT_SCOPE)
-endfunction()
-
index cf72bae..3ef5f58 100644 (file)
@@ -49,7 +49,7 @@ add_compile_flags("-mstackrealign")
 add_compile_flags("-fno-aggressive-loop-optimizations")
 
 if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
-    add_compile_flags_language("-std=gnu99 -Wno-microsoft" "C")
+    add_compile_options("$<$<COMPILE_LANGUAGE:C>:-std=gnu99;-Wno-microsoft>")
     set(CMAKE_LINK_DEF_FILE_FLAG "")
     set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
     set(CMAKE_LINK_LIBRARY_SUFFIX "")
@@ -65,7 +65,7 @@ endif()
 
 if(DBG)
     if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
-        add_compile_flags_language("-Wold-style-declaration" "C")
+        add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wold-style-declaration>")
     endif()
 endif()
 
index 92d5bf4..f44af85 100644 (file)
@@ -125,8 +125,7 @@ endif()
 add_compile_flags("/w14115")
 
 if(USE_CLANG_CL)
-    add_compile_flags_language("-nostdinc -Wno-multichar -Wno-char-subscripts -Wno-microsoft-enum-forward-reference -Wno-pragma-pack -Wno-microsoft-anon-tag -Wno-parentheses-equality -Wno-unknown-pragmas" "C")
-    add_compile_flags_language("-nostdinc -Wno-multichar -Wno-char-subscripts -Wno-microsoft-enum-forward-reference -Wno-pragma-pack -Wno-microsoft-anon-tag -Wno-parentheses-equality -Wno-unknown-pragmas" "CXX")
+    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>")
 endif()
 
 # Debugging
index f9e0e19..3b6bf13 100644 (file)
@@ -6,10 +6,10 @@ endfunction()
 
 if(MSVC)
     add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DHAVE_IO_H=1)
-    add_compile_flags_language("/EHsc" "CXX")
+    add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/EHsc>")
 
     # Disable warning "conversion from 'size_t' to 'int', possible loss of data"
-    add_compile_flags("/wd4267")
+    add_compile_options("/wd4267")
 endif()
 
 add_host_tool(bin2c bin2c.c)
index e3be784..b74e41f 100644 (file)
@@ -1,11 +1,6 @@
 
 set(USE_DIBLIB FALSE)
 
-if(NOT MSVC)
-    # HACK: this should be enabled globally!
-    add_compile_flags_language("-std=c++11" "CXX")
-endif()
-
 # Give WIN32 subsystem its own project.
 PROJECT(WIN32SS)
 
@@ -247,4 +242,4 @@ set_source_files_properties(sys-stubs.S PROPERTIES OBJECT_DEPENDS ${CMAKE_CURREN
 add_asm_files(win32ksys_asm sys-stubs.S)
 add_library(win32ksys ${win32ksys_asm})
 set_target_properties(win32ksys PROPERTIES LINKER_LANGUAGE "C")
-add_dependencies(win32ksys asm)
\ No newline at end of file
+add_dependencies(win32ksys asm)