Codegen: Migrate from gccxml to castxml
authorLudwig Jäck <ludwig.jaeck@intra2net.com>
Fri, 31 May 2024 09:48:32 +0000 (11:48 +0200)
committerLudwig Jäck <ludwig.jaeck@intra2net.com>
Fri, 7 Jun 2024 08:01:26 +0000 (10:01 +0200)
The goal of this and following commits is to migrate the code generator
of libt2n from gccxml to castxml. This is necessary since gccxml does
not support newer gcc versions.

This commit introduces the CASTXML_CXXFLAGS for future portability.
Right now all projects depending on libt2n are compiled in 32 bit and use
the gcc 4.4.4 std library. The variable allows for project wide upgrades.

A new cmake list transform syntax replaces the old for loop because castxml
has problems parsing the old string expansion which introduced unwanted
white space and '\' concatenation characters.

codegen/Libt2n.cmake

index 4df5932..2272f12 100644 (file)
@@ -17,7 +17,7 @@ execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable libt2n_datadir libt2
                                 OUTPUT_VARIABLE LIBT2N_DATADIR
                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
 set(LIBT2N_CLIENT_PCTEMPLATE ${LIBT2N_DATADIR}/clientlib.pc.in)
-set(LIBT2N_GCCXML /usr/bin/libt2n-gccxml.sh)
+set(LIBT2N_CASTXML /usr/bin/castxml)
 
 # Basic pkgconfig settings needed for client.pc generation
 set(prefix      ${CMAKE_INSTALL_PREFIX})
@@ -40,17 +40,18 @@ function(setup_libt2n)
         DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
         PROPERTY INCLUDE_DIRECTORIES
     )
-    set(gccxml_include_dirs "")
-    foreach(gcc_include_dir ${gcc_include_dirs})
-        set(gccxml_include_dirs "${gccxml_include_dirs} -I${gcc_include_dir}")
-    endforeach(gcc_include_dir ${gcc_include_dirs})
+    list(TRANSFORM gcc_include_dirs PREPEND "-I")
+
+    if(NOT DEFINED CASTXML_CXXFLAGS)
+        set(CASTXML_CXXFLAGS --castxml-gccxml -m32 -std=gnu++98 --gcc-install-dir=/usr/lib/gcc/i686-redhat-linux/4.4.4)
+    endif(NOT DEFINED CASTXML_CXXFLAGS)
 
     foreach(CMDGROUP ${ARGV})
         message(STATUS "Processing libt2n command group ${CMDGROUP}")
 
-        # We are going to run each .cpp file through gccxml for the current CMDGROUP
-        set(T2N_GCCXML_FILES "")
-        set(T2N_GCCXML_COMMANDS "")
+        # We are going to run each .cpp file through castxml for the current CMDGROUP
+        set(T2N_CASTXML_FILES "")
+        set(T2N_CASTXML_COMMANDS "")
         foreach(T2NFILE ${${CMDGROUP}_GROUP})
             get_filename_component(FILE_NAME ${T2NFILE} NAME)
             # get_filename_component(FILE_EXT ${T2NFILE} EXT)   <-- Doesn't work for filenames with multiple dots
@@ -60,12 +61,12 @@ function(setup_libt2n)
             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
+            # We build the commands in advance which execute castxml on each file in the CMDGROUP
+            set(T2N_CASTXML_COMMANDS ${T2N_CASTXML_COMMANDS}
+                COMMAND ${LIBT2N_CASTXML} ${gcc_include_dirs} ${T2NFILE}  -o ${T2NFILE}.xml ${CASTXML_CXXFLAGS}
                 )
-            # The filenames of the created intermediate gccxml files for the current CMDGROUP
-            set(T2N_GCCXML_FILES ${T2N_GCCXML_FILES} ${T2NFILE}.xml)
+            # The filenames of the created intermediate castxml files for the current CMDGROUP
+            set(T2N_CASTXML_FILES ${T2N_CASTXML_FILES} ${T2NFILE}.xml)
         endforeach(T2NFILE ${${CMDGROUP}_GROUP})
 
         add_custom_command(
@@ -75,13 +76,13 @@ function(setup_libt2n)
             COMMAND echo "\\#include \\\"codegen-stubhead.hxx\\\"" >${CMDGROUP}_common.hxx
             COMMAND echo "\\#include \\\"${CMDGROUP}.hxx\\\"" >>${CMDGROUP}_common.hxx
 
-            # Invoke gccxml on each source file in the current CMDGROUP and delete the dummy file
-            ${T2N_GCCXML_COMMANDS}
+            # Invoke castxml on each source file in the current CMDGROUP and delete the dummy file
+            ${T2N_CASTXML_COMMANDS}
             COMMAND rm -f ${CMDGROUP}_common.hxx
 
-            # 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}
+            # Run the code generator on all the generated castxml files and remove those intermediate castxml files
+            COMMAND ${LIBT2N_CODEGEN} ${CMDGROUP} ${T2N_CASTXML_FILES}
+            COMMAND rm -f ${T2N_CASTXML_FILES}
 
             DEPENDS ${${CMDGROUP}_GROUP}
             )