2011-05-16 13:12:07 +00:00
if ( ${ CMAKE_BUILD_TYPE } MATCHES Debug )
2011-10-04 14:20:25 +00:00
# no optimization
2011-05-16 13:12:07 +00:00
elseif ( OPTIMIZE STREQUAL "1" )
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 ( )
2011-06-22 11:31:01 +00:00
if ( ARCH MATCHES i386 )
add_definitions ( /DWIN32 /D_WINDOWS )
endif ( )
add_definitions ( /Dinline=__inline /D__STDC__=1 )
2011-05-16 13:12:07 +00:00
2011-09-03 14:57:27 +00:00
add_compile_flags ( "/X /GR- /GS- /Zl /W3" )
2011-06-22 13:17:37 +00:00
2011-05-16 13:12:07 +00:00
if ( ${ _MACHINE_ARCH_FLAG } MATCHES X86 )
2011-10-04 14:20:25 +00:00
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB /RELEASE" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB /RELEASE" )
set ( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB /RELEASE" )
2011-05-16 13:12:07 +00:00
endif ( )
if ( ${ ARCH } MATCHES amd64 )
2011-06-22 11:31:01 +00:00
add_definitions ( /D__x86_64 )
2011-06-06 09:58:58 +00:00
set ( SPEC2DEF_ARCH x86_64 )
else ( )
set ( SPEC2DEF_ARCH i386 )
2011-05-16 13:12:07 +00:00
endif ( )
2011-06-18 21:39:27 +00:00
link_directories ( ${ REACTOS_SOURCE_DIR } /importlibs ${ REACTOS_BINARY_DIR } /importlibs ${ REACTOS_BINARY_DIR } /lib/sdk/crt )
2011-05-16 13:12:07 +00:00
2011-08-25 22:32:57 +00:00
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>" )
2011-06-11 16:09:57 +00:00
2011-06-14 15:28:16 +00:00
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 ( )
2011-06-11 16:09:57 +00:00
2011-05-16 13:12:07 +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-06-11 16:09:57 +00:00
set ( CMAKE_ASM_CREATE_STATIC_LIBRARY ${ CMAKE_C_CREATE_STATIC_LIBRARY } )
2011-05-16 13:12:07 +00:00
2011-06-05 14:51:31 +00:00
macro ( add_pch _target_name _FILE )
2011-05-16 13:12:07 +00:00
endmacro ( )
2011-08-20 12:29:51 +00:00
function ( set_entrypoint _module _entrypoint )
if ( ${ _entrypoint } STREQUAL "0" )
2011-09-03 14:57:27 +00:00
add_target_link_flags ( ${ _module } "/NOENTRY" )
2011-08-20 12:29:51 +00:00
elseif ( ARCH MATCHES i386 )
set ( _entrysymbol ${ _entrypoint } )
2011-10-02 18:59:33 +00:00
if ( ${ ARGC } GREATER 2 )
2011-08-20 12:29:51 +00:00
set ( _entrysymbol ${ _entrysymbol } @ ${ ARGV2 } )
endif ( )
2011-09-03 14:57:27 +00:00
add_target_link_flags ( ${ _module } "/ENTRY:${_entrysymbol}" )
2011-05-16 13:12:07 +00:00
else ( )
2011-09-03 14:57:27 +00:00
add_target_link_flags ( ${ _module } "/ENTRY:${_entrypoint}" )
2011-05-16 13:12:07 +00:00
endif ( )
2011-08-08 11:54:20 +00:00
endfunction ( )
2011-05-16 13:12:07 +00:00
2011-08-08 11:54:20 +00:00
function ( set_subsystem MODULE SUBSYSTEM )
2011-09-03 14:57:27 +00:00
add_target_link_flags ( ${ MODULE } "/subsystem:${SUBSYSTEM}" )
2011-08-08 11:54:20 +00:00
endfunction ( )
2011-05-16 13:12:07 +00:00
2011-08-08 11:54:20 +00:00
function ( set_image_base MODULE IMAGE_BASE )
2011-09-03 14:57:27 +00:00
add_target_link_flags ( ${ MODULE } "/BASE:${IMAGE_BASE}" )
2011-08-08 11:54:20 +00:00
endfunction ( )
2011-05-16 13:12:07 +00:00
2011-09-03 17:48:57 +00:00
function ( set_module_type_toolchain MODULE TYPE )
if ( ( ${ TYPE } STREQUAL win32dll ) OR ( ${ TYPE } STREQUAL win32ocx ) OR ( ${ TYPE } STREQUAL cpl ) )
2011-09-03 14:57:27 +00:00
add_target_link_flags ( ${ MODULE } "/DLL" )
2011-09-03 17:48:57 +00:00
elseif ( ${ TYPE } STREQUAL kernelmodedriver )
2011-09-03 14:57:27 +00:00
add_target_link_flags ( ${ MODULE } "/DRIVER" )
2011-05-16 13:12:07 +00:00
endif ( )
2011-08-08 11:54:20 +00:00
endfunction ( )
2011-05-16 13:12:07 +00:00
2011-08-08 11:54:20 +00:00
function ( set_rc_compiler )
2011-08-21 21:18:59 +00:00
get_directory_property ( defines COMPILE_DEFINITIONS )
get_directory_property ( includes INCLUDE_DIRECTORIES )
foreach ( arg ${ defines } )
set ( rc_result_defs "${rc_result_defs} /D${arg}" )
endforeach ( )
foreach ( arg ${ includes } )
set ( rc_result_incs "/I${arg} ${rc_result_incs}" )
endforeach ( )
2011-08-25 22:32:57 +00:00
set ( CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_result_defs} /I${CMAKE_CURRENT_SOURCE_DIR} ${rc_result_incs} /fo <OBJECT> <SOURCE>" PARENT_SCOPE )
2011-08-08 11:54:20 +00:00
endfunction ( )
2011-05-16 13:12:07 +00:00
# Thanks MS for creating a stupid linker
2011-08-08 11:54:20 +00:00
function ( add_importlib_target _exports_file )
2011-05-16 13:12:07 +00:00
get_filename_component ( _name ${ _exports_file } NAME_WE )
get_target_property ( _suffix ${ _name } SUFFIX )
if ( ${ _suffix } STREQUAL "_suffix-NOTFOUND" )
get_target_property ( _type ${ _name } TYPE )
if ( ${ _type } MATCHES EXECUTABLE )
set ( _suffix ".exe" )
else ( )
set ( _suffix ".dll" )
endif ( )
endif ( )
# Generate the asm stub file and the export def file
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 . 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-06-26 22:23:08 +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 }
2011-08-05 20:40:40 +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 } n a t i v e - s p e c 2 d e f )
2011-05-16 13:12:07 +00:00
# Assemble the stub file
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
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
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 " )
# Add neccessary importlibs for redirections
set ( _libraries "" )
2011-08-07 00:46:46 +00:00
set ( _dependencies "" )
2011-05-16 13:12:07 +00:00
foreach ( _lib ${ ARGN } )
list ( APPEND _libraries "${CMAKE_BINARY_DIR}/importlibs/${_lib}.lib" )
list ( APPEND _dependencies ${ _lib } )
endforeach ( )
# Build the importlib
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 } . l i b
2011-06-06 09:58:58 +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 }
2011-05-16 13:12:07 +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 )
# Add the importlib target
add_custom_target (
l i b $ { _ n a m e }
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 )
add_dependencies ( lib ${ _name } asm ${ _dependencies } )
2011-08-08 11:54:20 +00:00
endfunction ( )
2011-05-16 13:12:07 +00:00
2011-06-10 20:44:47 +00:00
macro ( add_delay_importlibs MODULE )
2011-08-11 13:39:06 +00:00
foreach ( LIB ${ ARGN } )
2011-09-03 14:57:27 +00:00
add_target_link_flags ( ${ MODULE } "/DELAYLOAD:${LIB}.dll" )
2011-08-11 13:39:06 +00:00
target_link_libraries ( ${ MODULE } ${ CMAKE_BINARY_DIR } /importlibs/lib ${ LIB } .LIB )
add_dependencies ( ${ MODULE } lib ${ LIB } )
endforeach ( )
target_link_libraries ( ${ MODULE } delayimp )
2011-06-10 20:44:47 +00:00
endmacro ( )
2011-08-08 11:54:20 +00:00
function ( spec2def _dllname _spec_file )
2011-08-15 15:36:25 +00:00
if ( ${ ARGC } GREATER 2 )
set ( _file ${ ARGV2 } )
else ( )
get_filename_component ( _file ${ _spec_file } NAME_WE )
endif ( )
2011-05-16 13:12:07 +00:00
add_custom_command (
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-06-06 09:58:58 +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 }
2011-08-05 20:40:40 +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 } n a t i v e - s p e c 2 d e f )
2011-05-16 13:12:07 +00:00
set_source_files_properties ( ${ CMAKE_CURRENT_BINARY_DIR } / ${ _file } .def ${ CMAKE_CURRENT_BINARY_DIR } / ${ _file } _stubs.c
P R O P E R T I E S G E N E R A T E D T R U E )
2011-08-08 11:54:20 +00:00
endfunction ( )
2011-05-16 13:12:07 +00:00
2011-10-03 19:09:26 +00:00
macro ( macro_mc FLAG FILE )
set ( COMMAND_MC mc ${ FLAG } -r ${ REACTOS_BINARY_DIR } /include/reactos -h ${ REACTOS_BINARY_DIR } /include/reactos ${ CMAKE_CURRENT_SOURCE_DIR } / ${ FILE } .mc )
2011-05-16 13:12:07 +00:00
endmacro ( )
file ( MAKE_DIRECTORY ${ CMAKE_BINARY_DIR } /importlibs )
#pseh workaround
set ( PSEH_LIB "pseh" )
2011-06-07 23:22:38 +00:00
2011-08-26 17:33:33 +00:00
# Use full path for ml when using x64 VS
if ( ( ARCH MATCHES amd64 ) AND ( $ENV{ VCINSTALLDIR } ) )
set ( CMAKE_ASM16_COMPILER $ENV{ VCINSTALLDIR } /bin/ml.exe )
else ( )
set ( CMAKE_ASM16_COMPILER ml.exe )
endif ( )
2011-08-08 11:54:20 +00:00
function ( CreateBootSectorTarget2 _target_name _asm_file _binary_file _base_address )
2011-06-07 23:22:38 +00:00
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 }
2011-08-26 17:33:33 +00:00
C O M M A N D $ { C M A K E _ A S M 1 6 _ C O M P I L E R } / 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 }
2011-06-07 23:22:38 +00:00
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 }
2011-08-05 20:40:40 +00:00
D E P E N D S $ { _ o b j e c t _ f i l e } n a t i v e - o b j 2 b i n )
2011-06-07 23:22:38 +00:00
set_source_files_properties ( ${ _object_file } ${ _temp_file } ${ _binary_file } PROPERTIES GENERATED TRUE )
add_custom_target ( ${ _target_name } ALL DEPENDS ${ _binary_file } )
2011-08-08 11:54:20 +00:00
endfunction ( )
2011-09-11 00:44:13 +00:00
function ( allow_warnings __module )
endfunction ( )