diff --git a/CMakeLists.txt b/CMakeLists.txt index ce104a93a..1ed6621b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,6 @@ set(DF_VERSION "0.40.24") SET(DFHACK_RELEASE "r2") set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") -add_definitions(-DDFHACK_VERSION="${DFHACK_VERSION}") ## where to install things (after the build is done, classic 'make install' or package structure) # the dfhack libraries will be installed here: diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 8bedb6b1d..69bf4d63a 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -22,6 +22,7 @@ SET_SOURCE_FILES_PROPERTIES(${GENERATED_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE G SET(MAIN_HEADERS include/Internal.h include/DFHack.h +include/DFHackVersion.h include/Console.h include/Core.h include/ColorText.h @@ -249,6 +250,9 @@ ELSE(WIN32) SET(PROJECT_LIBS psapi dfhack-tinyxml dfhack-tinythread) ENDIF() +ADD_LIBRARY(dfhack-version STATIC DFHackVersion.cpp) +SET_TARGET_PROPERTIES(dfhack-version PROPERTIES COMPILE_DEFINITIONS DFHACK_VERSION="${DFHACK_VERSION}") + ADD_LIBRARY(dfhack SHARED ${PROJECT_SOURCES}) ADD_DEPENDENCIES(dfhack generate_headers) @@ -290,7 +294,7 @@ IF(APPLE) SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0) ENDIF() -TARGET_LINK_LIBRARIES(dfhack protobuf-lite clsocket lua ${PROJECT_LIBS}) +TARGET_LINK_LIBRARIES(dfhack protobuf-lite clsocket lua dfhack-version ${PROJECT_LIBS}) SET_TARGET_PROPERTIES(dfhack PROPERTIES LINK_INTERFACE_LIBRARIES "") TARGET_LINK_LIBRARIES(dfhack-client protobuf-lite clsocket) diff --git a/library/Core.cpp b/library/Core.cpp index cba4fe42f..dac776506 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -52,6 +52,7 @@ using namespace std; #include "modules/Windows.h" #include "RemoteServer.h" #include "LuaTools.h" +#include "DFHackVersion.h" #include "MiscUtils.h" @@ -487,7 +488,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve " reload PLUGIN|all - Reload a plugin or all loaded plugins.\n" ); - con.print("\nDFHack version " DFHACK_VERSION ".\n"); + con.print("\nDFHack version %s.\n", get_dfhack_version()); } else if (parts.size() == 1) { diff --git a/library/DFHackVersion.cpp b/library/DFHackVersion.cpp new file mode 100644 index 000000000..4f82d3638 --- /dev/null +++ b/library/DFHackVersion.cpp @@ -0,0 +1,2 @@ +#include "DFHackVersion.h" +const char *get_dfhack_version() { return DFHACK_VERSION; } diff --git a/library/LuaTools.cpp b/library/LuaTools.cpp index 383e8b490..b883ea5b9 100644 --- a/library/LuaTools.cpp +++ b/library/LuaTools.cpp @@ -47,6 +47,7 @@ distribution. #include "LuaTools.h" #include "MiscUtils.h" +#include "DFHackVersion.h" #include "df/job.h" #include "df/job_item.h" @@ -1587,7 +1588,7 @@ lua_State *DFHack::Lua::Open(color_ostream &out, lua_State *state) lua_rawsetp(state, LUA_REGISTRYINDEX, &DFHACK_BASE_G_TOKEN); lua_setfield(state, -2, "BASE_G"); - lua_pushstring(state, DFHACK_VERSION); + lua_pushstring(state, get_dfhack_version()); lua_setfield(state, -2, "VERSION"); lua_pushboolean(state, IsCoreContext(state)); diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index ea919dc61..d89fcad71 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -35,6 +35,7 @@ distribution. #include "DataDefs.h" #include "MiscUtils.h" +#include "DFHackVersion.h" #include "LuaWrapper.h" #include "LuaTools.h" @@ -226,10 +227,10 @@ bool Plugin::load(color_ostream &con) state = PS_BROKEN; return false; } - if(strcmp(DFHACK_VERSION, *plug_version) != 0) + if(strcmp(get_dfhack_version(), *plug_version) != 0) { con.printerr("Plugin %s was not built for this version of DFHack.\n" - "Plugin: %s, DFHack: %s\n", *plug_name, *plug_version, DFHACK_VERSION); + "Plugin: %s, DFHack: %s\n", *plug_name, *plug_version, get_dfhack_version()); ClosePlugin(plug); RefAutolock lock(access); state = PS_BROKEN; diff --git a/library/RemoteTools.cpp b/library/RemoteTools.cpp index f1887c9a7..d065dfa5e 100644 --- a/library/RemoteTools.cpp +++ b/library/RemoteTools.cpp @@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "PluginManager.h" #include "MiscUtils.h" #include "VersionInfo.h" +#include "DFHackVersion.h" #include "modules/Materials.h" #include "modules/Translation.h" @@ -360,7 +361,7 @@ void DFHack::describeUnit(BasicUnitInfo *info, df::unit *unit, static command_result GetVersion(color_ostream &stream, const EmptyMessage *, StringMessage *out) { - out->set_value(DFHACK_VERSION); + out->set_value(get_dfhack_version()); return CR_OK; } diff --git a/library/include/DFHackVersion.h b/library/include/DFHackVersion.h new file mode 100644 index 000000000..aead35369 --- /dev/null +++ b/library/include/DFHackVersion.h @@ -0,0 +1 @@ +const char *get_dfhack_version(); diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index 3075844da..befc030ff 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -24,6 +24,7 @@ distribution. #pragma once +#include "DFHackVersion.h" #include "Export.h" #include "Hooks.h" #include "ColorText.h" @@ -272,8 +273,8 @@ namespace DFHack /// You have to have this in every plugin you write - just once. Ideally on top of the main file. #define DFHACK_PLUGIN(plugin_name) \ - DFhackDataExport const char * version = DFHACK_VERSION;\ DFhackDataExport const char * name = plugin_name;\ + DFhackDataExport const char * version = get_dfhack_version();\ DFhackDataExport Plugin *plugin_self = NULL;\ std::vector _plugin_globals;\ DFhackDataExport std::vector* plugin_globals = &_plugin_globals; diff --git a/plugins/Plugins.cmake b/plugins/Plugins.cmake index e5d0c3bae..1e8ef8936 100644 --- a/plugins/Plugins.cmake +++ b/plugins/Plugins.cmake @@ -65,7 +65,7 @@ MACRO(DFHACK_PLUGIN) ) CAR(PLUGIN_NAME ${PLUGIN_DEFAULT_ARGS}) CDR(PLUGIN_SOURCES ${PLUGIN_DEFAULT_ARGS}) - + SET(PLUGIN_PROTOCPP) FOREACH(pbuf ${PLUGIN_PROTOBUFS}) SET(PLUGIN_SOURCES ${PLUGIN_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/proto/${pbuf}.pb.cc) @@ -77,20 +77,22 @@ MACRO(DFHACK_PLUGIN) ADD_LIBRARY(${PLUGIN_NAME} MODULE ${PLUGIN_SOURCES}) IDE_FOLDER(${PLUGIN_NAME} "Plugins") - + + ADD_DEPENDENCIES(${PLUGIN_NAME} dfhack-version) + # Make sure the source is generated before the executable builds. ADD_DEPENDENCIES(${PLUGIN_NAME} generate_proto) - + LIST(LENGTH PLUGIN_PROTOBUFS NUM_PROTO) IF(NUM_PROTO) - TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack protobuf-lite ${PLUGIN_LINK_LIBRARIES}) + TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack protobuf-lite dfhack-version ${PLUGIN_LINK_LIBRARIES}) IF(UNIX) SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES COMPILE_FLAGS "-include Export.h") ELSE() SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"") ENDIF() ELSE() - TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack ${PLUGIN_LINK_LIBRARIES}) + TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack dfhack-version ${PLUGIN_LINK_LIBRARIES}) ENDIF() IF(APPLE) @@ -104,4 +106,4 @@ MACRO(DFHACK_PLUGIN) install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION ${DFHACK_PLUGIN_DESTINATION} RUNTIME DESTINATION ${DFHACK_PLUGIN_DESTINATION}) -ENDMACRO(DFHACK_PLUGIN) \ No newline at end of file +ENDMACRO(DFHACK_PLUGIN) diff --git a/plugins/ruby/ruby.cpp b/plugins/ruby/ruby.cpp index 93d6501f0..4aa78396a 100644 --- a/plugins/ruby/ruby.cpp +++ b/plugins/ruby/ruby.cpp @@ -483,7 +483,7 @@ static VALUE rb_cDFHack; // df-dfhack version (eg "0.34.11-r2") static VALUE rb_dfversion(VALUE self) { - return rb_str_new(DFHACK_VERSION, strlen(DFHACK_VERSION)); + return rb_str_new(get_dfhack_version(), strlen(get_dfhack_version())); } // enable/disable calls to DFHack.onupdate()