[CMAKE]
[reactos.git] / CMakeMacros.cmake
index d3e4a34..880555a 100644 (file)
 
-MACRO(_PCH_GET_COMPILE_FLAGS _target_name _out_compile_flags _header_filename)
+MACRO(_PCH_GET_COMPILE_FLAGS _target_name _out_compile_flags _header_filename)\r
+\r
+    # Add the precompiled header to the build\r
+    get_filename_component(FILE ${_header_filename} NAME)\r
+    set(_gch_filename "${_target_name}_${FILE}.gch")\r
+    list(APPEND ${_out_compile_flags} -c ${_header_filename} -o ${_gch_filename})\r
+\r
+    # This gets us our includes\r
+    get_directory_property(DIRINC INCLUDE_DIRECTORIES)\r
+    foreach(item ${DIRINC})\r
+        list(APPEND ${_out_compile_flags} -I${item})\r
+    endforeach(item) \r
+\r
+    # This is a particular bit of undocumented/hacky magic I'm quite proud of\r
+    get_directory_property(_compiler_flags DEFINITIONS)\r
+    string(REPLACE "\ " "\t" _compiler_flags ${_compiler_flags})\r
+    list(APPEND ${_out_compile_flags} ${_compiler_flags})\r
+\r
+    # This gets any specific definitions that were added with set-target-property\r
+    get_target_property(_target_defs ${_target_name} COMPILE_DEFINITIONS)\r
+    if (_target_defs)\r
+        foreach(item ${_target_defs})\r
+            list(APPEND ${_out_compile_flags} -D${item})\r
+        endforeach(item)\r
+    endif()\r
+\r
+ENDMACRO(_PCH_GET_COMPILE_FLAGS) \r
+\r
+MACRO(add_pch _target_name _header_filename _src_list)\r
+    \r
+    get_filename_component(FILE ${_header_filename} NAME)\r
+    set(_gch_filename "${_target_name}_${FILE}.gch")\r
+    list(APPEND ${_src_list} ${_gch_filename})\r
+    _PCH_GET_COMPILE_FLAGS(${_target_name} _args ${_header_filename})\r
+    file(REMOVE ${_gch_filename})\r
+    add_custom_command(\r
+        OUTPUT ${_gch_filename}\r
+        COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} ${_args}\r
+        DEPENDS ${_header_filename})\r
+\r
+ENDMACRO(add_pch _target_name _header_filename _src_list)\r
+\r
+MACRO(spec2def _target_name _spec_file _def_file)\r
+\r
+    add_custom_command(\r
+        OUTPUT ${_def_file}\r
+        COMMAND native-winebuild -o ${_def_file} --def -E ${_spec_file} --filename ${_target_name}.dll\r
+        DEPENDS native-winebuild)\r
+    set_source_files_properties(${_def_file} PROPERTIES GENERATED TRUE)\r
+    add_custom_target(${_target_name}_def ALL DEPENDS ${_def_file})\r
+\r
+ENDMACRO(spec2def _target_name _spec_file _def_file)\r
+\r
+if (NOT MSVC)\r
+MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)\r
+\r
+    get_filename_component(OBJECT_PATH ${_object_file} PATH)\r
+    get_filename_component(OBJECT_NAME ${_object_file} NAME)\r
+    file(MAKE_DIRECTORY ${OBJECT_PATH})\r
+    get_directory_property(defines COMPILE_DEFINITIONS)\r
+    get_directory_property(includes INCLUDE_DIRECTORIES)\r
+\r
+    foreach(arg ${defines})\r
+        set(result_defs ${result_defs} -D${arg})\r
+    endforeach(arg ${defines})\r
+\r
+    foreach(arg ${includes})\r
+        set(result_incs -I${arg} ${result_incs})\r
+    endforeach(arg ${includes})\r
+\r
+    add_custom_command(\r
+        OUTPUT ${_object_file}\r
+        COMMAND nasm -o ${_object_file} ${result_incs} ${result_defs} -f bin ${_asm_file}\r
+        DEPENDS native-winebuild)\r
+    set_source_files_properties(${_object_file} PROPERTIES GENERATED TRUE)\r
+    add_custom_target(${_target_name} ALL DEPENDS ${_object_file})\r
+    add_minicd(${_object_file} loader ${OBJECT_NAME})\r
+ENDMACRO(CreateBootSectorTarget _target_name _asm_file _object_file)\r
+else()\r
+MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)\r
+ENDMACRO()\r
+endif()\r
+\r
+MACRO(MACRO_IDL_COMPILE_OBJECT OBJECT SOURCE)\r
+  GET_PROPERTY(FLAGS SOURCE ${SOURCE} PROPERTY COMPILE_FLAGS)\r
+  GET_PROPERTY(DEFINES SOURCE ${SOURCE} PROPERTY COMPILE_DEFINITIONS)\r
+  GET_PROPERTY(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)\r
+  FOREACH(DIR ${INCLUDE_DIRECTORIES})\r
+    SET(FLAGS "${FLAGS} -I${DIR}")\r
+  ENDFOREACH()\r
+\r
+  SET(IDL_COMMAND ${CMAKE_IDL_COMPILE_OBJECT})\r
+  STRING(REPLACE "<CMAKE_IDL_COMPILER>" "${CMAKE_IDL_COMPILER}" IDL_COMMAND "${IDL_COMMAND}")\r
+  STRING(REPLACE <FLAGS> "${FLAGS}" IDL_COMMAND "${IDL_COMMAND}")\r
+  STRING(REPLACE "<DEFINES>" "${DEFINES}" IDL_COMMAND "${IDL_COMMAND}")\r
+  STRING(REPLACE "<OBJECT>" "${OBJECT}" IDL_COMMAND "${IDL_COMMAND}")\r
+  STRING(REPLACE "<SOURCE>" "${SOURCE}" IDL_COMMAND "${IDL_COMMAND}")\r
+  SEPARATE_ARGUMENTS(IDL_COMMAND)\r
+\r
+  ADD_CUSTOM_COMMAND(\r
+    OUTPUT ${OBJECT}\r
+    COMMAND ${IDL_COMMAND}\r
+    DEPENDS ${SOURCE}\r
+    VERBATIM\r
+  )\r
+ENDMACRO()\r
+\r
+MACRO(ADD_INTERFACE_DEFINITIONS TARGET)\r
+  FOREACH(SOURCE ${ARGN})\r
+    GET_FILENAME_COMPONENT(FILE ${SOURCE} NAME_WE)\r
+    SET(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.h)\r
+    MACRO_IDL_COMPILE_OBJECT(${OBJECT} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE})\r
+    LIST(APPEND OBJECTS ${OBJECT})\r
+  ENDFOREACH()\r
+  ADD_CUSTOM_TARGET(${TARGET} ALL DEPENDS ${OBJECTS})\r
+ENDMACRO()\r
+\r
+MACRO(add_minicd_target _targetname _dir) # optional parameter: _nameoncd\r
+    get_target_property(FILENAME ${_targetname} LOCATION)\r
+\r
+    if("${ARGN}" STREQUAL "")\r
+       get_filename_component(_nameoncd ${FILENAME} NAME)\r
+    else()\r
+       set(_nameoncd ${ARGN})\r
+    endif()\r
+\r
+    add_custom_command(\r
+        OUTPUT ${BOOTCD_DIR}/${_dir}/${_nameoncd}        \r
+        COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${BOOTCD_DIR}/${_dir}/${_nameoncd})\r
+\r
+    add_custom_target(${_targetname}_minicd DEPENDS ${BOOTCD_DIR}/${_dir}/${_nameoncd})\r
+\r
+    add_dependencies(${_targetname}_minicd ${_targetname})\r
+    add_dependencies(minicd ${_targetname}_minicd)\r
+ENDMACRO(add_minicd_target _targetname _dir _nameoncd)\r
+\r
+MACRO(add_minicd FILENAME _dir _nameoncd)\r
+    add_custom_command(\r
+        OUTPUT ${BOOTCD_DIR}/${_dir}/${_nameoncd}\r
+        DEPENDS ${FILENAME}\r
+        COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${BOOTCD_DIR}/${_dir}/${_nameoncd})\r
+        \r
+    add_custom_target(${_nameoncd}_minicd DEPENDS ${BOOTCD_DIR}/${_dir}/${_nameoncd})\r
+    \r
+    add_dependencies(minicd ${_nameoncd}_minicd)\r
+ENDMACRO(add_minicd)\r
 
-  # Add the precompiled header to the build
-  set(_gch_filename "${_header_filename}.gch")
-  list(APPEND ${_out_compile_flags} -c ${_header_filename} -o ${_gch_filename})
-
-  # This gets us our includes
-  get_directory_property(DIRINC INCLUDE_DIRECTORIES)
-  foreach(item ${DIRINC})
-    list(APPEND ${_out_compile_flags} -I${item})
-  endforeach(item) 
-
-  # This is a particular bit of undocumented/hacky magic I'm quite proud of
-  get_directory_property(_compiler_flags DEFINITIONS)
-  STRING(REPLACE "\ " "\t" _compiler_flags ${_compiler_flags})
-  list(APPEND ${_out_compile_flags} ${_compiler_flags})
-
-  # This gets any specific definitions that were added with set-target-property
-  GET_TARGET_PROPERTY(_target_defs ${_target_name} COMPILE_DEFINITIONS)
-  if (_target_defs)
-    foreach(item ${_target_defs})
-      list(APPEND ${_out_compile_flags} -D${item})
-    endforeach(item)
-  endif()
-
-ENDMACRO(_PCH_GET_COMPILE_FLAGS) 
-
-MACRO(add_pch _target_name _header_filename _src_list)
-
-  set(_gch_filename "${_header_filename}.gch")
-  list(APPEND ${_src_list} ${_gch_filename})
-  _PCH_GET_COMPILE_FLAGS(${_target_name} _args ${_header_filename})
-  file(REMOVE ${_gch_filename})
-  add_custom_command(
-    OUTPUT ${_gch_filename}
-    COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} ${_args}
-    DEPENDS ${_header_filename})
-
-ENDMACRO(add_pch _target_name _header_filename _src_list)
+macro(set_cpp)
+  include_directories(BEFORE ${REACTOS_SOURCE_DIR}/lib/3rdparty/stlport/stlport)
+  set(IS_CPP 1)
+endmacro()
+\r
+MACRO(add_livecd_target _targetname _dir )# optional parameter : _nameoncd\r
+    \r
+    get_target_property(FILENAME ${_targetname} LOCATION)\r
+\r
+    if("${ARGN}" STREQUAL "")\r
+       get_filename_component(_nameoncd ${FILENAME} NAME)\r
+    else()\r
+       set(_nameoncd ${ARGN})\r
+    endif()\r
+\r
+    add_custom_command(\r
+        OUTPUT ${LIVECD_DIR}/${_dir}/${_nameoncd}        \r
+        COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${LIVECD_DIR}/${_dir}/${_nameoncd})\r
+        \r
+    add_custom_target(${_targetname}_livecd DEPENDS ${LIVECD_DIR}/${_dir}/${_nameoncd})\r
+\r
+    add_dependencies(${_targetname}_livecd ${_targetname})\r
+    add_dependencies(livecd ${_targetname}_livecd)\r
+ENDMACRO(add_livecd_target _targetname _dir _nameoncd)\r
+\r
+MACRO(add_livecd FILENAME _dir _nameoncd)\r
+    add_custom_command(\r
+        OUTPUT ${LIVECD_DIR}/${_dir}/${_nameoncd}\r
+        DEPENDS ${FILENAME}\r
+        COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${LIVECD_DIR}/${_dir}/${_nameoncd})\r
+        \r
+    add_custom_target(${_nameoncd}_livecd DEPENDS ${LIVECD_DIR}/${_dir}/${_nameoncd})\r
+    \r
+    add_dependencies(livecd ${_nameoncd}_livecd)\r
+ENDMACRO(add_livecd)\r
+\r
+macro(custom_incdefs)\r
+    if(NOT DEFINED result_incs) #rpc_defines\r
+        get_directory_property(rpc_defines COMPILE_DEFINITIONS)\r
+        get_directory_property(rpc_includes INCLUDE_DIRECTORIES)\r
+\r
+        foreach(arg ${rpc_defines})\r
+            set(result_defs ${result_defs} -D${arg})\r
+        endforeach(arg ${defines})\r
+\r
+        foreach(arg ${rpc_includes})\r
+            set(result_incs -I${arg} ${result_incs})\r
+        endforeach(arg ${includes})\r
+    endif()\r
+endmacro(custom_incdefs)\r
+\r
+macro(rpcproxy TARGET)\r
+    custom_incdefs()\r
+        list(APPEND SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c)\r
+\r
+    foreach(_in_FILE ${ARGN})\r
+        get_filename_component(FILE ${_in_FILE} NAME_WE)\r
+        add_custom_command(\r
+            OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c\r
+            COMMAND native-widl ${result_incs} ${result_defs} -m32 --win32 -h -H ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.h -p -P ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl\r
+            DEPENDS native-widl)\r
+        set_source_files_properties(\r
+            ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c\r
+            PROPERTIES GENERATED TRUE)\r
+        list(APPEND SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c)\r
+        list(APPEND IDLS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl)\r
+        list(APPEND PROXY_DEPENDS ${TARGET}_${FILE}_p)\r
+        add_custom_target(${TARGET}_${FILE}_p \r
+            DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c)\r
+        #add_dependencies(${TARGET}_proxy ${TARGET}_${FILE}_p)\r
+    endforeach(_in_FILE ${ARGN})\r
+    \r
+       add_custom_command(\r
+           OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c\r
+           COMMAND native-widl ${result_incs} ${result_defs}  -m32 --win32 --dlldata-only --dlldata=${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c ${IDLS}\r
+           DEPENDS native-widl)\r
+       set_source_files_properties(\r
+           ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c\r
+           PROPERTIES GENERATED TRUE)\r
+        \r
+        add_library(${TARGET}_proxy ${SOURCE})\r
+        add_dependencies(${TARGET}_proxy psdk ${PROXY_DEPENDS})\r
+endmacro(rpcproxy)\r
+\r
+macro (MACRO_IDL_FILES)\r
+    custom_incdefs()\r
+    foreach(_in_FILE ${ARGN})\r
+        get_filename_component(FILE ${_in_FILE} NAME_WE)\r
+        add_custom_command(\r
+            OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c\r
+            COMMAND native-widl ${result_incs} ${result_defs} -m32 --win32 -h -H ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h -s -S ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl\r
+            DEPENDS native-widl)\r
+        set_source_files_properties(\r
+            ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c\r
+            PROPERTIES GENERATED TRUE)\r
+        add_library(${FILE}_server ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c)\r
+        add_dependencies(${FILE}_server psdk)\r
+    \r
+        add_custom_command(\r
+            OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c\r
+            COMMAND native-widl ${result_incs} ${result_defs} -m32 --win32 -h -H ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h -c -C ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl\r
+            DEPENDS native-widl)\r
+        set_source_files_properties(\r
+            ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c\r
+            PROPERTIES GENERATED TRUE)\r
+        add_library(${FILE}_client ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c)\r
+        add_dependencies(${FILE}_client psdk)\r
+    endforeach(_in_FILE ${ARGN})\r
+\r
+endmacro (MACRO_IDL_FILES)\r