2010-09-19 20:06:02 +00:00
|
|
|
|
2011-02-14 11:09:48 +00:00
|
|
|
if(${CMAKE_BUILD_TYPE} MATCHES Debug)
|
|
|
|
# no optimitation
|
|
|
|
elseif(OPTIMIZE STREQUAL "1")
|
2011-01-09 16:49:10 +00:00
|
|
|
add_definitions(/O1)
|
|
|
|
elseif(OPTIMIZE STREQUAL "2")
|
|
|
|
add_definitions(/O2)
|
|
|
|
elseif(OPTIMIZE STREQUAL "3")
|
|
|
|
add_definitions(/Ot /Ox /GS-)
|
|
|
|
elseif(OPTIMIZE STREQUAL "4")
|
|
|
|
add_definitions(/Os /Ox /GS-)
|
|
|
|
elseif(OPTIMIZE STREQUAL "5")
|
|
|
|
add_definitions(/GF /Gy /Ob2 /Os /Ox /GS-)
|
|
|
|
endif()
|
2010-09-19 20:06:02 +00:00
|
|
|
|
2011-02-14 10:32:46 +00:00
|
|
|
add_definitions(/X /GR- /GS- /Zl)
|
2010-09-19 20:06:02 +00:00
|
|
|
add_definitions(-Dinline=__inline -D__STDC__=1)
|
|
|
|
|
2011-01-09 16:49:10 +00:00
|
|
|
if(${_MACHINE_ARCH_FLAG} MATCHES X86)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
|
|
|
|
endif()
|
2010-11-05 00:08:12 +00:00
|
|
|
|
2011-01-24 18:13:40 +00:00
|
|
|
if(${ARCH} MATCHES amd64)
|
|
|
|
add_definitions(-D__x86_64)
|
|
|
|
endif()
|
|
|
|
|
2010-11-02 09:22:58 +00:00
|
|
|
link_directories("${REACTOS_BINARY_DIR}/importlibs" ${REACTOS_BINARY_DIR}/lib/3rdparty/mingw)
|
|
|
|
|
2011-02-01 22:06:31 +00:00
|
|
|
set(CMAKE_RC_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY})
|
|
|
|
set(CMAKE_ASM_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY})
|
2010-10-10 16:17:40 +00:00
|
|
|
|
2011-01-09 16:49:10 +00:00
|
|
|
macro(add_pch _target_name _header_filename _src_list)
|
2010-11-21 12:32:03 +00:00
|
|
|
get_filename_component(FILE ${_header_filename} NAME)
|
|
|
|
set(_gch_filename "${_target_name}_${FILE}.gch")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${_gch_filename}
|
2010-11-22 12:25:25 +00:00
|
|
|
COMMAND echo Ignoring precompiled header
|
2010-11-21 12:32:03 +00:00
|
|
|
DEPENDS ${_header_filename})
|
2011-01-09 16:49:10 +00:00
|
|
|
endmacro()
|
2010-11-21 12:32:03 +00:00
|
|
|
|
2010-11-08 12:24:33 +00:00
|
|
|
macro(add_linkerflag MODULE _flag)
|
|
|
|
set(NEW_LINKER_FLAGS ${_flag})
|
2010-09-25 20:44:46 +00:00
|
|
|
get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
|
|
|
|
if(LINKER_FLAGS)
|
|
|
|
set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
|
|
|
|
endif()
|
|
|
|
set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
|
2010-09-19 20:06:02 +00:00
|
|
|
endmacro()
|
|
|
|
|
2010-11-08 12:24:33 +00:00
|
|
|
macro(set_entrypoint MODULE ENTRYPOINT)
|
|
|
|
if(${ENTRYPOINT} STREQUAL "0")
|
2010-11-21 19:47:55 +00:00
|
|
|
add_linkerflag(${MODULE} "/NOENTRY")
|
2010-11-08 12:24:33 +00:00
|
|
|
else()
|
|
|
|
add_linkerflag(${MODULE} "/ENTRY:${ENTRYPOINT}")
|
2010-09-25 20:44:46 +00:00
|
|
|
endif()
|
2010-11-08 12:24:33 +00:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(set_subsystem MODULE SUBSYSTEM)
|
|
|
|
add_linkerflag(${MODULE} "/subsystem:${SUBSYSTEM}")
|
2010-09-19 23:03:25 +00:00
|
|
|
endmacro()
|
|
|
|
|
2010-10-26 07:31:04 +00:00
|
|
|
macro(set_image_base MODULE IMAGE_BASE)
|
2010-11-08 12:24:33 +00:00
|
|
|
add_linkerflag(${MODULE} "/BASE:${IMAGE_BASE}")
|
2010-10-26 07:31:04 +00:00
|
|
|
endmacro()
|
|
|
|
|
2010-09-19 20:06:02 +00:00
|
|
|
macro(set_module_type MODULE TYPE)
|
2010-10-26 07:31:04 +00:00
|
|
|
add_dependencies(${MODULE} psdk buildno_header)
|
2010-10-02 16:09:32 +00:00
|
|
|
if(${TYPE} MATCHES nativecui)
|
|
|
|
set_subsystem(${MODULE} native)
|
2010-11-21 12:32:03 +00:00
|
|
|
set_entrypoint(${MODULE} NtProcessStartup@4)
|
2010-10-02 16:09:32 +00:00
|
|
|
endif()
|
|
|
|
if (${TYPE} MATCHES win32gui)
|
|
|
|
set_subsystem(${MODULE} windows)
|
2010-11-10 12:33:24 +00:00
|
|
|
set_entrypoint(${MODULE} WinMainCRTStartup)
|
2010-11-21 12:32:03 +00:00
|
|
|
if(IS_UNICODE)
|
|
|
|
target_link_libraries(${MODULE} mingw_wmain)
|
|
|
|
else()
|
|
|
|
target_link_libraries(${MODULE} mingw_main)
|
|
|
|
endif()
|
2011-01-09 16:49:10 +00:00
|
|
|
target_link_libraries(${MODULE} mingw_common msvcsup)
|
2010-10-02 16:09:32 +00:00
|
|
|
endif ()
|
|
|
|
if (${TYPE} MATCHES win32cui)
|
|
|
|
set_subsystem(${MODULE} console)
|
2010-11-02 09:22:58 +00:00
|
|
|
set_entrypoint(${MODULE} mainCRTStartup)
|
2010-11-21 12:32:03 +00:00
|
|
|
if(IS_UNICODE)
|
|
|
|
target_link_libraries(${MODULE} mingw_wmain)
|
|
|
|
else()
|
|
|
|
target_link_libraries(${MODULE} mingw_main)
|
|
|
|
endif()
|
2011-01-09 16:49:10 +00:00
|
|
|
target_link_libraries(${MODULE} mingw_common msvcsup)
|
2010-10-02 16:09:32 +00:00
|
|
|
endif ()
|
2010-11-02 09:22:58 +00:00
|
|
|
if(${TYPE} MATCHES win32dll)
|
2010-11-02 21:31:45 +00:00
|
|
|
# Need this only because mingw library is broken
|
|
|
|
set_entrypoint(${MODULE} DllMainCRTStartup@12)
|
2011-01-09 16:49:10 +00:00
|
|
|
if(DEFINED baseaddress_${MODULE})
|
|
|
|
set_image_base(${MODULE} ${baseaddress_${MODULE}})
|
|
|
|
else()
|
|
|
|
message(STATUS "${MODULE} has no base address")
|
|
|
|
endif()
|
|
|
|
target_link_libraries(${MODULE} mingw_common mingw_dllmain msvcsup)
|
2010-11-10 12:33:24 +00:00
|
|
|
add_linkerflag(${MODULE} "/DLL")
|
2010-11-21 12:32:03 +00:00
|
|
|
endif()
|
|
|
|
if(${TYPE} MATCHES win32ocx)
|
2010-11-26 23:48:07 +00:00
|
|
|
set_entrypoint(${MODULE} DllMainCRTStartup@12)
|
2010-11-21 12:32:03 +00:00
|
|
|
set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
|
2010-11-26 23:48:07 +00:00
|
|
|
target_link_libraries(${MODULE} mingw_common mingw_dllmain msvcsup)
|
|
|
|
add_linkerflag(${MODULE} "/DLL")
|
2010-11-21 12:32:03 +00:00
|
|
|
endif()
|
|
|
|
if(${TYPE} MATCHES cpl)
|
2010-11-26 23:48:07 +00:00
|
|
|
set_entrypoint(${MODULE} DllMainCRTStartup@12)
|
2010-11-21 12:32:03 +00:00
|
|
|
set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
|
2010-11-26 23:48:07 +00:00
|
|
|
target_link_libraries(${MODULE} mingw_common mingw_dllmain msvcsup)
|
|
|
|
add_linkerflag(${MODULE} "/DLL")
|
2010-11-02 09:22:58 +00:00
|
|
|
endif()
|
2011-01-09 16:49:10 +00:00
|
|
|
if(${TYPE} MATCHES kernelmodedriver)
|
|
|
|
set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
|
|
|
|
set_entrypoint(${MODULE} DriverEntry@8)
|
|
|
|
set_subsystem(${MODULE} native)
|
2010-11-21 00:55:46 +00:00
|
|
|
set_image_base(${MODULE} 0x00010000)
|
2010-11-26 23:48:07 +00:00
|
|
|
add_linkerflag(${MODULE} "/DRIVER")
|
2011-01-09 16:49:10 +00:00
|
|
|
add_dependencies(${MODULE} bugcodes)
|
2011-01-28 17:40:36 +00:00
|
|
|
target_link_libraries(${MODULE} msvcsup)
|
2011-01-09 16:49:10 +00:00
|
|
|
endif()
|
2010-09-19 20:06:02 +00:00
|
|
|
endmacro()
|
|
|
|
|
2010-10-02 16:09:32 +00:00
|
|
|
macro(set_unicode)
|
2010-11-21 12:32:03 +00:00
|
|
|
add_definitions(-DUNICODE -D_UNICODE)
|
|
|
|
set(IS_UNICODE 1)
|
2010-09-25 23:01:09 +00:00
|
|
|
endmacro()
|
|
|
|
|
2010-09-27 09:14:54 +00:00
|
|
|
macro(set_rc_compiler)
|
|
|
|
# dummy, this workaround is only needed in mingw due to lack of RC support in cmake
|
2010-09-28 13:32:41 +00:00
|
|
|
endmacro()
|
|
|
|
|
2010-11-10 12:33:24 +00:00
|
|
|
# Thanks MS for creating a stupid linker
|
2010-12-22 16:37:32 +00:00
|
|
|
macro(add_importlib_target _exports_file)
|
|
|
|
get_filename_component(_name ${_exports_file} NAME_WE)
|
2011-01-27 21:50:54 +00:00
|
|
|
get_target_property(_suffix ${_name} SUFFIX)
|
2011-01-28 11:25:24 +00:00
|
|
|
if(${_suffix} STREQUAL "_suffix-NOTFOUND")
|
|
|
|
get_target_property(_type ${_name} TYPE)
|
|
|
|
if(${_type} MATCHES EXECUTABLE)
|
|
|
|
set(_suffix ".exe")
|
|
|
|
else()
|
|
|
|
set(_suffix ".dll")
|
|
|
|
endif()
|
|
|
|
endif()
|
2010-11-10 12:33:24 +00:00
|
|
|
|
2010-12-02 22:16:59 +00:00
|
|
|
# Generate the asm stub file and the export def file
|
2010-11-10 12:33:24 +00:00
|
|
|
add_custom_command(
|
2010-12-02 21:56:40 +00:00
|
|
|
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def
|
2011-01-28 09:31:54 +00:00
|
|
|
COMMAND native-spec2def --ms --kill-at -r -n=${_name}${_suffix} -d=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def -l=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}
|
2010-12-22 16:37:32 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file})
|
2010-11-10 12:33:24 +00:00
|
|
|
|
2010-12-02 22:16:59 +00:00
|
|
|
# Assemble the stub file
|
2010-11-10 12:33:24 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj
|
2011-01-28 17:40:36 +00:00
|
|
|
COMMAND ${CMAKE_ASM_COMPILER} /nologo /Cp /Fo${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj /c /Ta ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm
|
2010-12-02 21:56:40 +00:00
|
|
|
DEPENDS "${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm")
|
2010-11-10 12:33:24 +00:00
|
|
|
|
|
|
|
# Add neccessary importlibs for redirections
|
2010-11-19 10:54:05 +00:00
|
|
|
set(_libraries "")
|
2010-11-10 12:33:24 +00:00
|
|
|
foreach(_lib ${ARGN})
|
|
|
|
list(APPEND _libraries "${CMAKE_BINARY_DIR}/importlibs/${_lib}.lib")
|
2010-11-28 16:12:25 +00:00
|
|
|
list(APPEND _dependencies ${_lib})
|
2010-11-10 12:33:24 +00:00
|
|
|
endforeach()
|
2010-10-31 17:31:05 +00:00
|
|
|
|
2010-11-10 12:33:24 +00:00
|
|
|
# Build the importlib
|
2010-11-02 21:31:45 +00:00
|
|
|
add_custom_command(
|
2010-11-19 10:54:05 +00:00
|
|
|
OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
|
|
|
|
COMMAND LINK /LIB /NOLOGO /MACHINE:X86 /DEF:${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${_libraries}
|
2010-12-02 21:56:40 +00:00
|
|
|
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def)
|
2010-11-10 12:33:24 +00:00
|
|
|
|
|
|
|
# Add the importlib target
|
2010-11-01 17:24:32 +00:00
|
|
|
add_custom_target(
|
|
|
|
lib${_name}
|
2010-12-02 21:56:40 +00:00
|
|
|
DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib)
|
2011-01-24 18:13:40 +00:00
|
|
|
|
2010-11-28 16:12:25 +00:00
|
|
|
add_dependencies(lib${_name} asm ${_dependencies})
|
2010-10-31 17:31:05 +00:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(add_importlibs MODULE)
|
|
|
|
foreach(LIB ${ARGN})
|
|
|
|
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.lib)
|
2010-11-02 21:31:45 +00:00
|
|
|
add_dependencies(${MODULE} lib${LIB})
|
2010-10-31 17:31:05 +00:00
|
|
|
endforeach()
|
|
|
|
endmacro()
|
|
|
|
|
2010-11-19 17:41:48 +00:00
|
|
|
macro(spec2def _dllname _spec_file)
|
2010-11-10 12:33:24 +00:00
|
|
|
get_filename_component(_file ${_spec_file} NAME_WE)
|
|
|
|
add_custom_command(
|
2010-11-29 18:36:22 +00:00
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
|
2011-01-25 16:31:04 +00:00
|
|
|
COMMAND native-spec2def --ms --kill-at -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
|
2010-11-10 12:33:24 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file})
|
2010-11-29 18:35:43 +00:00
|
|
|
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
|
2010-11-19 14:21:18 +00:00
|
|
|
PROPERTIES GENERATED TRUE)
|
2010-11-19 17:41:48 +00:00
|
|
|
endmacro()
|
2010-11-10 12:33:24 +00:00
|
|
|
|
2011-01-08 20:44:41 +00:00
|
|
|
macro(macro_mc FILE)
|
2011-01-25 18:09:29 +00:00
|
|
|
set(COMMAND_MC mc -r ${REACTOS_BINARY_DIR}/include/reactos -h ${REACTOS_BINARY_DIR}/include/reactos ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)
|
2011-01-08 20:44:41 +00:00
|
|
|
endmacro()
|
|
|
|
|
2010-10-31 17:31:05 +00:00
|
|
|
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/importlibs)
|
|
|
|
|
2010-11-01 17:24:32 +00:00
|
|
|
#pseh workaround
|
2011-01-25 16:31:04 +00:00
|
|
|
set(PSEH_LIB "pseh")
|
2010-11-01 17:24:32 +00:00
|
|
|
|