2015-03-29 14:51:14 +00:00
## EXPERIMENTAL!!
# We need to use almost the same tricks as the ones used for MSVC 'add_asm_files'
# support because we are going to compile ASM files for a fixed target (16-bit x86)
# that is different from the main target.
if ( NOT MSVC )
###
### For GCC
###
function ( add_asm16_bin _target _binary_file _base_address )
set ( _concatenated_asm_file ${ CMAKE_CURRENT_BINARY_DIR } / ${ _target } .asm )
set ( _object_file ${ CMAKE_CURRENT_BINARY_DIR } / ${ _target } .o )
# unset(_source_file_list)
get_defines ( _directory_defines )
get_includes ( _directory_includes )
get_directory_property ( _defines COMPILE_DEFINITIONS )
# Build a list of all the defines needed.
foreach ( _source_file ${ ARGN } )
get_filename_component ( _source_file_full_path ${ _source_file } ABSOLUTE )
get_source_file_property ( _defines_semicolon_list ${ _source_file_full_path } COMPILE_DEFINITIONS )
# unset(_source_file_defines)
foreach ( _define ${ _defines_semicolon_list } )
if ( NOT ${ _define } STREQUAL "NOTFOUND" )
list ( APPEND _source_file_defines -D ${ _define } )
endif ( )
endforeach ( )
list ( APPEND _source_file_list ${ _source_file_full_path } )
endforeach ( )
# We do not support 16-bit ASM linking so the only way to compile
# many ASM files is by concatenating them into a single one and
# compile the resulting file.
concatenate_files ( ${ _concatenated_asm_file } ${ _source_file_list } )
2015-09-15 01:59:14 +00:00
set_source_files_properties ( ${ _concatenated_asm_file } PROPERTIES GENERATED TRUE )
2015-03-29 14:51:14 +00:00
##
## All this part is the same as CreateBootSectorTarget
##
add_custom_command (
O U T P U T $ { _ o b j e c t _ f i l e }
2016-04-20 12:36:25 +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 } - x a s s e m b l e r - w i t h - c p p - o $ { _ o b j e c t _ f i l e } - I $ { R E A C T O S _ S O U R C E _ D I R } / s d k / 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 } / s d k / i n c l u d e / a s m $ { _ d i r e c t o r y _ i n c l u d e s } $ { _ s o u r c e _ f i l e _ d e f i n e s } $ { _ d i r e c t o r y _ d e f i n e s } - D _ _ A S M _ _ - c $ { _ c o n c a t e n a t e d _ a s m _ f i l e }
2015-03-29 14:51:14 +00:00
D E P E N D S $ { _ c o n c a t e n a t e d _ a s m _ 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 }
# COMMAND objcopy --output-target binary --image-base 0x${_base_address} ${_object_file} ${_binary_file}
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 )
add_custom_target ( ${ _target } ALL DEPENDS ${ _binary_file } )
2015-09-15 01:59:14 +00:00
# set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_target} SUFFIX ".bin")
set_target_properties ( ${ _target } PROPERTIES LOCATION_ ${ CMAKE_BUILD_TYPE } ${ _binary_file } ) ## Support of $<TARGET_FILE:xxx> is limited to add_executable() or add_library()
set_target_properties ( ${ _target } PROPERTIES LOCATION ${ _binary_file } ) ## Support of $<TARGET_FILE:xxx> is limited to add_executable() or add_library()
add_clean_target ( ${ _target } )
2015-03-29 14:51:14 +00:00
endfunction ( )
else ( )
###
### For MSVC
###
function ( add_asm16_bin _target _binary_file _base_address )
set ( _concatenated_asm_file ${ CMAKE_CURRENT_BINARY_DIR } / ${ _target } .asm )
set ( _preprocessed_asm_file ${ CMAKE_CURRENT_BINARY_DIR } / ${ _target } .tmp )
set ( _object_file ${ CMAKE_CURRENT_BINARY_DIR } / ${ _target } .obj )
# unset(_source_file_list)
get_defines ( _directory_defines )
get_includes ( _directory_includes )
get_directory_property ( _defines COMPILE_DEFINITIONS )
# Build a list of all the defines needed.
foreach ( _source_file ${ ARGN } )
get_filename_component ( _source_file_full_path ${ _source_file } ABSOLUTE )
get_source_file_property ( _defines_semicolon_list ${ _source_file_full_path } COMPILE_DEFINITIONS )
# unset(_source_file_defines)
foreach ( _define ${ _defines_semicolon_list } )
if ( NOT ${ _define } STREQUAL "NOTFOUND" )
list ( APPEND _source_file_defines -D ${ _define } )
endif ( )
endforeach ( )
list ( APPEND _source_file_list ${ _source_file_full_path } )
endforeach ( )
# We do not support 16-bit ASM linking so the only way to compile
# many ASM files is by concatenating them into a single one and
# compile the resulting file.
concatenate_files ( ${ _concatenated_asm_file } ${ _source_file_list } )
2015-09-15 01:59:14 +00:00
set_source_files_properties ( ${ _concatenated_asm_file } PROPERTIES GENERATED TRUE )
2015-03-29 14:51:14 +00:00
##
## All this part is the same as CreateBootSectorTarget
##
if ( ARCH STREQUAL "arm" )
set ( _pp_asm16_compile_command ${ CMAKE_ASM16_COMPILER } -nologo -o ${ _object_file } ${ _preprocessed_asm_file } )
else ( )
set ( _pp_asm16_compile_command ${ CMAKE_ASM16_COMPILER } /nologo /Cp /Fo ${ _object_file } /c /Ta ${ _preprocessed_asm_file } )
endif ( )
2017-10-27 21:18:01 +00:00
# FIXME: clang-cl can't compile this so use cl here instead of ${CMAKE_C_COMPILER} in the meantime
2015-03-29 14:51:14 +00:00
add_custom_command (
O U T P U T $ { _ p r e p r o c e s s e d _ a s m _ f i l e } $ { _ o b j e c t _ f i l e }
2017-10-27 21:18:01 +00:00
C O M M A N D c l / n o l o g o / X / I $ { R E A C T O S _ S O U R C E _ D I R } / s d k / 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 } / s d k / i n c l u d e / a s m $ { _ d i r e c t o r y _ i n c l u d e s } $ { _ s o u r c e _ f i l e _ d e f i n e s } $ { _ d i r e c t o r y _ d e f i n e s } / D _ _ A S M _ _ / D _ U S E _ M L / E P / c $ { _ c o n c a t e n a t e d _ a s m _ f i l e } > $ { _ p r e p r o c e s s e d _ a s m _ f i l e } & & $ { _ p p _ a s m 1 6 _ c o m p i l e _ c o m m a n d }
2015-03-29 14:51:14 +00:00
D E P E N D S $ { _ c o n c a t e n a t e d _ a s m _ 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 } n a t i v e - o b j 2 b i n )
add_custom_target ( ${ _target } ALL DEPENDS ${ _binary_file } )
2015-09-15 01:59:14 +00:00
# set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_target} SUFFIX ".bin")
set_target_properties ( ${ _target } PROPERTIES LOCATION_ ${ CMAKE_BUILD_TYPE } ${ _binary_file } ) ## Support of $<TARGET_FILE:xxx> is limited to add_executable() or add_library()
set_target_properties ( ${ _target } PROPERTIES LOCATION ${ _binary_file } ) ## Support of $<TARGET_FILE:xxx> is limited to add_executable() or add_library()
add_clean_target ( ${ _target } )
2015-03-29 14:51:14 +00:00
endfunction ( )
endif ( )