Proper dependency handling in Libt2n.cmake by using only one add_custom_command for...
authorKristóf Katus <kristof.katus@intra2net.com>
Thu, 25 Aug 2011 07:59:17 +0000 (09:59 +0200)
committerKristóf Katus <kristof.katus@intra2net.com>
Thu, 25 Aug 2011 07:59:17 +0000 (09:59 +0200)
examples-codegen/cmake/Libt2n.cmake

index ee0e9ef..a31edee 100644 (file)
@@ -1,4 +1,4 @@
-# Detect libt2n. Version of this file: 1.1
+# Detect libt2n. Version of this file: 1.2
 pkg_check_modules(LIBT2N REQUIRED libt2n)
 include_directories(${LIBT2N_INCLUDE_DIRS})
 link_directories(${LIBT2N_LIBRARY_DIRS})
@@ -40,42 +40,44 @@ function(setup_libt2n)
     endforeach(gcc_include_dir ${gcc_include_dirs})
 
     foreach(CMDGROUP ${ARGV})
-        message("Processing libt2n command group ${CMDGROUP}")
+        message(STATUS "Processing libt2n command group ${CMDGROUP}")
 
-        # Run each .cpp file through gccxml
+        # We are going to run each .cpp file through gccxml for the current CMDGROUP
        set(T2N_GCCXML_FILES "")
-       # string(REGEX REPLACE "\\.cpp$" ".xml" T2N_GCCXML_FILES "${${CMDGROUP}_GROUP}")
+       set(T2N_GCCXML_COMMANDS "")
         foreach(T2NFILE ${${CMDGROUP}_GROUP})
-            get_filename_component(FILE_WE ${T2NFILE} NAME_WE)
             get_filename_component(FILE_NAME ${T2NFILE} NAME)
-            message("   Processing file ${FILE_NAME}")
-           
-           add_custom_command(
-           OUTPUT ${FILE_WE}.xml
+           get_filename_component(FILE_EXT ${T2NFILE} EXT)
+           if(NOT FILE_EXT STREQUAL ".cpp")
+               message(FATAL_ERROR "   Error: ${FILE_NAME} is not a .cpp file based on its filename extension!")
+           endif()
+            message(STATUS "   Processing file ${FILE_NAME}")
+
+           # We build the commands in advance which execute gccxml on each file in the CMDGROUP
+           set(T2N_GCCXML_COMMANDS ${T2N_GCCXML_COMMANDS}
+               COMMAND ${LIBT2N_GCCXML} ${gccxml_include_dirs} ${T2NFILE} -fxml=${T2NFILE}.xml
+               )
+           # The filenames of the created intermediate gccxml files for the current CMDGROUP
+           set(T2N_GCCXML_FILES ${T2N_GCCXML_FILES} ${T2NFILE}.xml)
+        endforeach(T2NFILE ${${CMDGROUP}_GROUP})
+
+       add_custom_command(
+           OUTPUT ${CMDGROUP}_common.cpp ${CMDGROUP}_common.hxx ${CMDGROUP}_client.cpp ${CMDGROUP}_client.hxx ${CMDGROUP}_server.cpp  ${CMDGROUP}_server.hxx
+
            # Create dummy _common.hxx file
            COMMAND echo "\\#include \\\"codegen-stubhead.hxx\\\"" >${CMDGROUP}_common.hxx
            COMMAND echo "\\#include \\\"${CMDGROUP}.hxx\\\"" >>${CMDGROUP}_common.hxx
 
-           # Invoke gccxml
-           COMMAND ${LIBT2N_GCCXML} ${gccxml_include_dirs} ${T2NFILE} -fxml=${FILE_WE}.xml || rm -f ${CMDGROUP}_common.hxx
+           # Invoke gccxml on each source file in the current CMDGROUP and delete the dummy file
+           ${T2N_GCCXML_COMMANDS}
+           COMMAND rm -f ${CMDGROUP}_common.hxx
 
-           DEPENDS ${T2NFILE}
-           )
-
-           # Created intermediate gccxml filenames for current CMDGROUP
-           set(T2N_GCCXML_FILES ${T2N_GCCXML_FILES} ${FILE_WE}.xml)
-        endforeach(T2NFILE ${${CMDGROUP}_GROUP})
-        # Wait till generated gccxml files are available
-        # add_custom_target(${CMDGROUP}_gccxml_done ALL DEPENDS ???)
-message("--- ${T2N_GCCXML_FILES}  ---")
-       add_custom_command(OUTPUT ${CMDGROUP}_common.cpp ${CMDGROUP}_common.hxx ${CMDGROUP}_client.cpp ${CMDGROUP}_client.hxx ${CMDGROUP}_server.cpp  ${CMDGROUP}_server.hxx
-           # Transform xml files to real code
+           # Run the code generator on all the generated gccxml files and remove those intermediate gccxml files
            COMMAND ${LIBT2N_CODEGEN} ${CMDGROUP} ${T2N_GCCXML_FILES}
            COMMAND rm -f ${T2N_GCCXML_FILES}
 
-           DEPENDS ${T2N_GCCXML_FILES}
-           # DEPENDS ${CMDGROUP}_gccxml_done
-       )
+           DEPENDS ${${CMDGROUP}_GROUP}
+           )
 
         # Write out pkgconfig file
         configure_file(${LIBT2N_CLIENT_PCTEMPLATE} ${CMAKE_CURRENT_BINARY_DIR}/${CMDGROUP}.pc @ONLY@)
@@ -102,7 +104,6 @@ message("--- ${T2N_GCCXML_FILES}  ---")
         )
 
         # Wait till generated code is available
-        # add_custom_target(${CMDGROUP}_codegen_done ALL DEPENDS ${CMDGROUP}_common.cpp)
        add_custom_target(${CMDGROUP}_codegen_done ALL DEPENDS ${CMDGROUP}_common.cpp ${CMDGROUP}_common.hxx ${CMDGROUP}_client.cpp ${CMDGROUP}_client.hxx ${CMDGROUP}_server.cpp  ${CMDGROUP}_server.hxx)
         add_dependencies(${CMDGROUP} ${CMDGROUP}_codegen_done)
         add_dependencies(${CMDGROUP}-static ${CMDGROUP}_codegen_done)