[xsd-users] GML Processing

Brad Howes howes at ll.mit.edu
Tue Feb 2 14:09:58 EST 2010


All,

First, a big thanks to the to Code Synthesis for their great tool, xsd. I'm working on an FAA project looking into next-generation controller displays and xsd has proved to be an incredibly useful tool for adapting a C++ program written for another project so that it can read and write XML messages from/to Apache's ActiveMQ messaging service.

The project is using GML as a container and type foundation for its XML schemas, and getting the stock 3.1.1 to build properly with xsd was a major hurdle to overcome. Following the posts from Boris and others, I have a well-commented CMakeLists.txt file that generates a dynamic library of the GML C++ classes. I have attached it for posterity and to help others out who may have to solve the same problem I did. Also attached is a FindXSD.cmake file that follows the conventions of other CMake packages to properly setup some CMake variables when working with xsd. Of course, all of this only works when using CMake.

Regards,

Brad

-- 
Brad Howes
Group 42
MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420

-------------- next part --------------
A non-text attachment was scrubbed...
Name: FindXSD.cmake
Type: application/octet-stream
Size: 2865 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20100202/a497c544/FindXSD.obj
-------------- next part --------------
# -*- Mode: CMake -*-
# 
# CMake build file for the OpenGIS GML 3.1.1 schemas.
# 

#
# Add directories to use for finding C++ include files
#
INCLUDE_DIRECTORIES( ${XSD_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )

# 
# Point to the OpenGIS GML schema directory -- files are in subdirectories
# (base, smil, etc.)
#
SET( GML_DIR "${OGC_BINDINGS_DIR}/schemas/net/opengis/gml/3.1.1" )

#
# Set common XSD options
#
SET( XSD_OPTS --generate-polymorphic
			  --generate-serialization
			  --generate-inline
			  --root-element-none
			  --disable-warning F001
			  --disable-warning B002

			  #
			  # Flatten the generated GML directory includes so that everything
			  # is found in this directory. NOTE: could cause problems if names
			  # collide, but so far so good...
			  #
			  --include-regex "'@.*/xlinks[.](.+)@xlinks.$$1'@"
			  --include-regex "'@.*/smil20[.](.+)@smil20.$$1'@"
			  --namespace-map ${GMLNS} )

#
# Build the SMIL schema files. Due to a circular-dependency in the schema
# definitions, we use the --file-per-type XSD option to generate files for each
# type found in the schema files. 
#
FILE( GLOB FILES ${GML_DIR}/smil/*.xsd )
IF( NOT FILES )
  MESSAGE( FATAL "No SMIL schema files to process" )
ENDIF( NOT FILES )

FOREACH( FILE ${FILES} )
  XSD_SCHEMA( GML_SCHEMA_SRCS ${FILE} ${XSD_OPTS} --file-per-type )
ENDFOREACH( FILE )

# 
# The following is a list of C++ source files generated by the XSD command
# using the --file-per-type option. If we were working in a temporary
# directory, we could use the FILE( GLOB ... ) CMake command to identify the
# generated files...
#
SET( SMIL_CXX accumulate.cxx additive.cxx animateColorPrototype.cxx
	 animateColorType.cxx animateMotionPrototype.cxx animateMotionType.cxx
	 animatePrototype.cxx animateType.cxx attributeType.cxx calcMode.cxx
	 fillDefaultType.cxx fillTimingAttrsType.cxx nonNegativeDecimalType.cxx
	 restartDefaultType.cxx restartTimingType.cxx setPrototype.cxx setType.cxx
	 space.cxx syncBehaviorDefaultType.cxx syncBehaviorType.cxx )

#
# Generate list of header and inline include files from the list of source
# files.
#
STRING( REPLACE "cxx" "hxx" SMIL_HXX ${SMIL_CXX} )
STRING( REPLACE "cxx" "ixx" SMIL_IXX ${SMIL_CXX} )

#
# Tell CMake that these are generated files, and that to clean this build
# directory, it must remove all of them.
#
SET( SMIL_FILES ${SMIL_CXX} ${SMIL_HXX} ${SMIL_IXX} )
SET_SOURCE_FILES_PROPERTIES( ${SMIL_FILES} PROPERTIES GENERATED TRUE )
SET_DIRECTORY_PROPERTIES( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
						  "${SMIL_FILES}" )

#
# Make the SMIL C++ files part of the GML library build
#
LIST( APPEND GML_SCHEMA_SRCS ${SMIL_CXX} )

# 
# Obtain the list of schema files for XLINK package, generate C++ files for
# them, and build.

FILE( GLOB FILES ${OGC_BINDINGS_DIR}/schemas/net/opengis/xlink/1.0.0/*.xsd )
IF( NOT FILES )
  MESSAGE( FATAL "No XLINK schema files to process" )
ENDIF( NOT FILES )

FOREACH( FILE ${FILES} )
  XSD_SCHEMA( GML_SCHEMA_SRCS ${FILE} ${XSD_OPTS} )
ENDFOREACH( FILE )

# 
# Obtain the list of schema files for GML base directory, generate C++ files
# for them, and build.
#
FILE( GLOB FILES ${GML_DIR}/base/*.xsd )
IF( NOT FILES )
  MESSAGE( FATAL "No GML schema files to process" )
ENDIF( NOT FILES )
  
FOREACH( FILE ${FILES} )
  XSD_SCHEMA( GML_SCHEMA_SRCS ${FILE} ${XSD_OPTS} )
ENDFOREACH( FILE )

#
# Generate the libGML shared library
#
ADD_LIBRARY( GML SHARED ${GML_SCHEMA_SRCS} )

#
# Add the Xerces C libraries to the link stage
#
TARGET_LINK_LIBRARIES( GML ${XERCESC_LIBRARIES} )

#
# Set the installation location for the GML library. Install also performs a
# link edit with the installation location for the RPATH.
#
INSTALL( TARGETS GML LIBRARY DESTINATION lib )


More information about the xsd-users mailing list