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-07-08 01:50:19 +00:00
if ( ARCH MATCHES i386 )
add_definitions ( /DWIN32 /D_WINDOWS )
endif ( )
add_definitions ( /Dinline=__inline /D__STDC__=1 )
add_compiler_flags ( /X /GR- /GS- /Zl /W3 )
2010-09-19 20:06:02 +00:00
2011-01-09 16:49:10 +00:00
if ( ${ _MACHINE_ARCH_FLAG } MATCHES X86 )
2011-07-08 01:50:19 +00:00
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB" )
set ( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB" )
2011-01-09 16:49:10 +00:00
endif ( )
2010-11-05 00:08:12 +00:00
2011-01-24 18:13:40 +00:00
if ( ${ ARCH } MATCHES amd64 )
2011-07-08 01:50:19 +00:00
add_definitions ( /D__x86_64 )
set ( SPEC2DEF_ARCH x86_64 )
else ( )
set ( SPEC2DEF_ARCH i386 )
2011-01-24 18:13:40 +00:00
endif ( )
2011-07-08 01:50:19 +00:00
link_directories ( ${ REACTOS_SOURCE_DIR } /importlibs ${ REACTOS_BINARY_DIR } /importlibs ${ REACTOS_BINARY_DIR } /lib/sdk/crt )
set ( CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <DEFINES> /I${REACTOS_SOURCE_DIR}/include/psdk /I${REACTOS_BINARY_DIR}/include/psdk /I${REACTOS_SOURCE_DIR}/include /I${REACTOS_SOURCE_DIR}/include/reactos /I${REACTOS_BINARY_DIR}/include/reactos /I${REACTOS_SOURCE_DIR}/include/reactos/wine /I${REACTOS_SOURCE_DIR}/include/crt /I${REACTOS_SOURCE_DIR}/include/crt/mingw32 /fo <OBJECT> <SOURCE>" )
if ( MSVC_IDE )
# Asm source files are not supported in VS generators yet. As a result, <DEFINES> isn't recognized.
# We may temporarily use just the global defines, but this is not a solution as some modules (minihal for example) apply additional definitions to source files, so we get an incorrect build of such targets.
get_directory_property ( definitions DEFINITIONS )
set ( CMAKE_ASM_COMPILE_OBJECT
" < C M A K E _ C _ C O M P I L E R > / n o l o g o / X / I $ { R E A C T O S _ S O U R C E _ D I R } / i n c l u d e / a s m / I $ { R E A C T O S _ B I N A R Y _ D I R } / i n c l u d e / a s m < F L A G S > $ { d e f i n i t i o n s } / D _ _ A S M _ _ / D _ U S E _ M L / E P / c < S O U R C E > > < O B J E C T > . t m p "
" < C M A K E _ A S M _ C O M P I L E R > / n o l o g o / C p / F o < O B J E C T > / c / T a < O B J E C T > . t m p " )
else ( )
# NMake Makefiles
set ( CMAKE_ASM_COMPILE_OBJECT
" < C M A K E _ C _ C O M P I L E R > / n o l o g o / X / I $ { R E A C T O S _ S O U R C E _ D I R } / i n c l u d e / a s m / I $ { R E A C T O S _ B I N A R Y _ D I R } / i n c l u d e / a s m < F L A G S > < D E F I N E S > / D _ _ A S M _ _ / D _ U S E _ M L / E P / c < S O U R C E > > < O B J E C T > . t m p "
" < C M A K E _ A S M _ C O M P I L E R > / n o l o g o / C p / F o < O B J E C T > / c / T a < O B J E C T > . t m p " )
endif ( )
2010-11-02 09:22:58 +00:00
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 } )
2011-07-08 01:50:19 +00:00
set ( CMAKE_ASM_CREATE_STATIC_LIBRARY ${ CMAKE_C_CREATE_STATIC_LIBRARY } )
2010-10-10 16:17:40 +00:00
2011-07-08 01:50:19 +00:00
macro ( add_pch _target_name _FILE )
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 )
2011-05-10 13:15:51 +00:00
add_dependencies ( ${ MODULE } psdk )
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 )
2011-07-08 01:50:19 +00:00
elseif ( ${ TYPE } MATCHES win32gui )
2010-10-02 16:09:32 +00:00
set_subsystem ( ${ MODULE } windows )
2010-11-21 12:32:03 +00:00
if ( IS_UNICODE )
2011-07-08 01:50:19 +00:00
set_entrypoint ( ${ MODULE } wWinMainCRTStartup )
2010-11-21 12:32:03 +00:00
else ( )
2011-07-08 01:50:19 +00:00
set_entrypoint ( ${ MODULE } WinMainCRTStartup )
endif ( IS_UNICODE )
elseif ( ${ TYPE } MATCHES win32cui )
2010-10-02 16:09:32 +00:00
set_subsystem ( ${ MODULE } console )
2010-11-21 12:32:03 +00:00
if ( IS_UNICODE )
2011-07-08 01:50:19 +00:00
set_entrypoint ( ${ MODULE } wmainCRTStartup )
2010-11-21 12:32:03 +00:00
else ( )
2011-07-08 01:50:19 +00:00
set_entrypoint ( ${ MODULE } mainCRTStartup )
endif ( IS_UNICODE )
elseif ( ${ 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 ( )
2010-11-10 12:33:24 +00:00
add_linkerflag ( ${ MODULE } "/DLL" )
2011-07-08 01:50:19 +00:00
elseif ( ${ 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
add_linkerflag ( ${ MODULE } "/DLL" )
2011-07-08 01:50:19 +00:00
elseif ( ${ 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
add_linkerflag ( ${ MODULE } "/DLL" )
2011-07-08 01:50:19 +00:00
elseif ( ${ TYPE } MATCHES kernelmodedriver )
2011-01-09 16:49:10 +00:00
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 )
endif ( )
2010-09-19 20:06:02 +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
O U T P U T $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ s t u b s . a s m $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ e x p . d e f
2011-07-08 01:50:19 +00:00
C O M M A N D n a t i v e - s p e c 2 d e f - - m s - - k i l l - a t - a = $ { S P E C 2 D E F _ A R C H } - - i m p l i b - n = $ { _ n a m e } $ { _ s u f f i x } - d = $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ e x p . d e f - l = $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ s t u b s . a s m $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { _ e x p o r t s _ f i l e }
2010-12-22 16:37:32 +00:00
D E P E N D S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { _ e x p o r t s _ f i l e } )
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 (
O U T P U T $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ s t u b s . o b j
2011-01-28 17:40:36 +00:00
C O M M A N D $ { C M A K E _ A S M _ C O M P I L E R } / n o l o g o / C p / F o $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ s t u b s . o b j / c / T a $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ s t u b s . a s m
2010-12-02 21:56:40 +00:00
D E P E N D S " $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ s t u b s . a s m " )
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
O U T P U T $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } . l i b
2011-07-08 01:50:19 +00:00
C O M M A N D L I N K / L I B / N O L O G O / D E F : $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ e x p . d e f / O U T : $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } . l i b $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ s t u b s . o b j $ { _ l i b r a r i e s }
2010-12-02 21:56:40 +00:00
D E P E N D S $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ s t u b s . o b j $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } _ e x p . d e f )
2010-11-10 12:33:24 +00:00
# Add the importlib target
2010-11-01 17:24:32 +00:00
add_custom_target (
l i b $ { _ n a m e }
2010-12-02 21:56:40 +00:00
D E P E N D S $ { C M A K E _ B I N A R Y _ D I R } / i m p o r t l i b s / l i b $ { _ n a m e } . l i b )
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 ( )
2011-07-08 01:50:19 +00:00
macro ( add_delay_importlibs MODULE )
# TODO. For now forward to normal import libs
add_importlibs ( ${ MODULE } ${ ARGN } )
2010-10-31 17:31:05 +00:00
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
O U T P U T $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { _ f i l e } . d e f $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { _ f i l e } _ s t u b s . c
2011-07-08 01:50:19 +00:00
C O M M A N D n a t i v e - s p e c 2 d e f - - m s - - k i l l - a t - a = $ { S P E C 2 D E F _ A R C H } - n = $ { _ d l l n a m e } - d = $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { _ f i l e } . d e f - s = $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { _ f i l e } _ s t u b s . c $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { _ s p e c _ f i l e }
2010-11-10 12:33:24 +00:00
D E P E N D S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { _ s p e c _ f i l e } )
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
P R O P E R T I E S G E N E R A T E D T R U E )
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
2011-07-08 01:50:19 +00:00
macro ( CreateBootSectorTarget2 _target_name _asm_file _binary_file _base_address )
set ( _object_file ${ _binary_file } .obj )
set ( _temp_file ${ _binary_file } .tmp )
add_custom_command (
O U T P U T $ { _ t e m p _ f i l e }
C O M M A N D $ { C M A K E _ C _ C O M P I L E R } / n o l o g o / X / I $ { R E A C T O S _ S O U R C E _ D I R } / i n c l u d e / a s m / I $ { R E A C T O S _ B I N A R Y _ D I R } / i n c l u d e / a s m / D _ _ A S M _ _ / D _ U S E _ M L / E P / c $ { _ a s m _ f i l e } > $ { _ t e m p _ f i l e }
D E P E N D S $ { _ a s m _ f i l e } )
add_custom_command (
O U T P U T $ { _ o b j e c t _ f i l e }
C O M M A N D m l / n o l o g o / C p / F o $ { _ o b j e c t _ f i l e } / c / T a $ { _ t e m p _ f i l e }
D E P E N D S $ { _ t e m p _ f i l e } )
add_custom_command (
O U T P U T $ { _ b i n a r y _ f i l e }
C O M M A N D n a t i v e - o b j 2 b i n $ { _ o b j e c t _ f i l e } $ { _ b i n a r y _ f i l e } $ { _ b a s e _ a d d r e s s }
D E P E N D S $ { _ o b j e c t _ f i l e } )
set_source_files_properties ( ${ _object_file } ${ _temp_file } ${ _binary_file } PROPERTIES GENERATED TRUE )
add_custom_target ( ${ _target_name } ALL DEPENDS ${ _binary_file } )
endmacro ( )