Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Serialise validly named model to XML #52

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
45aaaa9
Use case: Empty, nameless model. Test fail intended.
Mar 27, 2015
9c4f117
Fixed implementation code to pass test.
Mar 27, 2015
37f2601
Enabled MSVC exceptions.
Mar 27, 2015
a357443
Renamed cellml_1_2.* to start with lowercase letter
Mar 29, 2015
2154983
Changed from using auto to explicitly stating type
Mar 29, 2015
4b12cc5
Eliminated `using namespace` as per Google style.
Mar 29, 2015
c4431f0
Made use of full stop at end of comments consistent.
Mar 29, 2015
cf391bb
Removed unneeded scope resolution.
Mar 29, 2015
89b2f09
Using `version.h`'s technique for exporting symbols
Mar 29, 2015
00e7344
Faking Cmake required version.
Mar 29, 2015
799e632
Used `sstream` instead of deprecated `strstream`.
Mar 30, 2015
54de041
Refactored common cmake settings.
Mar 30, 2015
2c6df65
Actually call the macro defined in cmake common.
Mar 30, 2015
357be47
Eliminated unused variable.
Mar 30, 2015
2461bad
Minor refactoring of Cmake: reduce duplication.
Mar 30, 2015
c5aef13
Added Cmake flag to control whether warnings=errors.
Mar 30, 2015
ce41908
Removed unneeded conditional.
Mar 30, 2015
d1cba61
Bumped required version.
Mar 30, 2015
bcbb61b
Changed include guard name convention for API headers.
Mar 30, 2015
867166b
Made condition compiler dependent.
Mar 30, 2015
7dcbb9b
Renamed Cmake macro.
Mar 30, 2015
d86fdc5
Using `CMAKE_MODULE_PATH` to specify include location.
Mar 31, 2015
b95c119
For 3rd-party code, warnings are not deemed errors.
Mar 31, 2015
7ba287a
Added and optional model name attribute.
Mar 31, 2015
25f9ce2
Serialiser uses name when serialising.
Mar 31, 2015
c3f756c
Correct conditional statement.
hsorby Mar 31, 2015
3be776a
Show how you use the CMAKE_MODULE_PATH. Set the include directories …
hsorby Mar 31, 2015
891d2a1
This is how you create a reusable function to set compiler flags per …
hsorby Mar 31, 2015
9ad1400
Merge pull request #8 from hsorby/empty-model-01
Mar 31, 2015
4017ed0
Added "AppleClang" condition for warnings-as-errors
Apr 1, 2015
307ebd6
Merge branch 'empty-model-01' into named-model-0
Apr 1, 2015
99f11b0
Forgot to commit this as part of 7ba287ab5a
Apr 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,50 @@
# See the License for the specific language governing permissions and
# limitations under the License.cmake_minimum_required (VERSION 3.1)

cmake_minimum_required (VERSION 3.1)

cmake_minimum_required(VERSION 3.2)

set(PROJECT_NAME libCellML)
project(${PROJECT_NAME} CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(common)

# Use the following variables when configuring the build from the command line to
# set the corresponding cache variables.
# TESTS ==> LIBCELLML_TESTS
set( LIBCELLML_TESTS OFF CACHE BOOL "Enable build of automated LibCellML tests." )
set(_PARAM_ANNOTATION "Enable build of automated LibCellML tests.")
set( LIBCELLML_TESTS OFF CACHE BOOL ${_PARAM_ANNOTATION} )
if( TESTS )
set( LIBCELLML_TESTS "${TESTS}" CACHE BOOL "Enable build of automated LibCellML tests." FORCE )
set( LIBCELLML_TESTS "${TESTS}" CACHE BOOL ${_PARAM_ANNOTATION} FORCE )
endif()

# WARNINGS_TREATED_AS_ERRORS ==> LIBCELLML_WARNINGS_TREATED_AS_ERRORS -- Note: This excludes third party code, where warnings are never treated as errors.
set(_PARAM_ANNOTATION "Treat warnings as errors (note: warnings in 3rd party code are never treated as errors)")
set( LIBCELLML_WARNINGS_TREATED_AS_ERRORS OFF CACHE BOOL ${_PARAM_ANNOTATION} )
if( WARNINGS_TREATED_AS_ERRORS )
set( LIBCELLML_WARNINGS_TREATED_AS_ERRORS "${WARNINGS_TREATED_AS_ERRORS}" CACHE BOOL ${_PARAM_ANNOTATION} FORCE )
endif()

# BUILD_TYPE ==> LIBCELLML_BUILD_TYPE
set( LIBCELLML_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." )
set(_PARAM_ANNOTATION "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
set( LIBCELLML_BUILD_TYPE "Release" CACHE STRING ${_PARAM_ANNOTATION} )
if( BUILD_TYPE )
set( LIBCELLML_BUILD_TYPE ${BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE )
set( LIBCELLML_BUILD_TYPE ${BUILD_TYPE} CACHE STRING ${_PARAM_ANNOTATION} FORCE )
endif()

# INSTALL_PREFIX ==> LIBCELLML_INSTALL_PREFIX
set( LIBCELLML_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "Install path prefix, prepended onto install directories." )
set(_PARAM_ANNOTATION "Install path prefix, prepended onto install directories.")
set( LIBCELLML_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING ${_PARAM_ANNOTATION} )
if( INSTALL_PREFIX )
set( LIBCELLML_INSTALL_PREFIX ${INSTALL_PREFIX} CACHE STRING "Install path prefix, prepended onto install directories." FORCE )
set( LIBCELLML_INSTALL_PREFIX ${INSTALL_PREFIX} CACHE STRING ${_PARAM_ANNOTATION} FORCE )
endif()

# BUILD_SHARED ==> LIBCELLML_BUILD_SHARED
set( LIBCELLML_BUILD_SHARED OFF CACHE BOOL "Build shared libraries (so, dylib, DLLs)." )
set(_PARAM_ANNOTATION "Build shared libraries (so, dylib, DLLs).")
set( LIBCELLML_BUILD_SHARED OFF CACHE BOOL ${_PARAM_ANNOTATION} )
if( BUILD_SHARED )
set( LIBCELLML_BUILD_SHARED ${BUILD_SHARED} CACHE BOOL "Build shared libraries (so, dylib, DLLs)." FORCE )
set( LIBCELLML_BUILD_SHARED ${BUILD_SHARED} CACHE BOOL ${_PARAM_ANNOTATION} FORCE )
endif()

# internalise some CMake variables
Expand Down
31 changes: 31 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2015 University of Auckland
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.cmake_minimum_required (VERSION 3.1)

function(TARGET_WARNINGS_AS_ERRORS _TARGET)
set(_COMPILER_WAE)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(_COMPILER_WAE -Wall -W -Werror)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(_COMPILER_WAE -Wall -W -Werror)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(_COMPILER_WAE /W3)
endif()
if(_COMPILER_WAE)
target_compile_options(${_TARGET} PRIVATE ${_COMPILER_WAE})
endif()
unset(_COMPILER_WAE)
endfunction()

54 changes: 40 additions & 14 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,75 @@
# See the License for the specific language governing permissions and
# limitations under the License.cmake_minimum_required (VERSION 3.1)


set(CELLML_EXPORT_H "${CMAKE_CURRENT_BINARY_DIR}/api/libcellml/libcellml_export.h")
set(LIBCELLML_CONFIG_H "${CMAKE_CURRENT_BINARY_DIR}/libcellml_config.h")
configure_file (
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/libcellml_config.h.in"
${LIBCELLML_CONFIG_H}
)

set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/version.cpp
${CMAKE_CURRENT_SOURCE_DIR}/model.cpp
${CMAKE_CURRENT_SOURCE_DIR}/xml_serialisation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cellml_1_2.cpp
)

set(API_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/version.h
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/model.h
${CMAKE_CURRENT_SOURCE_DIR}/api/libcellml/xml_serialisation.h
${CMAKE_CURRENT_SOURCE_DIR}/cellml_1_2.h
${CELLML_EXPORT_H}
)

set(HEADER_FILES
${LIBCELLML_CONFIG_H}
)

include_directories(
${CMAKE_CURRENT_BINARY_DIR}/api
${CMAKE_CURRENT_SOURCE_DIR}/api
${CMAKE_CURRENT_BINARY_DIR}
)

include(GenerateExportHeader)

add_compiler_export_flags()

add_library(cellml
${SOURCE_FILES}
${HEADER_FILES}
${API_HEADER_FILES}
)
generate_export_header(cellml EXPORT_FILE_NAME ${CELLML_EXPORT_H} BASE_NAME LIBCELLML)

set_source_files_properties(${CELLML_EXPORT_H} PROPERTIES GENERATED TRUE)
target_include_directories(cellml PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/api
${CMAKE_CURRENT_SOURCE_DIR}/api
${CMAKE_CURRENT_SOURCE_DIR}/../extdep/libxsd
${CMAKE_CURRENT_BINARY_DIR}
)

# To work around a bug conditionally set the CXX_STANDARD property
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set_target_properties(cellml PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
if(LIBCELLML_WARNINGS_TREATED_AS_ERRORS)
target_warnings_as_errors(cellml)
endif()

generate_export_header(cellml EXPORT_FILE_NAME ${CELLML_EXPORT_H} BASE_NAME LIBCELLML)

set(XercesC_ROOT "${XercesC_ROOT}" CACHE PATH "Location of Xerces-C")
set(BOOST_ROOT "${BOOST_ROOT}" CACHE PATH "Location of Boost")

set(CMAKE_INCLUDE_PATH "${XercesC_ROOT}/include")
set(CMAKE_LIBRARY_PATH "${XercesC_ROOT}/lib")
find_package (XercesC)
if (XercesC_FOUND)
target_include_directories(cellml PRIVATE ${XercesC_INCLUDE_DIR})
target_link_libraries (cellml ${XercesC_LIBRARY})
endif (XercesC_FOUND)


find_package (Boost)
if (Boost_FOUND)
target_include_directories(cellml PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries (cellml ${Boost_LIBRARIES})
endif (Boost_FOUND)


set_source_files_properties(${CELLML_EXPORT_H} PROPERTIES GENERATED TRUE)

export(TARGETS cellml FILE libcellml-exports.cmake)

install(TARGETS cellml EXPORT libcellml-targets
Expand All @@ -71,3 +96,4 @@ install(FILES

install(EXPORT libcellml-targets DESTINATION lib/cmake)

set_target_properties(cellml PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
56 changes: 56 additions & 0 deletions src/api/libcellml/model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2015 University of Auckland

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.Some license of other
*/

#ifndef LIBCELLML_LIBCELLML_MODEL_H_
#define LIBCELLML_LIBCELLML_MODEL_H_

#include <string>
#include <boost/optional.hpp>

#include "libcellml/libcellml_export.h"

//! Everything in LibCellML is in this namespace.
namespace libcellml {

//! In-memory representation of a CellML model.
class LIBCELLML_EXPORT Model {
//! Model name
boost::optional<std::wstring> name_;

public:
/**
* Default constructor.
*/
Model();

/**
* Constructor
* \param name The model name
*/
Model(const boost::optional<std::wstring> name);

/** Model name attribute
* \return Model name
*/
boost::optional< std::wstring> getName() const {
return name_;
}

};

} // namespace libcellml

#endif // LIBCELLML_LIBCELLML_MODEL_H_
10 changes: 5 additions & 5 deletions src/api/libcellml/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.Some license of other
*/

#ifndef LIBCELLML_VERSION_H
#define LIBCELLML_VERSION_H
#ifndef LIBCELLML_LIBCELLML_VERSION_H_
#define LIBCELLML_LIBCELLML_VERSION_H_

#include <string>

Expand All @@ -28,10 +28,10 @@ namespace libcellml {
* Get the version string.
* The version string is in the format x.y.z, where the "."s are literal, and x,y and z represent counting numbers,
* in which case x is the major version, y the minor version, and z the patch level.
* @return a string to represent the version
* @return a string to represent the version.
*/
LIBCELLML_EXPORT const std::string getVersion();

} // namespace libcellml
} // namespace libcellml

#endif /* LIBCELLML_VERSION_H */
#endif // LIBCELLML_LIBCELLML_VERSION_H_
36 changes: 36 additions & 0 deletions src/api/libcellml/xml_serialisation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2015 University of Auckland

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.Some license of other
*/

#ifndef LIBCELLML_LIBCELLML_XML_SERIALISATION_H_
#define LIBCELLML_LIBCELLML_XML_SERIALISATION_H_

#include "model.h"
#include "libcellml/libcellml_export.h"

#include <string>

namespace libcellml {

/**
Serialise the Model.
\param model The model to be serialised.
\return XML representation.
*/
std::string LIBCELLML_EXPORT createXml(const Model& model);

}

#endif // LIBCELLML_LIBCELLML_XML_SERIALISATION_H_
Loading