mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 08:55:19 +00:00
[CMAKE]
- Add add_target_property macro and add wrapper macros to easily set important properties - This makes macros more consistent, follows CMake property names, favors per-target instead of per-directory property settings and favors adding to properties instead of replacing them - Convert the global settings to use the new add_compile_flags and add_target_link_flags - no functional change - Fix add_importlibs to add to compile definitions instead of replacing them - Big thanks to Amine svn path=/trunk/; revision=53545
This commit is contained in:
parent
5caee6abdf
commit
079f80ff56
4 changed files with 113 additions and 39 deletions
|
@ -231,7 +231,7 @@ function(add_importlibs _module)
|
|||
add_dependency_node(${_module})
|
||||
foreach(LIB ${ARGN})
|
||||
if ("${LIB}" MATCHES "msvcrt")
|
||||
add_definitions(-D_DLL -D__USE_CRTIMP)
|
||||
add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
|
||||
target_link_libraries(${_module} msvcrtex)
|
||||
endif()
|
||||
target_link_libraries(${_module} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
|
|
|
@ -1,4 +1,32 @@
|
|||
|
||||
# add_target_property
|
||||
# Adds one or more values to the specified property of the specified target.
|
||||
# Note that there are properties which require (semicolon-separated) lists,
|
||||
# while others require space-separated strings. The function has a list of
|
||||
# properties of the former variety and handles the values accordingly
|
||||
function(add_target_property _module _propname)
|
||||
list(APPEND _list_properties COMPILE_DEFINITIONS INCLUDE_DIRECTORIES)
|
||||
set(_newvalue "")
|
||||
get_target_property(_oldvalue ${_module} ${_propname})
|
||||
if (_oldvalue)
|
||||
set(_newvalue ${_oldvalue})
|
||||
endif()
|
||||
list(FIND _list_properties ${_propname} _list_index)
|
||||
if (NOT _list_index EQUAL -1)
|
||||
# list property
|
||||
list(APPEND _newvalue ${ARGN})
|
||||
else()
|
||||
# string property
|
||||
foreach(_flag ${ARGN})
|
||||
set(_newvalue "${_newvalue} ${_flag}")
|
||||
endforeach()
|
||||
endif()
|
||||
set_property(TARGET ${_module} PROPERTY ${_propname} ${_newvalue})
|
||||
endfunction()
|
||||
|
||||
#
|
||||
# For backwards compatibility. To be removed soon.
|
||||
#
|
||||
function(add_compiler_flags)
|
||||
set(flags_list "")
|
||||
# Adds the compiler flag to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
|
||||
|
@ -11,6 +39,9 @@ function(add_compiler_flags)
|
|||
endfunction()
|
||||
|
||||
function(add_linkerflag MODULE _flag)
|
||||
if (${ARGC} GREATER 2)
|
||||
message(STATUS "Excess arguments to add_linkerflag! Module ${MODULE}, args ${ARGN}")
|
||||
endif()
|
||||
set(NEW_LINKER_FLAGS ${_flag})
|
||||
get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
|
||||
if(LINKER_FLAGS)
|
||||
|
@ -19,6 +50,48 @@ function(add_linkerflag MODULE _flag)
|
|||
set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
|
||||
endfunction()
|
||||
|
||||
# New versions, using add_target_property where appropriate.
|
||||
# Note that the functions for string properties take a single string
|
||||
# argument while those for list properties can take a variable number of
|
||||
# arguments, all of which will be added to the list
|
||||
#
|
||||
# Examples:
|
||||
# add_compile_flags("-pedantic -O5")
|
||||
# add_target_link_flags(mymodule "-s --fatal-warnings")
|
||||
# add_target_compile_flags(mymodule "-pedantic -O5")
|
||||
# add_target_compile_definitions(mymodule WIN32 _WIN32)
|
||||
# add_target_include_directories(mymodule include ../include)
|
||||
function(add_compile_flags _flags)
|
||||
if (${ARGC} GREATER 1)
|
||||
message(STATUS "Excess arguments to add_compile_flags! Args ${ARGN}")
|
||||
endif()
|
||||
# Adds the compiler flag to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flags}" PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(add_target_compile_flags _module _flags)
|
||||
if (${ARGC} GREATER 2)
|
||||
message(STATUS "Excess arguments to add_target_compile_flags! Module ${_module}, args ${ARGN}")
|
||||
endif()
|
||||
add_target_property(${_module} COMPILE_FLAGS ${_flags})
|
||||
endfunction()
|
||||
|
||||
function(add_target_link_flags _module _flags)
|
||||
if (${ARGC} GREATER 2)
|
||||
message(STATUS "Excess arguments to add_target_link_flags! Module ${_module}, args ${ARGN}")
|
||||
endif()
|
||||
add_target_property(${_module} LINK_FLAGS ${_flags})
|
||||
endfunction()
|
||||
|
||||
function(add_target_compile_definitions _module)
|
||||
add_target_property(${_module} COMPILE_DEFINITIONS ${ARGN})
|
||||
endfunction()
|
||||
|
||||
function(add_target_include_directories _module)
|
||||
add_target_property(${_module} INCLUDE_DIRECTORIES ${ARGN})
|
||||
endfunction()
|
||||
|
||||
macro(set_unicode)
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
set(IS_UNICODE 1)
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
|
||||
# Compiler Core
|
||||
add_compiler_flags(-pipe -fms-extensions)
|
||||
add_compile_flags("-pipe -fms-extensions")
|
||||
|
||||
# Debugging (Note: DWARF-4 on 4.5.1 when we ship)
|
||||
add_compiler_flags(-gdwarf-2 -g2 -femit-struct-debug-detailed=none -feliminate-unused-debug-types)
|
||||
add_compile_flags("-gdwarf-2 -g2 -femit-struct-debug-detailed=none -feliminate-unused-debug-types")
|
||||
|
||||
# Tuning
|
||||
if(ARCH MATCHES i386)
|
||||
add_compiler_flags(-march=${OARCH} -mtune=${TUNE})
|
||||
add_compile_flags("-march=${OARCH} -mtune=${TUNE}")
|
||||
else()
|
||||
add_compiler_flags(-march=${OARCH})
|
||||
add_compile_flags("-march=${OARCH}")
|
||||
endif()
|
||||
|
||||
# Warnings
|
||||
add_compiler_flags(-Wall -Wno-char-subscripts -Wpointer-arith -Wno-multichar -Wno-error=uninitialized -Wno-unused-value -Winvalid-pch)
|
||||
add_compile_flags("-Wall -Wno-char-subscripts -Wpointer-arith -Wno-multichar -Wno-error=uninitialized -Wno-unused-value -Winvalid-pch")
|
||||
|
||||
if(ARCH MATCHES amd64)
|
||||
add_compiler_flags(-Wno-format)
|
||||
add_compile_flags("-Wno-format")
|
||||
elseif(ARCH MATCHES arm)
|
||||
add_compiler_flags(-Wno-attributes)
|
||||
add_compile_flags("-Wno-attributes")
|
||||
endif()
|
||||
|
||||
# Optimizations
|
||||
if(OPTIMIZE STREQUAL "1")
|
||||
add_compiler_flags(-Os)
|
||||
add_compile_flags("-Os")
|
||||
elseif(OPTIMIZE STREQUAL "2")
|
||||
add_compiler_flags(-Os)
|
||||
add_compile_flags("-Os")
|
||||
elseif(OPTIMIZE STREQUAL "3")
|
||||
add_compiler_flags(-O1)
|
||||
add_compile_flags("-O1")
|
||||
elseif(OPTIMIZE STREQUAL "4")
|
||||
add_compiler_flags(-O2)
|
||||
add_compile_flags("-O2")
|
||||
elseif(OPTIMIZE STREQUAL "5")
|
||||
add_compiler_flags(-O3)
|
||||
add_compile_flags("-O3")
|
||||
endif()
|
||||
|
||||
add_compiler_flags(-fno-strict-aliasing)
|
||||
add_compile_flags("-fno-strict-aliasing")
|
||||
|
||||
if(ARCH MATCHES i386)
|
||||
add_compiler_flags(-mpreferred-stack-boundary=2 -fno-set-stack-executable -fno-optimize-sibling-calls -fno-omit-frame-pointer)
|
||||
add_compile_flags("-mpreferred-stack-boundary=2 -fno-set-stack-executable -fno-optimize-sibling-calls -fno-omit-frame-pointer")
|
||||
if(OPTIMIZE STREQUAL "1")
|
||||
add_compiler_flags(-ftracer -momit-leaf-frame-pointer)
|
||||
add_compile_flags("-ftracer -momit-leaf-frame-pointer")
|
||||
endif()
|
||||
elseif(ARCH MATCHES amd64)
|
||||
add_compiler_flags(-mpreferred-stack-boundary=4)
|
||||
add_compile_flags("-mpreferred-stack-boundary=4")
|
||||
if(OPTIMIZE STREQUAL "1")
|
||||
add_compiler_flags(-ftracer -momit-leaf-frame-pointer)
|
||||
add_compile_flags("-ftracer -momit-leaf-frame-pointer")
|
||||
endif()
|
||||
elseif(ARCH MATCHES arm)
|
||||
if(OPTIMIZE STREQUAL "1")
|
||||
add_compiler_flags(-ftracer)
|
||||
add_compile_flags("-ftracer")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -100,24 +100,24 @@ set(CMAKE_RC_COMPILE_OBJECT
|
|||
# Optional 3rd parameter: stdcall stack bytes
|
||||
function(set_entrypoint MODULE ENTRYPOINT)
|
||||
if(${ENTRYPOINT} STREQUAL "0")
|
||||
add_linkerflag(${MODULE} "-Wl,-entry,0")
|
||||
add_target_link_flags(${MODULE} "-Wl,-entry,0")
|
||||
elseif(ARCH MATCHES i386)
|
||||
set(_entrysymbol _${ENTRYPOINT})
|
||||
if (${ARGC} GREATER 2)
|
||||
set(_entrysymbol ${_entrysymbol}@${ARGV2})
|
||||
endif()
|
||||
add_linkerflag(${MODULE} "-Wl,-entry,${_entrysymbol}")
|
||||
add_target_link_flags(${MODULE} "-Wl,-entry,${_entrysymbol}")
|
||||
else()
|
||||
add_linkerflag(${MODULE} "-Wl,-entry,${ENTRYPOINT}")
|
||||
add_target_link_flags(${MODULE} "-Wl,-entry,${ENTRYPOINT}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(set_subsystem MODULE SUBSYSTEM)
|
||||
add_linkerflag(${MODULE} "-Wl,--subsystem,${SUBSYSTEM}")
|
||||
add_target_link_flags(${MODULE} "-Wl,--subsystem,${SUBSYSTEM}")
|
||||
endfunction()
|
||||
|
||||
function(set_image_base MODULE IMAGE_BASE)
|
||||
add_linkerflag(${MODULE} "-Wl,--image-base,${IMAGE_BASE}")
|
||||
add_target_link_flags(${MODULE} "-Wl,--image-base,${IMAGE_BASE}")
|
||||
endfunction()
|
||||
|
||||
function(set_module_type MODULE TYPE)
|
||||
|
@ -158,7 +158,8 @@ function(set_module_type MODULE TYPE)
|
|||
set_entrypoint(${MODULE} DllMainCRTStartup 12)
|
||||
set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
|
||||
elseif(${TYPE} MATCHES kernelmodedriver)
|
||||
set_target_properties(${MODULE} PROPERTIES LINK_FLAGS "-Wl,--exclude-all-symbols -Wl,-file-alignment=0x1000 -Wl,-section-alignment=0x1000" SUFFIX ".sys")
|
||||
add_target_link_flags(${MODULE} "-Wl,--exclude-all-symbols -Wl,-file-alignment=0x1000 -Wl,-section-alignment=0x1000")
|
||||
set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
|
||||
set_entrypoint(${MODULE} DriverEntry 8)
|
||||
set_subsystem(${MODULE} native)
|
||||
set_image_base(${MODULE} 0x00010000)
|
||||
|
@ -342,7 +343,7 @@ if(PCH)
|
|||
set_source_files_properties(${_item} PROPERTIES COMPILE_FLAGS "-fpch-preprocess" OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_gch_filename})
|
||||
endif()
|
||||
endforeach()
|
||||
#set dependency checking : depends on precompiled header only whixh already depends on deeper header
|
||||
#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()
|
||||
|
|
|
@ -19,7 +19,7 @@ endif()
|
|||
|
||||
add_definitions(/Dinline=__inline /D__STDC__=1)
|
||||
|
||||
add_compiler_flags(/X /GR- /GS- /Zl /W3)
|
||||
add_compile_flags("/X /GR- /GS- /Zl /W3")
|
||||
|
||||
if(${_MACHINE_ARCH_FLAG} MATCHES X86)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB")
|
||||
|
@ -61,24 +61,24 @@ endmacro()
|
|||
|
||||
function(set_entrypoint _module _entrypoint)
|
||||
if(${_entrypoint} STREQUAL "0")
|
||||
add_linkerflag(${_module} "/NOENTRY")
|
||||
add_target_link_flags(${_module} "/NOENTRY")
|
||||
elseif(ARCH MATCHES i386)
|
||||
set(_entrysymbol ${_entrypoint})
|
||||
if (${ARGC} GREATER 2)
|
||||
set(_entrysymbol ${_entrysymbol}@${ARGV2})
|
||||
endif()
|
||||
add_linkerflag(${_module} "/ENTRY:${_entrysymbol}")
|
||||
add_target_link_flags(${_module} "/ENTRY:${_entrysymbol}")
|
||||
else()
|
||||
add_linkerflag(${_module} "/ENTRY:${_entrypoint}")
|
||||
add_target_link_flags(${_module} "/ENTRY:${_entrypoint}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(set_subsystem MODULE SUBSYSTEM)
|
||||
add_linkerflag(${MODULE} "/subsystem:${SUBSYSTEM}")
|
||||
add_target_link_flags(${MODULE} "/subsystem:${SUBSYSTEM}")
|
||||
endfunction()
|
||||
|
||||
function(set_image_base MODULE IMAGE_BASE)
|
||||
add_linkerflag(${MODULE} "/BASE:${IMAGE_BASE}")
|
||||
add_target_link_flags(${MODULE} "/BASE:${IMAGE_BASE}")
|
||||
endfunction()
|
||||
|
||||
function(set_module_type MODULE TYPE)
|
||||
|
@ -108,21 +108,21 @@ function(set_module_type MODULE TYPE)
|
|||
else()
|
||||
message(STATUS "${MODULE} has no base address")
|
||||
endif()
|
||||
add_linkerflag(${MODULE} "/DLL")
|
||||
add_target_link_flags(${MODULE} "/DLL")
|
||||
elseif(${TYPE} MATCHES win32ocx)
|
||||
set_entrypoint(${MODULE} DllMainCRTStartup 12)
|
||||
set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
|
||||
add_linkerflag(${MODULE} "/DLL")
|
||||
add_target_link_flags(${MODULE} "/DLL")
|
||||
elseif(${TYPE} MATCHES cpl)
|
||||
set_entrypoint(${MODULE} DllMainCRTStartup 12)
|
||||
set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
|
||||
add_linkerflag(${MODULE} "/DLL")
|
||||
add_target_link_flags(${MODULE} "/DLL")
|
||||
elseif(${TYPE} MATCHES kernelmodedriver)
|
||||
set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
|
||||
set_entrypoint(${MODULE} DriverEntry 8)
|
||||
set_subsystem(${MODULE} native)
|
||||
set_image_base(${MODULE} 0x00010000)
|
||||
add_linkerflag(${MODULE} "/DRIVER")
|
||||
add_target_link_flags(${MODULE} "/DRIVER")
|
||||
add_dependencies(${MODULE} bugcodes)
|
||||
elseif(${TYPE} MATCHES nativedll)
|
||||
set_subsystem(${MODULE} native)
|
||||
|
@ -195,7 +195,7 @@ endfunction()
|
|||
|
||||
macro(add_delay_importlibs MODULE)
|
||||
foreach(LIB ${ARGN})
|
||||
add_linkerflag(${MODULE} "/DELAYLOAD:${LIB}.dll")
|
||||
add_target_link_flags(${MODULE} "/DELAYLOAD:${LIB}.dll")
|
||||
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.LIB)
|
||||
add_dependencies(${MODULE} lib${LIB})
|
||||
endforeach()
|
||||
|
|
Loading…
Reference in a new issue