Skip to content

Commit

Permalink
Merge branch 'issue1251' into issue1243
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Oct 28, 2024
2 parents 4c093e1 + 89d8eda commit 858f45f
Show file tree
Hide file tree
Showing 188 changed files with 433 additions and 315 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "Minimum OS X deployment vers

set(PROJECT_NAME libCellML)
set(PROJECT_URL https://libcellml.org)
set(_PROJECT_VERSION 0.6.0)
set(PROJECT_DEVELOPER_VERSION )
set(_PROJECT_VERSION 0.6.1)
set(PROJECT_DEVELOPER_VERSION -rc.1)
project(${PROJECT_NAME} VERSION ${_PROJECT_VERSION} LANGUAGES CXX)

# Set policies that affect the build.
Expand Down
88 changes: 88 additions & 0 deletions cmake/TestLibXml2ConstErrorStructuredErrorCallback.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Function: Test_LibXml2_Const_Error_Structured_Error_Callback
#
# Test if LibXml2 uses const Error * for structured error callback function.
#
# CONST_ERROR_STRUCTURED_ERROR_CALLBACK - true if const Error * is required
# for structuredErrorCallback.
#

function(Test_LibXml2_Const_Error_Structured_Error_Callback)
set(_VAR_NAME "CONST_ERROR_STRUCTURED_ERROR_CALLBACK")
set(_HASH_VAR_NAME "HASH_${_VAR_NAME}")

# Hash the CMAKE_FLAGS passed and check cache to know if we need to rerun.
string(MD5 _CMAKE_FLAGS_HASH "${CMAKE_SHARED_LINKER_FLAGS}")

if(NOT DEFINED "${_HASH_VAR_NAME}")
unset("${_VAR_NAME}" CACHE)
elseif(NOT "${${_HASH_VAR_NAME}}" STREQUAL "${_CMAKE_FLAGS_HASH}")
unset("${_VAR_NAME}" CACHE)
endif()

if(NOT DEFINED "${_VAR_NAME}")
message(STATUS "Performing Test ${_VAR_NAME} - ...")
set(_TEST_PROJECT_DIR "${PROJECT_BINARY_DIR}/CMakeTmp/${_VAR_NAME}")

file(WRITE "${_TEST_PROJECT_DIR}/CMakeLists.txt"
"
cmake_minimum_required(VERSION 3.18.0)
project(undefined CXX)
add_library(foo SHARED \"foo.cpp\")
")
if(HAVE_LIBXML2_CONFIG)
file(APPEND "${_TEST_PROJECT_DIR}/CMakeLists.txt"
"
set(LibXml2_DIR \"${LibXml2_DIR}\")
find_package(LibXml2 CONFIG)
target_link_libraries(foo PUBLIC ${LIBXML2_TARGET_NAME})
")
else()
file(APPEND "${_TEST_PROJECT_DIR}/CMakeLists.txt"
"
find_package(LibXml2)
target_include_directories(foo PUBLIC ${LIBXML2_INCLUDE_DIR})
target_link_libraries(foo PUBLIC ${LIBXML2_LIBRARIES})
target_compile_definitions(foo PUBLIC ${LIBXML2_DEFINITIONS})
")
endif()

file(WRITE "${_TEST_PROJECT_DIR}/foo.cpp"
"
#include <libxml/tree.h>
#include <libxml/xmlerror.h>
void structuredErrorCallback(void *userData, const xmlError *error)
{
}
void function()
{
xmlInitParser();
xmlParserCtxtPtr context = xmlNewParserCtxt();
xmlSetStructuredErrorFunc(context, structuredErrorCallback);
xmlFreeParserCtxt(context);
xmlSetStructuredErrorFunc(nullptr, nullptr);
xmlCleanupParser();
}
")

try_compile(${_VAR_NAME}
"${_TEST_PROJECT_DIR}"
"${_TEST_PROJECT_DIR}"
undefined
CMAKE_FLAGS
"-DCMAKE_SHARED_LINKER_FLAGS='${CMAKE_SHARED_LINKER_FLAGS}'"
OUTPUT_VARIABLE _OUTPUT)

set(${_HASH_VAR_NAME} "${_CMAKE_FLAGS_HASH}" CACHE INTERNAL "Hashed try_compile flags.")

if(${_VAR_NAME})
message(STATUS "Performing Test ${_VAR_NAME} - Success")
else()
message(STATUS "Performing Test ${_VAR_NAME} - Failed")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Performing Test ${_VAR_NAME} failed with the following output:\n"
"${_OUTPUT}\n")
endif()
endif()
endfunction()
25 changes: 12 additions & 13 deletions cmake/TestUndefinedSymbolsAllowed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,34 @@
# Test if the linker allows undefined symbols for shared libraries.
#
# UNDEFINED_SYMBOLS_ALLOWED - true if the linker will allow
# undefined symbols for shared libraries
# undefined symbols for shared libraries.
#

function(Test_Undefined_Symbols_Allowed)

set(_VAR_NAME "UNDEFINED_SYMBOLS_ALLOWED")
set(_HASH_VAR_NAME "HASH_${_VAR_NAME}")

# hash the CMAKE_FLAGS passed and check cache to know if we need to rerun
string(MD5 cmake_flags_hash "${CMAKE_SHARED_LINKER_FLAGS}")
# Hash the CMAKE_FLAGS passed and check cache to know if we need to rerun.
string(MD5 _CMAKE_FLAGS_HASH "${CMAKE_SHARED_LINKER_FLAGS}")

if(NOT DEFINED "${_HASH_VAR_NAME}")
unset("${_VAR_NAME}" CACHE)
elseif(NOT "${${_HASH_VAR_NAME}}" STREQUAL "${cmake_flags_hash}")
elseif(NOT "${${_HASH_VAR_NAME}}" STREQUAL "${_CMAKE_FLAGS_HASH}")
unset("${_VAR_NAME}" CACHE)
endif()

if(NOT DEFINED "${_VAR_NAME}")
message(STATUS "Performing Test ${_VAR_NAME} - ...")
set(test_project_dir "${PROJECT_BINARY_DIR}/CMakeTmp/${_VAR_NAME}")
set(_TEST_PROJECT_DIR "${PROJECT_BINARY_DIR}/CMakeTmp/${_VAR_NAME}")

file(WRITE "${test_project_dir}/CMakeLists.txt"
file(WRITE "${_TEST_PROJECT_DIR}/CMakeLists.txt"
"
cmake_minimum_required(VERSION 3.18.0)
project(undefined CXX)
add_library(foo SHARED \"foo.cpp\")
")

file(WRITE "${test_project_dir}/foo.cpp"
file(WRITE "${_TEST_PROJECT_DIR}/foo.cpp"
"
extern int bar(void);
int foo(void) {return bar()+1;}
Expand All @@ -44,23 +43,23 @@ int foo(void) {return bar()+1;}
endif()

try_compile(${_VAR_NAME}
"${test_project_dir}"
"${test_project_dir}"
"${_TEST_PROJECT_DIR}"
"${_TEST_PROJECT_DIR}"
undefined
CMAKE_FLAGS
"-DCMAKE_SHARED_LINKER_FLAGS='${CMAKE_SHARED_LINKER_FLAGS}'"
${_rpath_arg}
OUTPUT_ _VAR_NAME output)
OUTPUT_VARIABLE _OUTPUT)

set(${_HASH_VAR_NAME} "${cmake_flags_hash}" CACHE INTERNAL "hashed try_compile flags")
set(${_HASH_VAR_NAME} "${_CMAKE_FLAGS_HASH}" CACHE INTERNAL "hashed try_compile flags")

if(${_VAR_NAME})
message(STATUS "Performing Test ${_VAR_NAME} - Success")
else()
message(STATUS "Performing Test ${_VAR_NAME} - Failed")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Performing Test ${_VAR_NAME} failed with the following output:\n"
"${OUTPUT}\n")
"${_OUTPUT}\n")
endif()
endif()
endfunction()
25 changes: 25 additions & 0 deletions cmake/environmentchecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

include(CheckCXXCompilerFlag)
include(TestUndefinedSymbolsAllowed)
include(TestLibXml2ConstErrorStructuredErrorCallback)

get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)

Expand Down Expand Up @@ -132,6 +133,7 @@ if(LibXml2_FOUND)
endif()
else()
find_package(ZLIB REQUIRED)
set(_ZLIB_FIND_REPORTED TRUE CACHE INTERNAL "Flag for reporting on what ZLIB was found.")
endif()
endif()
set(HAVE_LIBXML2_CONFIG TRUE)
Expand All @@ -156,18 +158,33 @@ if(LibXml2_FOUND)
endforeach()
else()
find_package(LibXml2 REQUIRED)
set(_LibXml2_FIND_REPORTED TRUE CACHE INTERNAL "Flag for reporting on what LibXml2 was found.")
if(TARGET z)
set(HAVE_ZLIB_TARGET TRUE)
get_target_property(ZLIB_TARGET_TYPE z TYPE)
else()
find_package(ZLIB REQUIRED)
set(_ZLIB_FIND_REPORTED TRUE CACHE INTERNAL "Flag for reporting on what ZLIB was found.")
endif()
if(LibXml2_FOUND)
# Clear out GUI variable created in config search mode.
unset(LibXml2_DIR CACHE)
endif()
endif()

if(NOT DEFINED _LibXml2_FIND_REPORTED)
set(_LibXml2_FIND_REPORTED TRUE CACHE INTERNAL "Flag for reporting on what LibXml2 was found.")
message(STATUS "Found LibXml2: ${LIBXML2_LIBRARIES} (found version \"${LIBXML2_VERSION_STRING}\").")
endif()

if(NOT DEFINED _ZLIB_FIND_REPORTED)
set(_ZLIB_FIND_REPORTED TRUE CACHE INTERNAL "Flag for reporting on what ZLIB was found.")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.26)
set(ZLIB_VERSION_STRING ${ZLIB_VERSION})
endif()
message(STATUS "Found ZLIB: ${ZLIB_LIBRARIES} (found version \"${ZLIB_VERSION_STRING}\").")
endif()

if(BUILDCACHE_EXE OR CLCACHE_EXE OR CCACHE_EXE)
set(COMPILER_CACHE_AVAILABLE TRUE CACHE INTERNAL "Executable required to cache compilations.")
endif()
Expand Down Expand Up @@ -240,3 +257,11 @@ endif()
if(EMSCRIPTEN AND NODE_EXE AND NPM_EXE)
set(JAVASCRIPT_BINDINGS_TESTING_AVAILABLE TRUE CACHE INTERNAL "Executables required to run the javascript bindings tests are available.")
endif()

test_libxml2_const_error_structured_error_callback()

if(CONST_ERROR_STRUCTURED_ERROR_CALLBACK)
set(CONST_ERROR_STRUCTURED_ERROR_CALLBACK_TYPE "const xmlError *")
else()
set(CONST_ERROR_STRUCTURED_ERROR_CALLBACK_TYPE "xmlErrorPtr")
endif()
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ add_library(cellml
${API_HEADER_FILES}
)

set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/xmldoc.cpp PROPERTIES
COMPILE_DEFINITIONS XML_ERROR_CALLBACK_ARGUMENT_TYPE=${CONST_ERROR_STRUCTURED_ERROR_CALLBACK_TYPE})

generate_export_header(cellml EXPORT_FILE_NAME ${LIBCELLML_EXPORTDEFINITIONS_H} BASE_NAME LIBCELLML)

target_include_directories(cellml
Expand Down
2 changes: 1 addition & 1 deletion src/xmldoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace libcellml {
*
* @param error The @c xmlErrorPtr to the error raised by libxml.
*/
void structuredErrorCallback(void *userData, xmlErrorPtr error)
void structuredErrorCallback(void *userData, XML_ERROR_CALLBACK_ARGUMENT_TYPE error)
{
static const std::regex newLineRegex("\\n");
// Swap libxml2 carriage return for a period.
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings/javascript/version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ describe("Version tests", () => {
libcellml = await libCellMLModule();
});
test('Checking version string.', () => {
expect(libcellml.versionString()).toBe('0.6.0');
expect(libcellml.versionString()).toBe('0.6.1');
});
})
2 changes: 1 addition & 1 deletion tests/parser/libxml_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License.

#include <libxml/parser.h>

void structuredErrorCallback(void *userData, xmlErrorPtr error)
void structuredErrorCallback(void *userData, XML_ERROR_CALLBACK_ARGUMENT_TYPE error)
{
if (userData != nullptr && error != nullptr) {
// Suppress any error messages raised from using LibXml2.
Expand Down
3 changes: 3 additions & 0 deletions tests/parser/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ set(${CURRENT_TEST}_SRCS
#set(${CURRENT_TEST}_HDRS
# ${CMAKE_CURRENT_LIST_DIR}/<test_header_files.h>
#)

set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/libxml_user.cpp PROPERTIES
COMPILE_DEFINITIONS XML_ERROR_CALLBACK_ARGUMENT_TYPE=${CONST_ERROR_STRUCTURED_ERROR_CALLBACK_TYPE})
4 changes: 2 additions & 2 deletions tests/resources/coverage/generator/model.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* The content of this file was generated using the C profile of libCellML 0.6.0. */
/* The content of this file was generated using the C profile of libCellML 0.6.1. */

#include "model.h"

#include <math.h>
#include <stdlib.h>

const char VERSION[] = "0.6.0";
const char LIBCELLML_VERSION[] = "0.6.0";
const char LIBCELLML_VERSION[] = "0.6.1";

const size_t STATE_COUNT = 1;
const size_t CONSTANT_COUNT = 7;
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/coverage/generator/model.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* The content of this file was generated using the C profile of libCellML 0.6.0. */
/* The content of this file was generated using the C profile of libCellML 0.6.1. */

#pragma once

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */
/* The content of this file was generated using a modified C profile of libCellML 0.6.1. */

double xor(double x, double y)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/coverage/generator/model.interface.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */
/* The content of this file was generated using a modified C profile of libCellML 0.6.1. */

#pragma once

Expand Down
4 changes: 2 additions & 2 deletions tests/resources/coverage/generator/model.modified.profile.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */
/* The content of this file was generated using a modified C profile of libCellML 0.6.1. */

#include "model.h"

#include <math.h>
#include <stdlib.h>

const char VERSION[] = "0.6.0.post0";
const char LIBCELLML_VERSION[] = "0.6.0";
const char LIBCELLML_VERSION[] = "0.6.1";

const size_t STATE_COUNT = 1;
const size_t CONSTANT_COUNT = 7;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */
/* The content of this file was generated using a modified C profile of libCellML 0.6.1. */

#pragma once

Expand Down
4 changes: 2 additions & 2 deletions tests/resources/coverage/generator/model.modified.profile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# The content of this file was generated using a modified Python profile of libCellML 0.6.0.
# The content of this file was generated using a modified Python profile of libCellML 0.6.1.

from enum import Enum
from math import *


__version__ = "0.5.0.post0"
LIBCELLML_VERSION = "0.6.0"
LIBCELLML_VERSION = "0.6.1"

STATE_COUNT = 1
CONSTANT_COUNT = 7
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/coverage/generator/model.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* The content of this file was generated using a modified C profile of libCellML 0.6.0. */
/* The content of this file was generated using a modified C profile of libCellML 0.6.1. */

#include "customheaderfile.h"

Expand Down
4 changes: 2 additions & 2 deletions tests/resources/coverage/generator/model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# The content of this file was generated using the Python profile of libCellML 0.6.0.
# The content of this file was generated using the Python profile of libCellML 0.6.1.

from enum import Enum
from math import *


__version__ = "0.5.0"
LIBCELLML_VERSION = "0.6.0"
LIBCELLML_VERSION = "0.6.1"

STATE_COUNT = 1
CONSTANT_COUNT = 7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* The content of this file was generated using the C profile of libCellML 0.6.0. */
/* The content of this file was generated using the C profile of libCellML 0.6.1. */

#include "model.h"

#include <math.h>
#include <stdlib.h>

const char VERSION[] = "0.6.0";
const char LIBCELLML_VERSION[] = "0.6.0";
const char LIBCELLML_VERSION[] = "0.6.1";

const size_t CONSTANT_COUNT = 0;
const size_t COMPUTED_CONSTANT_COUNT = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* The content of this file was generated using the C profile of libCellML 0.6.0. */
/* The content of this file was generated using the C profile of libCellML 0.6.1. */

#include "model.external.h"

#include <math.h>
#include <stdlib.h>

const char VERSION[] = "0.6.0";
const char LIBCELLML_VERSION[] = "0.6.0";
const char LIBCELLML_VERSION[] = "0.6.1";

const size_t CONSTANT_COUNT = 0;
const size_t COMPUTED_CONSTANT_COUNT = 0;
Expand Down
Loading

0 comments on commit 858f45f

Please sign in to comment.