Merge pull request #559 from lethosor/dfhack-version-lib

Move DFHack version to a separate (static) library
develop
expwnent 2015-02-21 21:15:57 -05:00
commit 51722f3479
11 changed files with 28 additions and 15 deletions

@ -62,7 +62,6 @@ set(DF_VERSION "0.40.24")
SET(DFHACK_RELEASE "r2") SET(DFHACK_RELEASE "r2")
set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") 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) ## where to install things (after the build is done, classic 'make install' or package structure)
# the dfhack libraries will be installed here: # the dfhack libraries will be installed here:

@ -22,6 +22,7 @@ SET_SOURCE_FILES_PROPERTIES(${GENERATED_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE G
SET(MAIN_HEADERS SET(MAIN_HEADERS
include/Internal.h include/Internal.h
include/DFHack.h include/DFHack.h
include/DFHackVersion.h
include/Console.h include/Console.h
include/Core.h include/Core.h
include/ColorText.h include/ColorText.h
@ -249,6 +250,9 @@ ELSE(WIN32)
SET(PROJECT_LIBS psapi dfhack-tinyxml dfhack-tinythread) SET(PROJECT_LIBS psapi dfhack-tinyxml dfhack-tinythread)
ENDIF() 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_LIBRARY(dfhack SHARED ${PROJECT_SOURCES})
ADD_DEPENDENCIES(dfhack generate_headers) ADD_DEPENDENCIES(dfhack generate_headers)
@ -290,7 +294,7 @@ IF(APPLE)
SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0) SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0)
ENDIF() 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 "") SET_TARGET_PROPERTIES(dfhack PROPERTIES LINK_INTERFACE_LIBRARIES "")
TARGET_LINK_LIBRARIES(dfhack-client protobuf-lite clsocket) TARGET_LINK_LIBRARIES(dfhack-client protobuf-lite clsocket)

@ -52,6 +52,7 @@ using namespace std;
#include "modules/Windows.h" #include "modules/Windows.h"
#include "RemoteServer.h" #include "RemoteServer.h"
#include "LuaTools.h" #include "LuaTools.h"
#include "DFHackVersion.h"
#include "MiscUtils.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" " 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) else if (parts.size() == 1)
{ {

@ -0,0 +1,2 @@
#include "DFHackVersion.h"
const char *get_dfhack_version() { return DFHACK_VERSION; }

@ -47,6 +47,7 @@ distribution.
#include "LuaTools.h" #include "LuaTools.h"
#include "MiscUtils.h" #include "MiscUtils.h"
#include "DFHackVersion.h"
#include "df/job.h" #include "df/job.h"
#include "df/job_item.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_rawsetp(state, LUA_REGISTRYINDEX, &DFHACK_BASE_G_TOKEN);
lua_setfield(state, -2, "BASE_G"); lua_setfield(state, -2, "BASE_G");
lua_pushstring(state, DFHACK_VERSION); lua_pushstring(state, get_dfhack_version());
lua_setfield(state, -2, "VERSION"); lua_setfield(state, -2, "VERSION");
lua_pushboolean(state, IsCoreContext(state)); lua_pushboolean(state, IsCoreContext(state));

@ -35,6 +35,7 @@ distribution.
#include "DataDefs.h" #include "DataDefs.h"
#include "MiscUtils.h" #include "MiscUtils.h"
#include "DFHackVersion.h"
#include "LuaWrapper.h" #include "LuaWrapper.h"
#include "LuaTools.h" #include "LuaTools.h"
@ -226,10 +227,10 @@ bool Plugin::load(color_ostream &con)
state = PS_BROKEN; state = PS_BROKEN;
return false; 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" 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); ClosePlugin(plug);
RefAutolock lock(access); RefAutolock lock(access);
state = PS_BROKEN; state = PS_BROKEN;

@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "PluginManager.h" #include "PluginManager.h"
#include "MiscUtils.h" #include "MiscUtils.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "DFHackVersion.h"
#include "modules/Materials.h" #include "modules/Materials.h"
#include "modules/Translation.h" #include "modules/Translation.h"
@ -360,7 +361,7 @@ void DFHack::describeUnit(BasicUnitInfo *info, df::unit *unit,
static command_result GetVersion(color_ostream &stream, static command_result GetVersion(color_ostream &stream,
const EmptyMessage *, StringMessage *out) const EmptyMessage *, StringMessage *out)
{ {
out->set_value(DFHACK_VERSION); out->set_value(get_dfhack_version());
return CR_OK; return CR_OK;
} }

@ -0,0 +1 @@
const char *get_dfhack_version();

@ -24,6 +24,7 @@ distribution.
#pragma once #pragma once
#include "DFHackVersion.h"
#include "Export.h" #include "Export.h"
#include "Hooks.h" #include "Hooks.h"
#include "ColorText.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. /// You have to have this in every plugin you write - just once. Ideally on top of the main file.
#define DFHACK_PLUGIN(plugin_name) \ #define DFHACK_PLUGIN(plugin_name) \
DFhackDataExport const char * version = DFHACK_VERSION;\
DFhackDataExport const char * name = plugin_name;\ DFhackDataExport const char * name = plugin_name;\
DFhackDataExport const char * version = get_dfhack_version();\
DFhackDataExport Plugin *plugin_self = NULL;\ DFhackDataExport Plugin *plugin_self = NULL;\
std::vector<std::string> _plugin_globals;\ std::vector<std::string> _plugin_globals;\
DFhackDataExport std::vector<std::string>* plugin_globals = &_plugin_globals; DFhackDataExport std::vector<std::string>* plugin_globals = &_plugin_globals;

@ -65,7 +65,7 @@ MACRO(DFHACK_PLUGIN)
) )
CAR(PLUGIN_NAME ${PLUGIN_DEFAULT_ARGS}) CAR(PLUGIN_NAME ${PLUGIN_DEFAULT_ARGS})
CDR(PLUGIN_SOURCES ${PLUGIN_DEFAULT_ARGS}) CDR(PLUGIN_SOURCES ${PLUGIN_DEFAULT_ARGS})
SET(PLUGIN_PROTOCPP) SET(PLUGIN_PROTOCPP)
FOREACH(pbuf ${PLUGIN_PROTOBUFS}) FOREACH(pbuf ${PLUGIN_PROTOBUFS})
SET(PLUGIN_SOURCES ${PLUGIN_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/proto/${pbuf}.pb.cc) 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}) ADD_LIBRARY(${PLUGIN_NAME} MODULE ${PLUGIN_SOURCES})
IDE_FOLDER(${PLUGIN_NAME} "Plugins") IDE_FOLDER(${PLUGIN_NAME} "Plugins")
ADD_DEPENDENCIES(${PLUGIN_NAME} dfhack-version)
# Make sure the source is generated before the executable builds. # Make sure the source is generated before the executable builds.
ADD_DEPENDENCIES(${PLUGIN_NAME} generate_proto) ADD_DEPENDENCIES(${PLUGIN_NAME} generate_proto)
LIST(LENGTH PLUGIN_PROTOBUFS NUM_PROTO) LIST(LENGTH PLUGIN_PROTOBUFS NUM_PROTO)
IF(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) IF(UNIX)
SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES COMPILE_FLAGS "-include Export.h") SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES COMPILE_FLAGS "-include Export.h")
ELSE() ELSE()
SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"") SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"")
ENDIF() ENDIF()
ELSE() ELSE()
TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack ${PLUGIN_LINK_LIBRARIES}) TARGET_LINK_LIBRARIES(${PLUGIN_NAME} dfhack dfhack-version ${PLUGIN_LINK_LIBRARIES})
ENDIF() ENDIF()
IF(APPLE) IF(APPLE)
@ -104,4 +106,4 @@ MACRO(DFHACK_PLUGIN)
install(TARGETS ${PLUGIN_NAME} install(TARGETS ${PLUGIN_NAME}
LIBRARY DESTINATION ${DFHACK_PLUGIN_DESTINATION} LIBRARY DESTINATION ${DFHACK_PLUGIN_DESTINATION}
RUNTIME DESTINATION ${DFHACK_PLUGIN_DESTINATION}) RUNTIME DESTINATION ${DFHACK_PLUGIN_DESTINATION})
ENDMACRO(DFHACK_PLUGIN) ENDMACRO(DFHACK_PLUGIN)

@ -483,7 +483,7 @@ static VALUE rb_cDFHack;
// df-dfhack version (eg "0.34.11-r2") // df-dfhack version (eg "0.34.11-r2")
static VALUE rb_dfversion(VALUE self) 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() // enable/disable calls to DFHack.onupdate()