Add version numbers that can be queried at runtime
This commit is contained in:
parent
7932cb18f3
commit
b87c37032b
@ -192,12 +192,12 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
|
|||||||
set(CMAKE_SHARED_MODULE_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
|
set(CMAKE_SHARED_MODULE_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
|
||||||
|
|
||||||
|
|
||||||
add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp)
|
add_library(chaiscript_stdlib-${CHAI_VERSION} MODULE src/chaiscript_stdlib.cpp)
|
||||||
target_link_libraries(chaiscript_stdlib ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(chaiscript_stdlib-${CHAI_VERSION} ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
|
||||||
add_executable(chai src/main.cpp ${Chai_INCLUDES})
|
add_executable(chai src/main.cpp ${Chai_INCLUDES})
|
||||||
target_link_libraries(chai ${LIBS})
|
target_link_libraries(chai ${LIBS})
|
||||||
add_dependencies(chai chaiscript_stdlib)
|
add_dependencies(chai chaiscript_stdlib-${CHAI_VERSION})
|
||||||
|
|
||||||
if (BUILD_SAMPLES)
|
if (BUILD_SAMPLES)
|
||||||
add_executable(example samples/example.cpp)
|
add_executable(example samples/example.cpp)
|
||||||
@ -223,6 +223,14 @@ list(SORT UNIT_TESTS)
|
|||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
option(UNIT_TEST_LIGHT "Unit tests light (expect module loading failures)" FALSE)
|
option(UNIT_TEST_LIGHT "Unit tests light (expect module loading failures)" FALSE)
|
||||||
|
|
||||||
|
add_test(version_check chai -c "if(\"\\\${ version() };\\\${version_major()};\\\${version_minor()};\\\${version_patch()}\" != \"${CHAI_VERSION};${CPACK_PACKAGE_VERSION_MAJOR};${CPACK_PACKAGE_VERSION_MINOR};${CPACK_PACKAGE_VERSION_PATCH}\") { exit(-1) }")
|
||||||
|
set_property(TEST version_check
|
||||||
|
PROPERTY ENVIRONMENT
|
||||||
|
"CHAI_USE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/unittests/"
|
||||||
|
"CHAI_MODULE_PATH=${CMAKE_CURRENT_BINARY_DIR}/"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
foreach(filename ${UNIT_TESTS})
|
foreach(filename ${UNIT_TESTS})
|
||||||
message(STATUS "Adding test ${filename}")
|
message(STATUS "Adding test ${filename}")
|
||||||
add_test(${filename} chai ${CMAKE_CURRENT_SOURCE_DIR}/unittests/unit_test.inc ${CMAKE_CURRENT_SOURCE_DIR}/unittests/${filename})
|
add_test(${filename} chai ${CMAKE_CURRENT_SOURCE_DIR}/unittests/unit_test.inc ${CMAKE_CURRENT_SOURCE_DIR}/unittests/${filename})
|
||||||
@ -333,7 +341,7 @@ if(BUILD_TESTING)
|
|||||||
endif()
|
endif()
|
||||||
endif(BUILD_TESTING)
|
endif(BUILD_TESTING)
|
||||||
|
|
||||||
install(TARGETS chai chaiscript_stdlib ${MODULES} RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript )
|
install(TARGETS chai chaiscript_stdlib-${CHAI_VERSION} ${MODULES} RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript )
|
||||||
|
|
||||||
install(DIRECTORY include/chaiscript DESTINATION include
|
install(DIRECTORY include/chaiscript DESTINATION include
|
||||||
PATTERN "*.hpp"
|
PATTERN "*.hpp"
|
||||||
|
@ -36,7 +36,11 @@
|
|||||||
#define CHAISCRIPT_CONSTEXPR constexpr
|
#define CHAISCRIPT_CONSTEXPR constexpr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace chaiscript {
|
||||||
|
static const int version_major = 5;
|
||||||
|
static const int version_minor = 3;
|
||||||
|
static const int version_patch = 1;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -253,8 +253,6 @@ namespace chaiscript
|
|||||||
|
|
||||||
chaiscript::detail::Dispatch_Engine m_engine;
|
chaiscript::detail::Dispatch_Engine m_engine;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Evaluates the given string in by parsing it and running the results through the evaluator
|
/// Evaluates the given string in by parsing it and running the results through the evaluator
|
||||||
Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false)
|
Boxed_Value do_eval(const std::string &t_input, const std::string &t_filename = "__EVAL__", bool /* t_internal*/ = false)
|
||||||
{
|
{
|
||||||
@ -329,7 +327,6 @@ namespace chaiscript
|
|||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists");
|
||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions");
|
||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects");
|
||||||
|
|
||||||
m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&chaiscript::detail::Dispatch_Engine::call_exists, std::ref(m_engine), std::placeholders::_1))),
|
m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&chaiscript::detail::Dispatch_Engine::call_exists, std::ref(m_engine), std::placeholders::_1))),
|
||||||
"call_exists");
|
"call_exists");
|
||||||
m_engine.add(fun<Boxed_Value (const dispatch::Proxy_Function_Base *, const std::vector<Boxed_Value> &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call");
|
m_engine.add(fun<Boxed_Value (const dispatch::Proxy_Function_Base *, const std::vector<Boxed_Value> &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call");
|
||||||
@ -347,6 +344,12 @@ namespace chaiscript
|
|||||||
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
|
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
|
||||||
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
|
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
|
||||||
|
|
||||||
|
m_engine.add(fun(&ChaiScript::version_major, this), "version_major");
|
||||||
|
m_engine.add(fun(&ChaiScript::version_minor, this), "version_minor");
|
||||||
|
m_engine.add(fun(&ChaiScript::version_patch, this), "version_patch");
|
||||||
|
m_engine.add(fun(&ChaiScript::version, this), "version");
|
||||||
|
|
||||||
|
|
||||||
do_eval(ChaiScript_Prelude::chaiscript_prelude(), "standard prelude");
|
do_eval(ChaiScript_Prelude::chaiscript_prelude(), "standard prelude");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,12 +458,32 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
// attempt to load the stdlib
|
// attempt to load the stdlib
|
||||||
load_module("chaiscript_stdlib");
|
load_module("chaiscript_stdlib-" + version());
|
||||||
|
|
||||||
build_eval_system(ModulePtr());
|
build_eval_system(ModulePtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int version_major() const
|
||||||
|
{
|
||||||
|
return chaiscript::version_major;
|
||||||
|
}
|
||||||
|
|
||||||
|
int version_minor() const
|
||||||
|
{
|
||||||
|
return chaiscript::version_minor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int version_patch() const
|
||||||
|
{
|
||||||
|
return chaiscript::version_patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string version() const
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << version_major() << "." << version_minor() << "." << version_patch();
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Loads and parses a file. If the file is already, it is not reloaded
|
/// \brief Loads and parses a file. If the file is already, it is not reloaded
|
||||||
/// The use paths specified at ChaiScript construction time are searched for the
|
/// The use paths specified at ChaiScript construction time are searched for the
|
||||||
@ -655,6 +678,12 @@ namespace chaiscript
|
|||||||
std::string load_module(const std::string &t_module_name)
|
std::string load_module(const std::string &t_module_name)
|
||||||
{
|
{
|
||||||
std::vector<exception::load_module_error> errors;
|
std::vector<exception::load_module_error> errors;
|
||||||
|
std::string version_stripped_name = t_module_name;
|
||||||
|
size_t version_pos = version_stripped_name.find("-"+version());
|
||||||
|
if (version_pos != std::string::npos)
|
||||||
|
{
|
||||||
|
version_stripped_name.erase(version_pos);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> prefixes;
|
std::vector<std::string> prefixes;
|
||||||
prefixes.push_back("lib");
|
prefixes.push_back("lib");
|
||||||
@ -674,7 +703,7 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k];
|
std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k];
|
||||||
// std::cerr << "trying location: " << name << std::endl;
|
// std::cerr << "trying location: " << name << std::endl;
|
||||||
load_module(t_module_name, name);
|
load_module(version_stripped_name, name);
|
||||||
return name;
|
return name;
|
||||||
} catch (const chaiscript::exception::load_module_error &e) {
|
} catch (const chaiscript::exception::load_module_error &e) {
|
||||||
// std::cerr << "error: " << e.what() << std::endl;
|
// std::cerr << "error: " << e.what() << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user