mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-24 22:58:13 +00:00
Correctly search for libxsd and use python script instead of CMake custom target to generate XSD code.
This commit is contained in:
parent
53b9758d7a
commit
e5444986c9
3 changed files with 93 additions and 53 deletions
|
|
@ -22,36 +22,27 @@
|
|||
#
|
||||
# - Find the libxsd library
|
||||
#
|
||||
# XSD_FOUND - system has libxsd
|
||||
# XSD_LIBRARIES - The libraries needed to use libxsd
|
||||
# LIBXSD_FOUND - system has libxsd
|
||||
# LIBXSD_INCLUDE_DIRS - the libxsd include directory
|
||||
# LIBXSD_LIBRARIES - The libraries needed to use libxsd
|
||||
|
||||
if(APPLE)
|
||||
set(XSDCXX_DEFAULT_ROOT_PATH "/usr/local")
|
||||
else ()
|
||||
set(XSDCXX_DEFAULT_ROOT_PATH "/usr")
|
||||
endif()
|
||||
|
||||
set(XSDCXX_ROOT_PATH ${XSDCXX_DEFAULT_ROOT_PATH} CACHE STRING "Path of where the bin/xsdcxx executable will be found. Comes from http://www.codesynthesis.com/products/xsd/download.xhtml. On mac use 'brew install xsd'")
|
||||
find_package(XercesC)
|
||||
|
||||
find_program(XSDCXX_PROG NAMES "xsdcxx" "xsd"
|
||||
HINTS ${XSDCXX_ROOT_PATH}/bin
|
||||
find_path(LIBXSD_INCLUDE_DIRS
|
||||
NAMES xsd/cxx/config.hxx
|
||||
PATH_SUFFIXES include
|
||||
)
|
||||
if(XSDCXX_PROG)
|
||||
set(XSD_FOUND 1)
|
||||
message(STATUS "XSD found at ${XSDCXX_PROG}, enabling XSD")
|
||||
# TODO: check XSD is the correct executable
|
||||
find_library(XERCES_LIBS NAMES xerces-c)
|
||||
if(NOT XERCES_LIBS)
|
||||
message(FATAL_ERROR "Failed to find the Xerces library.")
|
||||
endif()
|
||||
find_path(XERCES_INCLUDE_DIRS NAMES xercesc/util/XercesDefs.hpp)
|
||||
if(NOT XERCES_INCLUDE_DIRS)
|
||||
message(FATAL_ERROR "Failed to find the Xerces includes.")
|
||||
endif()
|
||||
set(XSD_LIBRARIES ${XERCES_LIBS})
|
||||
else()
|
||||
set(XSD_FOUND 0)
|
||||
message(STATUS "Program 'xsdcxx' could not be found in ${XSDCXX_ROOT_PATH}/bin, disabling XSD features")
|
||||
endif()
|
||||
|
||||
mark_as_advanced(XSD_FOUND)
|
||||
if(LIBXSD_INCLUDE_DIRS)
|
||||
list(APPEND LIBXSD_INCLUDE_DIRS ${XercesC_INCLUDE_DIRS})
|
||||
endif()
|
||||
set(LIBXSD_LIBRARIES ${XercesC_LIBRARIES})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(LibXsd
|
||||
DEFAULT_MSG
|
||||
LIBXSD_INCLUDE_DIRS LIBXSD_LIBRARIES
|
||||
)
|
||||
|
||||
mark_as_advanced(LIBXSD_INCLUDE_DIRS LIBXSD_LIBRARIES)
|
||||
|
|
|
|||
|
|
@ -160,31 +160,6 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
|
|||
xml/xml.cpp
|
||||
)
|
||||
|
||||
function(ADD_XSD_WRAPPERS file _comment)
|
||||
set(destinations ${CMAKE_CURRENT_BINARY_DIR}/xml/${file}.hxx ${CMAKE_CURRENT_BINARY_DIR}/xml/${file}.cxx)
|
||||
set(source ${CMAKE_CURRENT_LIST_DIR}/xml/${file}.xsd)
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/xml")
|
||||
|
||||
set(regex "%http://.+/(.+)%\\\$$1%")
|
||||
|
||||
add_custom_command(OUTPUT ${destinations}
|
||||
COMMAND "${XSDCXX_PROG}" "cxx-tree" "--generate-wildcard"
|
||||
"--generate-serialization" "--generate-ostream"
|
||||
"--generate-detach" "--std" "c++11" "--type-naming" "java"
|
||||
"--function-naming" "java" "--location-regex-trace" "--show-sloc"
|
||||
"--location-regex" "\"${regex}\""
|
||||
"--output-dir" "${CMAKE_CURRENT_BINARY_DIR}/xml" "${source}"
|
||||
COMMENT "${_comment}")
|
||||
|
||||
add_custom_target(${file} DEPENDS ${destinations} SOURCES ${source})
|
||||
|
||||
set_source_files_properties(${destinations} PROPERTIES GENERATED ON)
|
||||
set(FLEXISIP_SOURCES ${FLEXISIP_SOURCES} ${destinations} PARENT_SCOPE)
|
||||
endfunction()
|
||||
ADD_XSD_WRAPPERS(xml "XML XSD - xml.xsd")
|
||||
ADD_XSD_WRAPPERS(conference-info "Conference info XSD - conference-info.xsd")
|
||||
ADD_XSD_WRAPPERS(resource-lists "Resourece lists XSD - resource-lists.xsd")
|
||||
|
||||
set(LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${BELR_INCLUDE_DIRS} ${LIBXSD_INCLUDE_DIRS})
|
||||
set(LINPHONE_CXX_OBJECTS_DEFINITIONS "-DLIBLINPHONE_EXPORTS")
|
||||
set(LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${BELR_INCLUDE_DIRS})
|
||||
|
|
|
|||
74
src/xml/generate.py
Executable file
74
src/xml/generate.py
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Copyright (C) 2014 Belledonne Communications SARL
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
|
||||
from distutils.spawn import find_executable
|
||||
import os
|
||||
import sys
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
|
||||
def find_xsdcxx():
|
||||
xsdcxx = find_executable("xsdcxx")
|
||||
if xsdcxx is not None:
|
||||
return xsdcxx
|
||||
xsdcxx = find_executable("xsd")
|
||||
return xsdcxx
|
||||
|
||||
def generate(name):
|
||||
xsdcxx = find_xsdcxx()
|
||||
if xsdcxx is None:
|
||||
print("Cannot find xsdcxx (or xsd) program in the PATH")
|
||||
return -1
|
||||
print("Using " + xsdcxx)
|
||||
cwd = os.getcwd()
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
source_file = name + ".xsd"
|
||||
print("Generating code from " + source_file)
|
||||
source_file = os.path.join("xml", source_file)
|
||||
work_dir = os.path.join(script_dir, "..")
|
||||
os.chdir(work_dir)
|
||||
p = Popen([xsdcxx,
|
||||
"cxx-tree",
|
||||
"--generate-wildcard",
|
||||
"--generate-serialization",
|
||||
"--generate-ostream",
|
||||
"--generate-detach",
|
||||
"--std", "c++11",
|
||||
"--type-naming", "java",
|
||||
"--function-naming", "java",
|
||||
"--location-regex-trace",
|
||||
"--show-sloc",
|
||||
"--hxx-suffix", ".h",
|
||||
"--ixx-suffix", ".h",
|
||||
"--cxx-suffix", ".cpp",
|
||||
"--location-regex", "%http://.+/(.+)%$1%",
|
||||
"--output-dir", "xml",
|
||||
source_file
|
||||
], shell=False)
|
||||
p.communicate()
|
||||
os.chdir(cwd)
|
||||
return 0
|
||||
|
||||
def main(argv = None):
|
||||
generate("xml")
|
||||
generate("conference-info")
|
||||
generate("resource-lists")
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Reference in a new issue