[NTVDM]: Minor code reorganization. StartTickCount is commented out because it's...
[reactos.git] / reactos / subsystems / mvdm / asm16.cmake
1 ## EXPERIMENTAL!!
2
3 # We need to use almost the same tricks as the ones used for MSVC 'add_asm_files'
4 # support because we are going to compile ASM files for a fixed target (16-bit x86)
5 # that is different from the main target.
6
7 if(NOT MSVC)
8 ###
9 ### For GCC
10 ###
11 function(add_asm16_bin _target _binary_file _base_address)
12 set(_concatenated_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.asm)
13 set(_object_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.o)
14
15 # unset(_source_file_list)
16
17 get_defines(_directory_defines)
18 get_includes(_directory_includes)
19 get_directory_property(_defines COMPILE_DEFINITIONS)
20
21 # Build a list of all the defines needed.
22 foreach(_source_file ${ARGN})
23 get_filename_component(_source_file_full_path ${_source_file} ABSOLUTE)
24 get_source_file_property(_defines_semicolon_list ${_source_file_full_path} COMPILE_DEFINITIONS)
25
26 # unset(_source_file_defines)
27
28 foreach(_define ${_defines_semicolon_list})
29 if(NOT ${_define} STREQUAL "NOTFOUND")
30 list(APPEND _source_file_defines -D${_define})
31 endif()
32 endforeach()
33
34 list(APPEND _source_file_list ${_source_file_full_path})
35 endforeach()
36
37 # We do not support 16-bit ASM linking so the only way to compile
38 # many ASM files is by concatenating them into a single one and
39 # compile the resulting file.
40 concatenate_files(${_concatenated_asm_file} ${_source_file_list})
41
42 ##
43 ## All this part is the same as CreateBootSectorTarget
44 ##
45 add_custom_command(
46 OUTPUT ${_object_file}
47 COMMAND ${CMAKE_ASM_COMPILER} -x assembler-with-cpp -o ${_object_file} -I${REACTOS_SOURCE_DIR}/include/asm -I${REACTOS_BINARY_DIR}/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} -D__ASM__ -c ${_concatenated_asm_file}
48 DEPENDS ${_concatenated_asm_file})
49
50 add_custom_command(
51 OUTPUT ${_binary_file}
52 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
53 # COMMAND objcopy --output-target binary --image-base 0x${_base_address} ${_object_file} ${_binary_file}
54 DEPENDS ${_object_file} native-obj2bin)
55
56 set_source_files_properties(${_object_file} ${_binary_file} PROPERTIES GENERATED TRUE)
57
58 add_custom_target(${_target} ALL DEPENDS ${_binary_file})
59 endfunction()
60
61 else()
62 ###
63 ### For MSVC
64 ###
65 function(add_asm16_bin _target _binary_file _base_address)
66 set(_concatenated_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.asm)
67 set(_preprocessed_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.tmp)
68 set(_object_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.obj)
69
70 # unset(_source_file_list)
71
72 get_defines(_directory_defines)
73 get_includes(_directory_includes)
74 get_directory_property(_defines COMPILE_DEFINITIONS)
75
76 # Build a list of all the defines needed.
77 foreach(_source_file ${ARGN})
78 get_filename_component(_source_file_full_path ${_source_file} ABSOLUTE)
79 get_source_file_property(_defines_semicolon_list ${_source_file_full_path} COMPILE_DEFINITIONS)
80
81 # unset(_source_file_defines)
82
83 foreach(_define ${_defines_semicolon_list})
84 if(NOT ${_define} STREQUAL "NOTFOUND")
85 list(APPEND _source_file_defines -D${_define})
86 endif()
87 endforeach()
88
89 list(APPEND _source_file_list ${_source_file_full_path})
90 endforeach()
91
92 # We do not support 16-bit ASM linking so the only way to compile
93 # many ASM files is by concatenating them into a single one and
94 # compile the resulting file.
95 concatenate_files(${_concatenated_asm_file} ${_source_file_list})
96
97 ##
98 ## All this part is the same as CreateBootSectorTarget
99 ##
100 if(ARCH STREQUAL "arm")
101 set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} -nologo -o ${_object_file} ${_preprocessed_asm_file})
102 else()
103 set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_preprocessed_asm_file})
104 endif()
105
106 add_custom_command(
107 OUTPUT ${_preprocessed_asm_file} ${_object_file}
108 COMMAND ${CMAKE_C_COMPILER} /nologo /X /I${REACTOS_SOURCE_DIR}/include/asm /I${REACTOS_BINARY_DIR}/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} /D__ASM__ /D_USE_ML /EP /c ${_concatenated_asm_file} > ${_preprocessed_asm_file} && ${_pp_asm16_compile_command}
109 DEPENDS ${_concatenated_asm_file})
110
111 add_custom_command(
112 OUTPUT ${_binary_file}
113 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
114 DEPENDS ${_object_file} native-obj2bin)
115
116 set_source_files_properties(${_object_file} ${_preprocessed_asm_file} ${_binary_file} PROPERTIES GENERATED TRUE)
117
118 add_custom_target(${_target} ALL DEPENDS ${_binary_file})
119 endfunction()
120
121 endif()