X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=cmake%2Fgcc.cmake;h=b8a3fac71d429aae896d5f61d73c778a71a006ab;hp=fc2cd520fd2b5810b28d64ca6870e25c3da42bfb;hb=83c026ccfe16145102d4894791b2bd8a1a25b945;hpb=bb519801e29effa8231b34f82088d72989c0e82e diff --git a/cmake/gcc.cmake b/cmake/gcc.cmake index fc2cd520fd2..b8a3fac71d4 100644 --- a/cmake/gcc.cmake +++ b/cmake/gcc.cmake @@ -1,6 +1,6 @@ # Show a note about ccache build -if(CCACHE STREQUAL "ccache") +if(ENABLE_CCACHE) message("-- Enabling ccache build - done") endif() @@ -9,8 +9,62 @@ if(NOT DEFINED SEPARATE_DBG) set(SEPARATE_DBG FALSE) endif() +# Dwarf based builds (no rsym) +if(NOT DEFINED NO_ROSSYM) + set(NO_ROSSYM FALSE) +endif() + +if(NOT DEFINED USE_PSEH3) + set(USE_PSEH3 1) +endif() + +if(USE_PSEH3) + add_definitions(-D_USE_PSEH3=1) +endif() + +if(NOT DEFINED USE_DUMMY_PSEH) + set(USE_DUMMY_PSEH 0) +endif() + +if(USE_DUMMY_PSEH) + add_definitions(-D_USE_DUMMY_PSEH=1) +endif() + +if(STACK_PROTECTOR) + add_compile_flags(${MODULE} "-fstack-protector-all") +endif() + # Compiler Core add_compile_flags("-pipe -fms-extensions -fno-strict-aliasing") +if(GCC_VERSION VERSION_GREATER 4.7) + add_compile_flags("-mstackrealign") +endif() + +if(CMAKE_C_COMPILER_ID STREQUAL "Clang") + 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 "") + set(CMAKE_ASM_FLAGS_DEBUG "") + set(CMAKE_C_FLAGS_DEBUG "") + set(CMAKE_CXX_FLAGS_DEBUG "") +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") #bug #file(TO_NATIVE_PATH ${REACTOS_SOURCE_DIR} REACTOS_SOURCE_DIR_NATIVE) @@ -19,13 +73,19 @@ set(REACTOS_SOURCE_DIR_NATIVE ${REACTOS_SOURCE_DIR}) if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") string(REPLACE "/" "\\" REACTOS_SOURCE_DIR_NATIVE ${REACTOS_SOURCE_DIR}) endif() -add_compile_flags("-fdebug-prefix-map=\"${REACTOS_SOURCE_DIR_NATIVE}\"=ReactOS") + +if((NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") AND (NOT SEPARATE_DBG)) + add_compile_flags("-fdebug-prefix-map=\"${REACTOS_SOURCE_DIR_NATIVE}\"=ReactOS") +endif() # Debugging if(SEPARATE_DBG) - add_compile_flags("-gdwarf-2 -g2") + add_compile_flags("-gdwarf-2 -ggdb") else() - add_compile_flags("-gstabs+") + 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") + endif() endif() # For some reason, cmake sets -fPIC, and we don't want it @@ -40,17 +100,21 @@ else() add_compile_flags("-march=${OARCH}") endif() -# Warnings -add_compile_flags("-Werror -Wall -Wno-char-subscripts -Wpointer-arith -Wno-multichar -Wno-unused-value") +# Warnings, errors +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(GCC_VERSION VERSION_LESS 4.6) - add_compile_flags("-Wno-error=uninitialized") -elseif((GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6) AND GCC_VERSION VERSION_LESS 4.7) - add_compile_flags("-Wno-error=unused-but-set-variable -Wno-error=uninitialized") -elseif(GCC_VERSION VERSION_EQUAL 4.7 OR GCC_VERSION VERSION_GREATER 4.7) - add_compile_flags("-Wno-error=unused-but-set-variable -Wno-error=maybe-uninitialized -Wno-error=delete-non-virtual-dtor -Wno-error=narrowing") +if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") + add_compile_flags("-Wno-maybe-uninitialized") + add_compile_flags("-Wno-error=unused-but-set-variable") endif() +add_compile_flags("-Wno-error=type-limits") + if(ARCH STREQUAL "amd64") add_compile_flags("-Wno-format") elseif(ARCH STREQUAL "arm") @@ -63,7 +127,7 @@ if(OPTIMIZE STREQUAL "1") elseif(OPTIMIZE STREQUAL "2") add_compile_flags("-Os") elseif(OPTIMIZE STREQUAL "3") - add_compile_flags("-O1 -fno-inline-functions-called-once -fno-tree-sra") + add_compile_flags("-Og") elseif(OPTIMIZE STREQUAL "4") add_compile_flags("-O1") elseif(OPTIMIZE STREQUAL "5") @@ -76,11 +140,15 @@ endif() # Link-time code generation if(LTCG) - add_compile_flags("-flto -Wno-error=clobbered") + add_compile_flags("-flto -fno-fat-lto-objects") endif() if(ARCH STREQUAL "i386") - add_compile_flags("-mpreferred-stack-boundary=3 -fno-set-stack-executable -fno-optimize-sibling-calls -fno-omit-frame-pointer") + add_compile_flags("-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") + 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") endif() @@ -98,7 +166,7 @@ endif() add_definitions(-D_inline=__inline) -# alternative arch name +# Alternative arch name if(ARCH STREQUAL "amd64") set(ARCH2 x86_64) else() @@ -135,32 +203,43 @@ if(SEPARATE_DBG) " -o " "${OBJCOPY} --only-keep-debug ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}" "${OBJCOPY} --strip-debug ") +elseif(NO_ROSSYM) + # Dwarf-based build + message(STATUS "Generating a dwarf-based build (no rsym)") + set(CMAKE_C_LINK_EXECUTABLE " ${CMAKE_C_FLAGS} -o ") + set(CMAKE_CXX_LINK_EXECUTABLE " ${CMAKE_CXX_FLAGS} -o ") + set(CMAKE_C_CREATE_SHARED_LIBRARY " ${CMAKE_C_FLAGS} -o ") + set(CMAKE_CXX_CREATE_SHARED_LIBRARY " ${CMAKE_CXX_FLAGS} -o ") + set(CMAKE_RC_CREATE_SHARED_LIBRARY " ${CMAKE_C_FLAGS} -o ") else() # Normal rsym build get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG) set(CMAKE_C_LINK_EXECUTABLE " ${CMAKE_C_FLAGS} -o " - "${RSYM} ") + "${RSYM} -s ${REACTOS_SOURCE_DIR} ") set(CMAKE_CXX_LINK_EXECUTABLE " ${CMAKE_CXX_FLAGS} -o " - "${RSYM} ") + "${RSYM} -s ${REACTOS_SOURCE_DIR} ") set(CMAKE_C_CREATE_SHARED_LIBRARY " ${CMAKE_C_FLAGS} -o " - "${RSYM} ") + "${RSYM} -s ${REACTOS_SOURCE_DIR} ") set(CMAKE_CXX_CREATE_SHARED_LIBRARY " ${CMAKE_CXX_FLAGS} -o " - "${RSYM} ") + "${RSYM} -s ${REACTOS_SOURCE_DIR} ") set(CMAKE_RC_CREATE_SHARED_LIBRARY - " ${CMAKE_C_FLAGS} -o " - "${RSYM} ") + " ${CMAKE_C_FLAGS} -o ") endif() set(CMAKE_EXE_LINKER_FLAGS "-nostdlib -Wl,--enable-auto-image-base,--disable-auto-import,--disable-stdcall-fixup") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup") -SET(CMAKE_C_COMPILE_OBJECT "${CCACHE} -o -c ") +if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(_compress_debug_sections_flag "-Wa,--compress-debug-sections") +endif() + +SET(CMAKE_C_COMPILE_OBJECT "${CCACHE} ${_compress_debug_sections_flag} -o -c ") SET(CMAKE_CXX_COMPILE_OBJECT "${CCACHE} -o -c ") -set(CMAKE_ASM_COMPILE_OBJECT " -x assembler-with-cpp -o -I${REACTOS_SOURCE_DIR}/include/asm -I${REACTOS_BINARY_DIR}/include/asm -D__ASM__ -c ") +set(CMAKE_ASM_COMPILE_OBJECT " ${_compress_debug_sections_flag} -x assembler-with-cpp -o -I${REACTOS_SOURCE_DIR}/include/asm -I${REACTOS_BINARY_DIR}/include/asm -D__ASM__ -c ") set(CMAKE_RC_COMPILE_OBJECT " -O coff -DRC_INVOKED -D__WIN32__=1 -D__FLAT__=1 ${I18N_DEFS} ") set(CMAKE_DEPFILE_FLAGS_RC "--preprocessor \"${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX} -E -xc-header -MMD -MF -MT \" ") @@ -189,20 +268,38 @@ function(set_image_base MODULE IMAGE_BASE) endfunction() function(set_module_type_toolchain MODULE TYPE) - if(IS_CPP) + if(CPP_USE_STL) + if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver")) + message(FATAL_ERROR "Use of STL in kernelmodedriver or wdmdriver type module prohibited") + endif() target_link_libraries(${MODULE} -lstdc++ -lsupc++ -lgcc -lmingwex) + elseif(CPP_USE_RT) + target_link_libraries(${MODULE} -lsupc++ -lgcc) + elseif(IS_CPP) + target_link_libraries(${MODULE} -lgcc) endif() - if(${TYPE} STREQUAL "kernelmodedriver") + if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver")) add_target_link_flags(${MODULE} "-Wl,--exclude-all-symbols,-file-alignment=0x1000,-section-alignment=0x1000") + if(${TYPE} STREQUAL "wdmdriver") + add_target_link_flags(${MODULE} "-Wl,--wdmdriver") + endif() + endif() + + if(STACK_PROTECTOR) + target_link_libraries(${MODULE} gcc_ssp) endif() endfunction() -function(add_delay_importlibs MODULE) - foreach(LIB ${ARGN}) - target_link_libraries(${MODULE} lib${LIB}_delayed) +function(add_delay_importlibs _module) + get_target_property(_module_type ${_module} TYPE) + if(_module_type STREQUAL "STATIC_LIBRARY") + message(FATAL_ERROR "Cannot add delay imports to a static library") + endif() + foreach(_lib ${ARGN}) + target_link_libraries(${_module} lib${_lib}_delayed) endforeach() - target_link_libraries(${MODULE} delayimp) + target_link_libraries(${_module} delayimp) endfunction() if(NOT ARCH STREQUAL "i386") @@ -210,18 +307,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} -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} + 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() @@ -230,30 +327,28 @@ endfunction() set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def --kill-at --output-lib=") set(CMAKE_IMPLIB_DELAYED_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def --kill-at --output-delaylib=") function(spec2def _dllname _spec_file) - # do we also want to add importlib targets? - if(${ARGC} GREATER 2) - if(${ARGN} STREQUAL "ADD_IMPORTLIB") - set(__add_importlib TRUE) - else() - message(FATAL_ERROR "Wrong argument passed to spec2def, ${ARGN}") - endif() - endif() + + cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;WITH_RELAY" "" "" ${ARGN}) - # 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 + if (__spec2def_WITH_RELAY) + set(__with_relay_arg "--with-tracing") + endif() + + # 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} --kill-at -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} + COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def) - if(__add_importlib) + if(__spec2def_ADD_IMPORTLIB) generate_import_lib(lib${_file} ${_dllname} ${_spec_file}) endif() endfunction() @@ -262,75 +357,45 @@ 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) - macro(_PCH_GET_COMPILE_FLAGS _target_name _out_compile_flags _header_filename) - # Add the precompiled header to the build - get_filename_component(_FILE ${_header_filename} NAME) - set(_gch_filename "${_FILE}.gch") - list(APPEND ${_out_compile_flags} -c ${_header_filename} -o ${_gch_filename}) - - # This gets us our includes - get_directory_property(DIRINC INCLUDE_DIRECTORIES) - foreach(item ${DIRINC}) - list(APPEND ${_out_compile_flags} -I${item}) - endforeach() - - # This our definitions - get_directory_property(_compiler_flags DEFINITIONS) - list(APPEND ${_out_compile_flags} ${_compiler_flags}) - - # This gets any specific definitions that were added with set-target-property - get_target_property(_target_defs ${_target_name} COMPILE_DEFINITIONS) - if(_target_defs) - foreach(item ${_target_defs}) - list(APPEND ${_out_compile_flags} -D${item}) - endforeach() - endif() + 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") + set(_gch ${CMAKE_CURRENT_BINARY_DIR}/${_pch_final_name}.gch) if(IS_CPP) - list(APPEND ${_out_compile_flags} ${CMAKE_CXX_FLAGS}) + set(_pch_language CXX) else() - list(APPEND ${_out_compile_flags} ${CMAKE_C_FLAGS}) + set(_pch_language C) endif() - separate_arguments(${_out_compile_flags}) - endmacro() - - macro(add_pch _target_name _FILE) - set(_header_filename ${CMAKE_CURRENT_SOURCE_DIR}/${_FILE}) - get_filename_component(_basename ${_FILE} NAME) - set(_gch_filename ${_basename}.gch) - _PCH_GET_COMPILE_FLAGS(${_target_name} _args ${_header_filename}) - - if(IS_CPP) - set(__lang CXX) - set(__compiler ${CCACHE} ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}) - else() - set(__lang C) - set(__compiler ${CCACHE} ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}) + # Build the precompiled header + # HEADER_FILE_ONLY FALSE: force compiling the header + # EXTERNAL_SOURCE TRUE: don't use the .gch file when linking + set_source_files_properties(${_pch} PROPERTIES + HEADER_FILE_ONLY FALSE + LANGUAGE ${_pch_language} + EXTERNAL_SOURCE TRUE + OBJECT_LOCATION ${_gch}) + + if(ENABLE_CCACHE) + set(_ccache_flag "-fpch-preprocess") endif() - add_custom_command(OUTPUT ${_gch_filename} - COMMAND ${__compiler} ${_args} - IMPLICIT_DEPENDS ${__lang} ${_header_filename} - DEPENDS ${_header_filename} ${ARGN}) - get_target_property(_src_files ${_target_name} SOURCES) - add_target_compile_flags(${_target_name} "-fpch-preprocess -Winvalid-pch -Wno-error=invalid-pch") - foreach(_item in ${_src_files}) - get_source_file_property(__src_lang ${_item} LANGUAGE) - if(__src_lang STREQUAL __lang) - set_source_files_properties(${_item} PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_gch_filename}) - endif() + # 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} -include ${CMAKE_CURRENT_BINARY_DIR}/${_pch_final_name}") + set_property(SOURCE ${_src} APPEND PROPERTY OBJECT_DEPENDS ${_gch}) endforeach() - #set dependency checking : depends on precompiled header only which already depends on deeper header - set_target_properties(${_target_name} PROPERTIES IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "\"${_basename}\"=;<${_basename}>=") endmacro() else() - macro(add_pch _target_name _FILE) + macro(add_pch _target _pch _sources) endmacro() endif() @@ -339,7 +404,7 @@ function(CreateBootSectorTarget _target_name _asm_file _binary_file _base_addres add_custom_command( OUTPUT ${_object_file} - COMMAND ${CMAKE_ASM_COMPILER} -x assembler-with-cpp -o ${_object_file} -I${REACTOS_SOURCE_DIR}/include/asm -I${REACTOS_BINARY_DIR}/include/asm -D__ASM__ -c ${_asm_file} + COMMAND ${CMAKE_ASM_COMPILER} -x assembler-with-cpp -o ${_object_file} -I${REACTOS_SOURCE_DIR}/include/asm -I${REACTOS_BINARY_DIR}/include/asm -I${REACTOS_SOURCE_DIR}/boot/freeldr -D__ASM__ -c ${_asm_file} DEPENDS ${_asm_file}) add_custom_command( @@ -361,4 +426,3 @@ endfunction() macro(add_asm_files _target) list(APPEND ${_target} ${ARGN}) endmacro() -