[SCons] Do not build both clibs

This commit is contained in:
Ingmar Schoegl
2025-06-04 13:24:20 -05:00
parent d4c5f43ce2
commit 0430b80477
11 changed files with 86 additions and 28 deletions
+2 -2
View File
@@ -8,8 +8,8 @@
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
#ifndef CTC_DEFS_H
#define CTC_DEFS_H
#ifndef __CLIB_DEFS_H__
#define __CLIB_DEFS_H__ // use same guards as clib_experimental
#include "cantera/base/config.h"
#include <stdlib.h>
+2 -2
View File
@@ -1,2 +1,2 @@
*.h
*.cpp
ct*.h
ct*.cpp
@@ -1,5 +1,5 @@
/**
* @file clib3_defs.h
* @file clib_defs.h
*
* @warning This module is an experimental part of the %Cantera API and
* may be changed or removed without notice.
@@ -13,8 +13,8 @@
* @brief %Cantera's experimental CLib interface.
*/
#ifndef __CLIB3_DEFS_H__
#define __CLIB3_DEFS_H__
#ifndef __CLIB_DEFS_H__
#define __CLIB_DEFS_H__
#include "cantera/base/config.h"
#include <stdlib.h>
@@ -28,13 +28,11 @@
# define DERR -999.999
#endif
// // Used by external logger
// enum LogLevel { INFO, WARN , ERROR };
// Used by external logger
enum LogLevel { INFO, WARN , ERROR };
// //! Represents a callback that is invoked to produce log output.
// //! TODO: Only needed in the main CLib library. Should be moved once the
// //! traditional CLib is removed.
// typedef void
// (*LogCallback)(enum LogLevel logLevel, const char* category, const char* message);
//! Represents a callback that is invoked to produce log output.
typedef void
(*LogCallback)(enum LogLevel logLevel, const char* category, const char* message);
#endif
@@ -0,0 +1,56 @@
/**
* @file clib_utils.h
*/
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
#ifndef __CLIB_UTILS_H__
#define __CLIB_UTILS_H__
#include "cantera/base/ctexceptions.h"
#include "cantera_clib/clib_defs.h"
#include "application.h"
#include "../clib/Cabinet.h" // File needs to be moved
#include <iostream>
namespace Cantera
{
//! Exception handler used at language interface boundaries.
/*!
* When called from a "catch (...)" block, this function will attempt to save
* an error message in global error stack and return a value indicating the
* type of exception caught.
*
* @param ctErrorCode Value to return if a CanteraError is caught
* @param otherErrorCode Value to return if a different exception is caught
*/
template <typename T>
T handleAllExceptions(T ctErrorCode, T otherErrorCode)
{
// Rethrow the previous exception, then catch a more
// specific exception type if possible.
try {
throw;
} catch (CanteraError& cterr) {
Application::Instance()->addError(cterr.what());
return ctErrorCode;
} catch (std::exception& err) {
std::cerr << "Cantera: caught an instance of "
<< err.what() << std::endl;
Application::Instance()->addError(err.what());
return otherErrorCode;
} catch (...) {
std::cerr << "Cantera: caught an instance of "
"an unknown exception type" << std::endl;
Application::Instance()->addError("unknown C++ exception");
return otherErrorCode;
}
}
}
#endif
@@ -51,7 +51,7 @@ prop_type_crosswalk:
# Cabinets with associated preambles (headers)
preambles:
"": |-
#include "cantera_clib/clib3_defs.h"
#include "cantera_clib/clib_defs.h"
#include <stdint.h> // for 32-bit int32_t / 64-bit int64_t
# Cabinets with associated includes (implementation files)
@@ -448,6 +448,8 @@ class CLibSourceGenerator(SourceGenerator):
if not headers.base:
# main CLib file receives references to all cabinets
other = [kk for kk in self._clib_bases if kk]
elif headers.base in other:
other.remove(headers.base)
includes = []
for obj in [headers.base] + list(other):
includes += self._config.includes[obj]
@@ -34,9 +34,7 @@ using namespace Cantera;
{% if base %}
// Define Cabinet<{{ base }}> (single-instance object)
typedef Cabinet<{{ base }}> {{ base }}Cabinet;
// Note: cabinet is already created by the traditional CLib interface
// template<> {{ base }}Cabinet* {{ base }}Cabinet::s_storage = 0; // initialized here
template<> {{ base }}Cabinet* {{ base }}Cabinet::s_storage; // temporary
template<> {{ base }}Cabinet* {{ base }}Cabinet::s_storage = 0; // initialized here
{% endif %}
{% if other %}
+1 -1
View File
@@ -8,7 +8,7 @@ samples = [('demo', ['demo.c'])]
for programName, sources in samples:
buildSample(localenv.Program, programName, sources,
CPPPATH=["#include", "#interfaces/clib_experimental/include"],
CPPPATH=["#interfaces/clib_experimental/include", "#include"],
LIBS=env['cantera_shared_libs'],
LIBPATH=env['extra_lib_dirs'] + ['#build/lib'])
+6 -4
View File
@@ -38,8 +38,10 @@ libs = [('base', ['cpp'], baseSetup),
('transport', ['cpp'], defaultSetup),
('oneD', ['cpp'], defaultSetup),
('zeroD', ['cpp'], defaultSetup),
('clib', ['cpp'], defaultSetup),
]
if not env["clib_experimental"]:
libs.append(('clib', ['cpp'], defaultSetup))
localenv = env.Clone()
localenv.Prepend(CPPPATH=[Dir('#include'), Dir('.')])
@@ -83,9 +85,9 @@ if localenv["clib_experimental"]:
yaml_files = list(auto_path.glob("*_auto.yaml"))
env2 = localenv.Clone()
env2.Append(CCFLAGS=env2['pch_flags'])
# Need to update include paths, where second entry is for clib_utils.h
env2.Prepend(CPPPATH=['#interfaces/clib_experimental/include', '#src/clib'])
env2.Append(CCFLAGS=env2["pch_flags"])
# Need to update include paths, where second entry is for application.h
env2.Prepend(CPPPATH=["#interfaces/clib_experimental/include", "#src/base"])
objects = []
for yaml_file in yaml_files:
+2 -1
View File
@@ -211,9 +211,10 @@ def addPythonTest(testname, subset):
# Instantiate tests
addTestProgram('clib', 'clib')
if localenv['clib_experimental']:
addTestProgram('clib_experimental', 'clib-experimental')
else:
addTestProgram('clib', 'clib')
addTestProgram('equil', 'equil')
addTestProgram('general', 'general')
addTestProgram('kinetics', 'kinetics')
+5 -4
View File
@@ -244,11 +244,12 @@ if env['HAS_OPENMP']:
Test('cxx-rankine', 'cxx_samples', '#build/samples/cxx/rankine/rankine',
'rankine_blessed.txt')
Test('clib-demo', 'clib', '#build/samples/clib/demo', 'clib_demo_blessed.txt')
if env["clib_experimental"]:
Test('clib-experimental-demo', 'clib',
'#build/samples/clib_experimental/demo', 'clib_demo_blessed.txt')
Test('clib-experimental-demo', 'clib',
'#build/samples/clib_experimental/demo', 'clib_demo_blessed.txt')
else:
Test('clib-demo', 'clib', '#build/samples/clib/demo', 'clib_demo_blessed.txt')
# C++ programs from User Guide
Test('cxx-guide-demo1a', 'cxx_userguide', '#build/samples/userguide/demo1a',