add_compile_flags("/Ox /Ob2 /Ot /Oy /GT /GF")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF")
elseif(OPTIMIZE STREQUAL "1")
- add_definitions(/O1)
+ add_compile_flags("/O1")
elseif(OPTIMIZE STREQUAL "2")
- add_definitions(/O2)
+ add_compile_flags("/O2")
elseif(OPTIMIZE STREQUAL "3")
- add_definitions(/Ot /Ox /GS-)
+ add_compile_flags("/Ot /Ox /GS-")
elseif(OPTIMIZE STREQUAL "4")
- add_definitions(/Os /Ox /GS-)
+ add_compile_flags("/Os /Ox /GS-")
elseif(OPTIMIZE STREQUAL "5")
- add_definitions(/GF /Gy /Ob2 /Os /Ox /GS-)
+ add_compile_flags("/GF /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")
+
# Enable function level linking and comdat folding
add_compile_flags("/Gy")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF /OPT:ICF")
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")
endif()
-add_compile_flags("/GR- /EHs-c- /GS- /W3")
+# Disable RTTI, exception handling and buffer security checks by default.
+# These require run-time support that may not always be available.
+add_compile_flags("/GR- /EHs-c- /GS-")
if(USE_CLANG_CL)
set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: ")
add_compile_flags("/Zc:threadSafeInit-")
endif ()
+# Generate Warnings Level 3
+add_compile_flags("/W3")
+
# Disable overly sensitive warnings as well as those that generally aren't
# useful to us.
# - C4244: implicit integer truncation
# - C4013: implicit function declaration
# - C4020: too many actual parameters
# - C4022: pointer type mismatch for parameter
-# - TODO: C4028: formal parameter different from declaration
+# - C4028: formal parameter different from declaration
# - C4047: different level of indirection
# - TODO: C4090: different 'modifier' qualifiers (for C programs only;
# for C++ programs, the compiler error C2440 is issued)
# - C4603: macro is not defined or definition is different after precompiled header use
# - C4716: function must return a value
add_compile_flags("/we4013 /we4020 /we4022 /we4047 /we4098 /we4113 /we4129 /we4163 /we4229 /we4700 /we4603 /we4716")
+# TODO: Check and fix other architectures.
+if(ARCH STREQUAL "i386")
+ add_compile_flags("/we4028")
+endif()
# - C4189: local variable initialized but not referenced
# Not in Release mode and not with MSVC 2010
add_compile_flags("/RTC1")
endif()
-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag}")
-set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE /IGNORE:4104 ${_hotpatch_link_flag}")
-set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag}")
+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")
+
+# HACK: Remove the /implib argument, implibs are generated separately
+string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
+string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE}")
+string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY}")
+string(REPLACE "/implib:<TARGET_IMPLIB>" "" CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
if(CMAKE_DISABLE_NINJA_DEPSLOG)
set(cl_includes_flag "")
# Add our library
if(MSVC_IDE)
add_library(${_libname} STATIC EXCLUDE_FROM_ALL ${_asm_stubs_file}.obj)
- set_source_files_properties(${_asm_stubs_file}.obj PROPERTIES EXTERNAL_OBJECT 1)
+ set_source_files_properties(${_asm_stubs_file}.obj PROPERTIES EXTERNAL_OBJECT TRUE)
set_target_properties(${_libname} PROPERTIES LINKER_LANGUAGE "C")
else()
# NOTE: as stub file and def file are generated in one pass, depending on one is like depending on the other
endif()
function(spec2def _dllname _spec_file)
- cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS" "" "" ${ARGN})
+ cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY" "VERSION" "" ${ARGN})
# Get library basename
get_filename_component(_file ${_dllname} NAME_WE)
message(FATAL_ERROR "spec2def only takes spec files as input.")
endif()
+ if (__spec2def_WITH_RELAY)
+ set(__with_relay_arg "--with-tracing")
+ endif()
+
+ if(__spec2def_VERSION)
+ set(__version_arg "--version=0x${__spec2def_VERSION}")
+ 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 --ms -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
+ COMMAND native-spec2def --ms -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
if(__spec2def_ADD_IMPORTLIB)
OUTPUT ${_preprocessed_asm_file} ${_object_file}
COMMAND cl /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} /D__ASM__ /D_USE_ML /EP /c ${_source_file_full_path} > ${_preprocessed_asm_file} && ${_pp_asm_compile_command}
DEPENDS ${_source_file_full_path})
- set_source_files_properties(${_object_file} PROPERTIES EXTERNAL_OBJECT 1)
+ set_source_files_properties(${_object_file} PROPERTIES EXTERNAL_OBJECT TRUE)
list(APPEND ${_target} ${_object_file})
endforeach()
else()
list(APPEND ${_target} ${ARGN})
endif()
endmacro()
+
+function(add_linker_script _target _linker_script_file)
+ get_filename_component(_file_full_path ${_linker_script_file} ABSOLUTE)
+ get_filename_component(_file_name ${_linker_script_file} NAME)
+ set(_generated_file_path_prefix "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_target}.dir/${_file_name}")
+
+ # Generate the ASM module containing sections specifications and layout.
+ set(_generated_file "${_generated_file_path_prefix}.S")
+ add_custom_command(
+ OUTPUT ${_generated_file}
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${_file_full_path}" "${_generated_file}"
+ DEPENDS ${_file_full_path})
+ set_source_files_properties(${_generated_file} PROPERTIES LANGUAGE "ASM" GENERATED TRUE)
+ add_asm_files(${_target}_linker_file ${_generated_file})
+
+ # Generate the C module containing extra sections specifications and layout,
+ # as well as comment-type linker #pragma directives.
+ set(_generated_file "${_generated_file_path_prefix}.c")
+ add_custom_command(
+ OUTPUT ${_generated_file}
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${_file_full_path}" "${_generated_file}"
+ DEPENDS ${_file_full_path})
+ set_source_files_properties(${_generated_file} PROPERTIES LANGUAGE "C" GENERATED TRUE)
+ list(APPEND ${_target}_linker_file ${_generated_file})
+
+ # Add both files to the sources of the target.
+ target_sources(${_target} PRIVATE "${${_target}_linker_file}")
+
+ # Create the additional linker response file.
+ set(_generated_file "${_generated_file_path_prefix}.rsp")
+ if(USE_CLANG_CL)
+ set(_no_std_includes_flag "-nostdinc")
+ else()
+ set(_no_std_includes_flag "/X")
+ endif()
+ add_custom_command(
+ #OUTPUT ${_generated_file}
+ TARGET ${_target} PRE_LINK
+ COMMAND ${CMAKE_C_COMPILER} /nologo ${_no_std_includes_flag} /D__LINKER__ /EP /c "${_file_full_path}" > "${_generated_file}"
+ DEPENDS ${_file_full_path}
+ VERBATIM)
+ set_source_files_properties(${_generated_file} PROPERTIES GENERATED TRUE)
+ add_target_link_flags(${_target} "@${_generated_file}")
+
+ # Unfortunately LINK_DEPENDS is ignored in non-Makefile generators (for now...)
+ # See also http://www.cmake.org/pipermail/cmake/2010-May/037206.html
+ add_target_property(${_target} LINK_DEPENDS ${_generated_file})
+endfunction()