[GDI32_APITEST] Add a PCH.
[reactos.git] / 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 set_source_files_properties(${_concatenated_asm_file} PROPERTIES GENERATED TRUE)
42
43 ##
44 ## All this part is the same as CreateBootSectorTarget
45 ##
46 add_custom_command(
47 OUTPUT ${_object_file}
48 COMMAND ${CMAKE_ASM_COMPILER} -x assembler-with-cpp -o ${_object_file} -I${REACTOS_SOURCE_DIR}/sdk/include/asm -I${REACTOS_BINARY_DIR}/sdk/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} -D__ASM__ -c ${_concatenated_asm_file}
49 DEPENDS ${_concatenated_asm_file})
50
51 add_custom_command(
52 OUTPUT ${_binary_file}
53 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
54 # COMMAND objcopy --output-target binary --image-base 0x${_base_address} ${_object_file} ${_binary_file}
55 DEPENDS ${_object_file} native-obj2bin)
56
57 add_custom_target(${_target} ALL DEPENDS ${_binary_file})
58 # set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_target} SUFFIX ".bin")
59 set_target_properties(${_target} PROPERTIES LOCATION_${CMAKE_BUILD_TYPE} ${_binary_file}) ## Support of $<TARGET_FILE:xxx> is limited to add_executable() or add_library()
60 set_target_properties(${_target} PROPERTIES LOCATION ${_binary_file}) ## Support of $<TARGET_FILE:xxx> is limited to add_executable() or add_library()
61 add_clean_target(${_target})
62 endfunction()
63
64 else()
65 ###
66 ### For MSVC
67 ###
68 function(add_asm16_bin _target _binary_file _base_address)
69 set(_concatenated_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.asm)
70 set(_preprocessed_asm_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.tmp)
71 set(_object_file ${CMAKE_CURRENT_BINARY_DIR}/${_target}.obj)
72
73 # unset(_source_file_list)
74
75 get_defines(_directory_defines)
76 get_includes(_directory_includes)
77 get_directory_property(_defines COMPILE_DEFINITIONS)
78
79 # Build a list of all the defines needed.
80 foreach(_source_file ${ARGN})
81 get_filename_component(_source_file_full_path ${_source_file} ABSOLUTE)
82 get_source_file_property(_defines_semicolon_list ${_source_file_full_path} COMPILE_DEFINITIONS)
83
84 # unset(_source_file_defines)
85
86 foreach(_define ${_defines_semicolon_list})
87 if(NOT ${_define} STREQUAL "NOTFOUND")
88 list(APPEND _source_file_defines -D${_define})
89 endif()
90 endforeach()
91
92 list(APPEND _source_file_list ${_source_file_full_path})
93 endforeach()
94
95 # We do not support 16-bit ASM linking so the only way to compile
96 # many ASM files is by concatenating them into a single one and
97 # compile the resulting file.
98 concatenate_files(${_concatenated_asm_file} ${_source_file_list})
99 set_source_files_properties(${_concatenated_asm_file} PROPERTIES GENERATED TRUE)
100
101 ##
102 ## All this part is the same as CreateBootSectorTarget
103 ##
104 if(ARCH STREQUAL "arm")
105 set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} -nologo -o ${_object_file} ${_preprocessed_asm_file})
106 else()
107 set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_preprocessed_asm_file})
108 endif()
109
110 # FIXME: clang-cl can't compile this so use cl here instead of ${CMAKE_C_COMPILER} in the meantime
111 add_custom_command(
112 OUTPUT ${_preprocessed_asm_file} ${_object_file}
113 COMMAND cl /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/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}
114 DEPENDS ${_concatenated_asm_file})
115
116 add_custom_command(
117 OUTPUT ${_binary_file}
118 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
119 DEPENDS ${_object_file} native-obj2bin)
120
121 add_custom_target(${_target} ALL DEPENDS ${_binary_file})
122 # set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_target} SUFFIX ".bin")
123 set_target_properties(${_target} PROPERTIES LOCATION_${CMAKE_BUILD_TYPE} ${_binary_file}) ## Support of $<TARGET_FILE:xxx> is limited to add_executable() or add_library()
124 set_target_properties(${_target} PROPERTIES LOCATION ${_binary_file}) ## Support of $<TARGET_FILE:xxx> is limited to add_executable() or add_library()
125 add_clean_target(${_target})
126 endfunction()
127
128 endif()