[CMAKE]
[reactos.git] / CMakeMacros.cmake
index 5c0b50f..3d4e3a2 100644 (file)
@@ -22,7 +22,6 @@ macro(CreateBootSectorTarget _target_name _asm_file _object_file)
         DEPENDS ${_asm_file})\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()\r
 \r
 else()\r
@@ -32,55 +31,6 @@ endmacro()
 \r
 endif()\r
 \r
-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
-  \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
-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
-        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
-    if("${ARGN}" STREQUAL "")\r
-        get_target_property(FILENAME ${_targetname} LOCATION)\r
-        get_filename_component(_nameoncd ${FILENAME} NAME)\r
-    else()\r
-        set(_nameoncd ${ARGN})\r
-    endif()\r
-    \r
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_minicd_target.txt "${_targetname}\t${_dir}\t${_nameoncd}\n")\r
-endmacro()\r
-\r
-macro(add_minicd FILENAME _dir _nameoncd)\r
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_minicd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")\r
-endmacro()\r
-\r
 macro(set_cpp)\r
     include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/c++/stlport)\r
     set(IS_CPP 1)\r
@@ -89,167 +39,117 @@ macro(set_cpp)
         -DNATIVE_C_INCLUDE=${REACTOS_SOURCE_DIR}/include/crt)\r
 endmacro()\r
 \r
-macro(add_livecd_target _targetname _dir )# optional parameter : _nameoncd\r
-    if("${ARGN}" STREQUAL "")\r
-        get_target_property(FILENAME ${_targetname} LOCATION)\r
-        get_filename_component(_nameoncd ${FILENAME} NAME)\r
-    else()\r
-        set(_nameoncd ${ARGN})\r
-    endif()\r
-    \r
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd_target.txt "${_targetname}\t${_dir}\t${_nameoncd}\n")\r
+macro(add_dependency_node _node)\r
+    if(GENERATE_DEPENDENCY_GRAPH)\r
+        get_target_property(_type ${_node} TYPE)\r
+        if(_type MATCHES SHARED_LIBRARY)\r
+            file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "    <node id=\"${_node}\"/>\n")\r
+        endif()\r
+     endif()\r
 endmacro()\r
 \r
-macro(add_livecd FILENAME _dir)# optional parameter : _nameoncd\r
-    if("${ARGN}" STREQUAL "")\r
-        get_filename_component(_nameoncd ${FILENAME} NAME)\r
-    else()\r
-        set(_nameoncd ${ARGN})\r
+macro(add_dependency_edge _source _target)\r
+    if(GENERATE_DEPENDENCY_GRAPH)\r
+        get_target_property(_type ${_source} TYPE)\r
+        if(_type MATCHES SHARED_LIBRARY)\r
+            file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "    <edge source=\"${_source}\" target=\"${_target}\"/>\n")\r
+        endif()\r
     endif()\r
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")\r
 endmacro()\r
 \r
-macro(cab_to_dir _dir_num _var_name)\r
-#   1 = system32\r
-#   2 = system32\drivers\r
-#   3 = Fonts\r
-#   4 =\r
-#   5 = system32\drivers\etc\r
-#   6 = inf\r
-#   7 = bin\r
-#   8 = media\r
-    if(${_dir_num} STREQUAL "1")\r
-        set(${_var_name} "reactos/system32")\r
-    elseif(${_dir_num} STREQUAL "2")\r
-        set(${_var_name} "reactos/system32/drivers")\r
-    elseif(${_dir_num} STREQUAL "3")\r
-        set(${_var_name} "reactos/fonts")\r
-    elseif(${_dir_num} STREQUAL "4")\r
-        set(${_var_name} "reactos")\r
-    elseif(${_dir_num} STREQUAL "5")\r
-        set(${_var_name} "reactos/system32/drivers/etc")\r
-    elseif(${_dir_num} STREQUAL "6")\r
-        set(${_var_name} "reactos/inf")\r
-    elseif(${_dir_num} STREQUAL "7")\r
-        set(${_var_name} "reactos/bin")\r
-    elseif(${_dir_num} STREQUAL "8")\r
-        set(${_var_name} "reactos/system32/drivers")\r
-    else()\r
-        message(FATAL_ERROR "Wrong directory ${_dir_num}")\r
-    endif()\r
-endmacro()\r
-\r
-macro(add_cab_target _targetname _num )\r
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab_target.txt "${_targetname}\t${_num}\n")\r
-    cab_to_dir(${_num} _dir)\r
-    add_livecd_target(${_targetname} ${_dir})\r
-endmacro()\r
-\r
-macro(add_cab FILENAME _num)\r
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab.txt "${FILENAME}\t${_num}\n")\r
-    cab_to_dir(${_num} _dir)\r
-    add_livecd(${FILENAME} ${_dir})\r
-endmacro()    \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()\r
-\r
-        foreach(arg ${rpc_includes})\r
-            set(result_incs -I${arg} ${result_incs})\r
-        endforeach()\r
-    endif()\r
+macro(add_dependency_header)\r
+    file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n  <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")\r
+    add_dependency_node(ntdll)\r
 endmacro()\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 ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.h ${IDL_PROXY_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl\r
-            DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl)\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()\r
-\r
-    add_custom_command(\r
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c\r
-        COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_DLLDATA_ARG}${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c ${IDLS}\r
-        DEPENDS ${IDLS})\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
+macro(add_dependency_footer)\r
+    file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "  </graph>\n</graphml>\n")\r
 endmacro()\r
 \r
-macro(idl_files)\r
-    custom_incdefs()\r
+macro(add_message_headers)\r
     foreach(_in_FILE ${ARGN})\r
         get_filename_component(FILE ${_in_FILE} NAME_WE)\r
+        macro_mc(${FILE})\r
         add_custom_command(\r
-            OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c\r
-            COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${IDL_SERVER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl\r
-            DEPENDS ${_in_file})\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 ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${IDL_CLIENT_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl\r
-            DEPENDS ${_in_file})\r
+            OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h\r
+            COMMAND ${COMMAND_MC}\r
+            DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)\r
         set_source_files_properties(\r
-            ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c\r
+            ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc\r
             PROPERTIES GENERATED TRUE)\r
-        add_library(${FILE}_client ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c)\r
-        add_dependencies(${FILE}_client psdk)\r
+        add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc)\r
     endforeach()\r
 endmacro()\r
 \r
-macro(add_typelib TARGET)\r
-    custom_incdefs()\r
-    foreach(SOURCE ${ARGN})\r
-        get_filename_component(FILE ${SOURCE} NAME_WE)\r
-        set(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb)\r
-        add_custom_command(\r
-            OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb\r
-            COMMAND ${IDL_COMPILER} ${result_incs} ${IDL_FLAGS} ${IDL_TYPELIB_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}\r
-            DEPENDS ${SOURCE})\r
-        list(APPEND OBJECTS ${OBJECT})\r
-    endforeach()\r
-    add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})\r
+macro(dir_to_num dir var)\r
+    if(${dir} STREQUAL reactos/system32)\r
+        set(${var} 1)\r
+    elseif(${dir} STREQUAL reactos/system32/drivers)\r
+        set(${var} 2)\r
+    elseif(${dir} STREQUAL reactos/Fonts)\r
+        set(${var} 3)\r
+    elseif(${dir} STREQUAL reactos)\r
+        set(${var} 4)\r
+    elseif(${dir} STREQUAL reactos/system32/drivers/etc)\r
+        set(${var} 5)\r
+    elseif(${dir} STREQUAL reactos/inf)\r
+        set(${var} 6)\r
+    elseif(${dir} STREQUAL reactos/bin)\r
+        set(${var} 7)\r
+    elseif(${dir} STREQUAL reactos/media)\r
+        set(${var} 8)\r
+    else()\r
+        message(ERROR "Wrong destination: ${dir}")\r
+    endif()\r
 endmacro()\r
 \r
-macro(add_idl_interface IDL_FILE)\r
-    custom_incdefs()\r
-    if(ARCH MATCHES i386)\r
-        set(platform_flags "-m32 --win32")\r
-    elseif(ARCH MATCHES amd64)\r
-        set(platform_flags "-m64 --win64")\r
+function(add_cd_file)\r
+    cmake_parse_arguments(_CD "NO_CAB;NO_LIVECD" "DESTINATION;NAME_ON_CD;TARGET" "FILE" ${ARGN})\r
+    if(NOT (_CD_TARGET OR _CD_FILE))\r
+        message(FATAL_ERROR "You must provide a target or a file to install!")\r
     endif()\r
-    get_filename_component(FILE ${IDL_FILE} NAME_WE)\r
-    add_custom_command(\r
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_i.c\r
-        COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${platform_flags} -u -U ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_i.c ${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}\r
-        DEPENDS ${IDL_FILE})\r
-    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${FILE}_i.c PROPERTIES GENERATED TRUE)\r
-endmacro()\r
+    \r
+    if(NOT _CD_DESTINATION)\r
+        message(FATAL_ERROR "You must provide a destination")\r
+    elseif(${_CD_DESTINATION} STREQUAL root)\r
+        set(_CD_DESTINATION "")\r
+    endif()\r
+    \r
+    if(NOT _CD_FILE)\r
+        get_target_property(__file ${_CD_TARGET} LOCATION)\r
+    else()\r
+        if(NOT _CD_NO_CAB)\r
+            add_dependencies(reactos_cab ${_CD_FILE})\r
+        endif()\r
+        set(__file ${_CD_FILE})\r
+    endif()\r
+    #whether or not we should put it in reactos.cab or directly on cd\r
+    if(_CD_NO_CAB)\r
+        foreach(item ${__file})\r
+            file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")\r
+        endforeach()\r
+        if(_CD_NAME_ON_CD)\r
+            get_filename_component(__file ${__file} NAME)\r
+            #rename it in the cd tree\r
+            file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")\r
+        endif()\r
+        #add right dependency\r
+        if(_CD_TARGET)\r
+            add_dependencies(bootcd ${_CD_TARGET})\r
+        else()\r
+            add_dependencies(bootcd ${_CD_FILE})\r
+        endif()\r
+        if(NOT _CD_NO_LIVECD)\r
+            file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${__file}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")\r
+        endif()\r
+    else()\r
+        #add right dependency\r
+        if(_CD_TARGET)\r
+            add_dependencies(reactos_cab ${_CD_TARGET})\r
+        else()\r
+            add_dependencies(reactos_cab ${_CD_FILE})\r
+        endif()\r
+        dir_to_num(${_CD_DESTINATION} _num)\r
+        file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${__file} ${_num}\n")\r
+    endif()\r
+endfunction()\r