I am Charmie

メモとログ

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

[code lang="bash"]

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() [/code]