0

CMakeLists.txt working with CodeSynthesis XSD

I made a repository that uses CodeSynthesis XSD with CMake. The CMakeLists.txt calls XSD and generates C++ classes so that we can avoid calling XSD from terminal, meaning the compilation is fully automatic. The CMakeLists.txt does

  1. find necessary packages (Xerces-C and CodeSynthesis XSD) and add include directories.
  2. make a build rule for each xsd file.
    1. make a directory for storing cxx and hxx files.
    2. run xsdcxx and store the resulting cxx and hxx files in the made directory.
    3. define compilation rules to make a library for the xsd file
# 1. find necessary packages
find_package(XercesC REQUIRED)
include_directories( ${XERCESC_INCLUDE_DIR})
find_package(XSD REQUIRED)
include_directories( ${XSD_INCLUDE_DIR} )
if(XSD_FOUND)
  # file all xsd files
  file( GLOB xsds ${CMAKE_SOURCE_DIR}/*.xsd )
  # 2. make a build rule for each xsd file
  foreach( xsd ${xsds} )
    get_filename_component(xsdName ${xsd} NAME_WE)
    set(xsdDir ${CMAKE_SOURCE_DIR}/${xsdName})
    # 2.1. make a directory for the xsd file
    file(MAKE_DIRECTORY ${xsdDir})
    include_directories( ${xsdDir} )
    # 2.2. run xsdcxx and store the resulting cxx and hxx files in the made directory
    execute_process(COMMAND ${XSD_EXECUTABLE} cxx-tree ${xsd} WORKING_DIRECTORY ${xsdDir} )
    set(PROJ_SCHEME_SOURCE  ${xsdDir}/${xsdName}.cxx)
    set(PROJ_SCHEME_INCLUDE ${xsdDir}/${xsdName}.hxx)
    # 2.3. define compilation rules to make a library for the xsd file
    add_library( ${xsdName} ${PROJ_SCHEME_SOURCE} ${PROJ_SCHEME_INCLUDE} )
    target_link_libraries( ${xsdName} ${XERCESC_LIBRARIES} )
    list(APPEND PROJ_SCHEME_NAME ${xsdName} )
    list(APPEND PROJ_INCLUDE ${PROJ_SCHEME_INCLUDE} )
    list(APPEND PROJ_SOURCE  ${PROJ_SCHEME_SOURCE} )
  endforeach()
endif()
Advertisements
0

CodeSynthesis XSD: CMake

Following the wiki, we should be able to use CodeSynthesis XSD with CMake. What the FindXSD.cmake does is that

  1. call the executable of CodeSynthesis XSD and give an .xsd file, say test.xsd, the executable.
  2. pre-defined function generates a set of .cxx and .hxx files, test.cxx and test.hxx in this case.
  3. add a rule to make a library libtest.a from the generated files.

MACRO and FUNCTION of CMake enable this procedure. Due to some unknown reasons, these FindXSD.cmake files didn’t work on my computer. So, I manually generate a set of .cxx and .hxx files and then run cmake to find XercesC and XSD, add a rule to make a library, and make a link to the library.

0

Xerces-C++ XML Parser installation

Xerces-C++ XML parser is an XML parser for C++. This library is also required for using code synthesis XSD. The library provides instruction for a href=”http://xerces.apache.org/xerces-c/install-3.html”>installation and build.

wget http://ftp.meisei-u.ac.jp/mirror/apache/dist//xerces/c/3/sources/xerces-c-3.1.1.tar.gz
tar -xvzf xerces-c-3.1.1.tar.gz
cd xerces-c-3.1.1
./configure --enable-netaccessor-curl --enable-transcoder-gnuiconv --enable-msgloader-inmemory
make 2>&1 | tee ../../XercesC3.1.1Make.log
sudo make install 2>&1 | tee ../../XercesC3.1.1MakeInstall.log
0

Expat installation

Expat is an XML parser library for C. Expat is required library for using code synthesis XSD.

wget downloads.sourceforge.net/project/expat/expat/2.1.0/expat-2.1.0.tar.gz
tar -xvzf expat-2.1.0.tar.gz
mkdir expat-2.1.0-build
cd expat-2.1.0-build
cmake ../expat-2.1.0
make 2>&1 | tee ../../Expat2.1.0Make.log
sudo make install 2>&1 | tee ../../Expat2.1.0MakeInstall.log