24bd8906176bbe765c540f5a6e600acaa22a750c
[reactos.git] / CMakeMacros.cmake
1
2 MACRO(_PCH_GET_COMPILE_FLAGS _target_name _out_compile_flags _header_filename)
3
4 # Add the precompiled header to the build
5 get_filename_component(FILE ${_header_filename} NAME)
6 set(_gch_filename "${_target_name}_${FILE}.gch")
7 list(APPEND ${_out_compile_flags} -c ${_header_filename} -o ${_gch_filename})
8
9 # This gets us our includes
10 get_directory_property(DIRINC INCLUDE_DIRECTORIES)
11 foreach(item ${DIRINC})
12 list(APPEND ${_out_compile_flags} -I${item})
13 endforeach(item)
14
15 # This is a particular bit of undocumented/hacky magic I'm quite proud of
16 get_directory_property(_compiler_flags DEFINITIONS)
17 string(REPLACE "\ " "\t" _compiler_flags ${_compiler_flags})
18 list(APPEND ${_out_compile_flags} ${_compiler_flags})
19
20 # This gets any specific definitions that were added with set-target-property
21 get_target_property(_target_defs ${_target_name} COMPILE_DEFINITIONS)
22 if (_target_defs)
23 foreach(item ${_target_defs})
24 list(APPEND ${_out_compile_flags} -D${item})
25 endforeach(item)
26 endif()
27
28 ENDMACRO(_PCH_GET_COMPILE_FLAGS)
29
30 MACRO(add_pch _target_name _header_filename _src_list)
31
32 get_filename_component(FILE ${_header_filename} NAME)
33 set(_gch_filename "${_target_name}_${FILE}.gch")
34 list(APPEND ${_src_list} ${_gch_filename})
35 _PCH_GET_COMPILE_FLAGS(${_target_name} _args ${_header_filename})
36 file(REMOVE ${_gch_filename})
37 add_custom_command(
38 OUTPUT ${_gch_filename}
39 COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} ${_args}
40 DEPENDS ${_header_filename})
41
42 ENDMACRO(add_pch _target_name _header_filename _src_list)
43
44 MACRO(spec2def _target_name _spec_file _def_file)
45
46 add_custom_command(
47 OUTPUT ${_def_file}
48 COMMAND native-winebuild -o ${_def_file} --def -E ${_spec_file} --filename ${_target_name}.dll
49 DEPENDS native-winebuild)
50 set_source_files_properties(${_def_file} PROPERTIES GENERATED TRUE)
51 add_custom_target(${_target_name}_def ALL DEPENDS ${_def_file})
52
53 ENDMACRO(spec2def _target_name _spec_file _def_file)
54
55 if (NOT MSVC)
56 MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
57
58 get_filename_component(OBJECT_PATH ${_object_file} PATH)
59 get_filename_component(OBJECT_NAME ${_object_file} NAME)
60 file(MAKE_DIRECTORY ${OBJECT_PATH})
61 get_directory_property(defines COMPILE_DEFINITIONS)
62 get_directory_property(includes INCLUDE_DIRECTORIES)
63
64 foreach(arg ${defines})
65 set(result_defs ${result_defs} -D${arg})
66 endforeach(arg ${defines})
67
68 foreach(arg ${includes})
69 set(result_incs -I${arg} ${result_incs})
70 endforeach(arg ${includes})
71
72 add_custom_command(
73 OUTPUT ${_object_file}
74 COMMAND nasm -o ${_object_file} ${result_incs} ${result_defs} -f bin ${_asm_file}
75 DEPENDS native-winebuild)
76 set_source_files_properties(${_object_file} PROPERTIES GENERATED TRUE)
77 add_custom_target(${_target_name} ALL DEPENDS ${_object_file})
78 add_minicd(${_object_file} loader ${OBJECT_NAME})
79 ENDMACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
80 else()
81 MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
82 ENDMACRO()
83 endif()
84
85 MACRO(MACRO_IDL_COMPILE_OBJECT OBJECT SOURCE)
86 GET_PROPERTY(FLAGS SOURCE ${SOURCE} PROPERTY COMPILE_FLAGS)
87 GET_PROPERTY(DEFINES SOURCE ${SOURCE} PROPERTY COMPILE_DEFINITIONS)
88 GET_PROPERTY(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
89 FOREACH(DIR ${INCLUDE_DIRECTORIES})
90 SET(FLAGS "${FLAGS} -I${DIR}")
91 ENDFOREACH()
92
93 SET(IDL_COMMAND ${CMAKE_IDL_COMPILE_OBJECT})
94 STRING(REPLACE "<CMAKE_IDL_COMPILER>" "${CMAKE_IDL_COMPILER}" IDL_COMMAND "${IDL_COMMAND}")
95 STRING(REPLACE <FLAGS> "${FLAGS}" IDL_COMMAND "${IDL_COMMAND}")
96 STRING(REPLACE "<DEFINES>" "${DEFINES}" IDL_COMMAND "${IDL_COMMAND}")
97 STRING(REPLACE "<OBJECT>" "${OBJECT}" IDL_COMMAND "${IDL_COMMAND}")
98 STRING(REPLACE "<SOURCE>" "${SOURCE}" IDL_COMMAND "${IDL_COMMAND}")
99 SEPARATE_ARGUMENTS(IDL_COMMAND)
100
101 ADD_CUSTOM_COMMAND(
102 OUTPUT ${OBJECT}
103 COMMAND ${IDL_COMMAND}
104 DEPENDS ${SOURCE}
105 VERBATIM
106 )
107 ENDMACRO()
108
109 MACRO(ADD_INTERFACE_DEFINITIONS TARGET)
110 FOREACH(SOURCE ${ARGN})
111 GET_FILENAME_COMPONENT(FILE ${SOURCE} NAME_WE)
112 SET(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.h)
113 MACRO_IDL_COMPILE_OBJECT(${OBJECT} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE})
114 LIST(APPEND OBJECTS ${OBJECT})
115 ENDFOREACH()
116 ADD_CUSTOM_TARGET(${TARGET} ALL DEPENDS ${OBJECTS})
117 ENDMACRO()
118
119 MACRO(add_minicd_target _targetname _dir _nameoncd)
120 get_target_property(FILENAME ${_targetname} LOCATION)
121
122 add_custom_command(
123 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcd/${_dir}/${_nameoncd}
124 COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${BOOTCD_DIR}/${_dir}/${_nameoncd})
125
126 add_custom_target(${_targetname}_minicd DEPENDS ${BOOTCD_DIR}/${_dir}/${_nameoncd})
127
128 add_dependencies(${_targetname}_minicd ${_targetname})
129 add_dependencies(minicd ${_targetname}_minicd)
130 ENDMACRO(add_minicd_target _targetname _dir _nameoncd)
131
132 MACRO(add_minicd FILENAME _dir _nameoncd)
133 add_custom_command(
134 OUTPUT ${BOOTCD_DIR}/${_dir}/${_nameoncd}
135 DEPENDS ${FILENAME}
136 COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${BOOTCD_DIR}/${_dir}/${_nameoncd})
137
138 add_custom_target(${_nameoncd}_minicd DEPENDS ${BOOTCD_DIR}/${_dir}/${_nameoncd})
139
140 add_dependencies(minicd ${_nameoncd}_minicd)
141 ENDMACRO(add_minicd)
142
143 macro(set_cpp)
144 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/lib/3rdparty/stlport/stlport)
145 set(IS_CPP 1)
146 endmacro()