[CMAKE/CLANG]
[reactos.git] / reactos / cmake / gcc.cmake
index 9cee334..7cf984e 100644 (file)
@@ -32,7 +32,24 @@ if(GCC_VERSION VERSION_GREATER 4.7)
 endif()
 
 if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
-    add_compile_flags_language("-std=gnu89" "C")
+    add_compile_flags_language("-std=gnu89 -Wno-microsoft" "C")
+    set(CMAKE_LINK_DEF_FILE_FLAG "")
+    set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+    set(CMAKE_LINK_LIBRARY_SUFFIX "")
+    set(CMAKE_CREATE_WIN32_EXE "")
+    set(CMAKE_C_COMPILE_OPTIONS_PIC "")
+    set(CMAKE_CXX_COMPILE_OPTIONS_PIC "")
+    set(CMAKE_C_COMPILE_OPTIONS_PIE "")
+    set(CMAKE_CXX_COMPILE_OPTIONS_PIE "")
+    set(CMAKE_SHARED_LIBRARY_C_FLAGS "")
+    set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
+endif()
+
+if(DBG)
+    if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
+        add_compile_flags_language("-Wold-style-declaration" "C")
+    endif()
+    add_compile_flags_language("-Wdeclaration-after-statement" "C")
 endif()
 
 add_compile_flags_language("-fno-rtti -fno-exceptions" "CXX")
@@ -72,7 +89,11 @@ else()
 endif()
 
 # Warnings, errors
-add_compile_flags("-Werror -Wall -Wpointer-arith")
+if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
+    add_compile_flags("-Werror")
+endif()
+
+add_compile_flags("-Wall -Wpointer-arith")
 add_compile_flags("-Wno-char-subscripts -Wno-multichar -Wno-unused-value")
 
 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
@@ -80,8 +101,7 @@ if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
     add_compile_flags("-Wno-error=unused-but-set-variable")
 endif()
 
-add_compile_flags("-Wno-error=narrowing")
-add_compile_flags("-Wtype-limits -Wno-error=type-limits")
+add_compile_flags("-Wno-error=type-limits")
 
 if(ARCH STREQUAL "amd64")
     add_compile_flags("-Wno-format")
@@ -108,7 +128,7 @@ endif()
 
 # Link-time code generation
 if(LTCG)
-    add_compile_flags("-flto -ffat-lto-objects")
+    add_compile_flags("-flto -fno-fat-lto-objects")
 endif()
 
 if(ARCH STREQUAL "i386")
@@ -134,7 +154,7 @@ endif()
 
 add_definitions(-D_inline=__inline)
 
-# alternative arch name
+# Alternative arch name
 if(ARCH STREQUAL "amd64")
     set(ARCH2 x86_64)
 else()
@@ -263,18 +283,18 @@ if(NOT ARCH STREQUAL "i386")
 endif()
 
 function(generate_import_lib _libname _dllname _spec_file)
-    # generate the def for the import lib
+    # Generate the def for the import lib
     add_custom_command(
         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
         COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
     set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def PROPERTIES EXTERNAL_OBJECT TRUE)
 
-    #create normal importlib
+    # Create normal importlib
     _add_library(${_libname} STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
     set_target_properties(${_libname} PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
 
-    #create delayed importlib
+    # Create delayed importlib
     _add_library(${_libname}_delayed STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
     set_target_properties(${_libname}_delayed PROPERTIES LINKER_LANGUAGE "IMPLIB_DELAYED" PREFIX "")
 endfunction()
@@ -283,7 +303,7 @@ endfunction()
 set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-lib=<TARGET>")
 set(CMAKE_IMPLIB_DELAYED_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-delaylib=<TARGET>")
 function(spec2def _dllname _spec_file)
-    # do we also want to add importlib targets?
+    # Do we also want to add importlib targets?
     if(${ARGC} GREATER 2)
         if(${ARGN} STREQUAL "ADD_IMPORTLIB")
             set(__add_importlib TRUE)
@@ -292,15 +312,15 @@ function(spec2def _dllname _spec_file)
         endif()
     endif()
 
-    # get library basename
+    # Get library basename
     get_filename_component(_file ${_dllname} NAME_WE)
 
-    # error out on anything else than spec
+    # Error out on anything else than spec
     if(NOT ${_spec_file} MATCHES ".*\\.spec")
         message(FATAL_ERROR "spec2def only takes spec files as input.")
     endif()
 
-    # generate exports def and stubs C file for the module
+    # Generate exports def and C stubs file for the DLL
     add_custom_command(
         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
         COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
@@ -315,11 +335,12 @@ macro(macro_mc FLAG FILE)
     set(COMMAND_MC ${CMAKE_MC_COMPILER} ${FLAG} -b ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc -r ${REACTOS_BINARY_DIR}/include/reactos -h ${REACTOS_BINARY_DIR}/include/reactos)
 endmacro()
 
-#pseh lib, needed with mingw
+# PSEH lib, needed with mingw
 set(PSEH_LIB "pseh")
 
 # Macros
 if(PCH)
+    add_compile_flags("-Winvalid-pch -Werror=invalid-pch")
     macro(add_pch _target _pch _sources)
         # When including x.h GCC looks for x.h.gch first
         set(_pch_final_name "${_target}_pch.h")
@@ -347,7 +368,7 @@ if(PCH)
         # Include the gch in the specified source files, skipping the pch file itself
         list(REMOVE_ITEM ${_sources} ${_pch})
         foreach(_src ${${_sources}})
-            set_property(SOURCE ${_src} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_ccache_flag} -Winvalid-pch -Werror=invalid-pch -include ${_pch_final_name}")
+            set_property(SOURCE ${_src} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_ccache_flag} -include ${_pch_final_name}")
             set_property(SOURCE ${_src} APPEND PROPERTY OBJECT_DEPENDS ${_gch})
         endforeach()
     endmacro()
@@ -383,4 +404,3 @@ endfunction()
 macro(add_asm_files _target)
     list(APPEND ${_target} ${ARGN})
 endmacro()
-