Generate verstub.cpp through raw cmake.

There is no need for an extra program.

As a bonus, generate a consistent windows vdi file.

There is still an issue with actually *reading* the vdi, but that's for someone else to tackle.
This commit is contained in:
Jason Felds
2015-10-02 20:02:55 -04:00
parent 429d4dbce2
commit 99b79e5410
12 changed files with 24 additions and 178 deletions
+1
View File
@@ -419,6 +419,7 @@ elseif(LINUX)
endif()
configure_file("${SM_SRC_DIR}/config.in.hpp" "${SM_SRC_DIR}/generated/config.hpp")
configure_file("${SM_SRC_DIR}/verstub.in.cpp" "${SM_SRC_DIR}/generated/verstub.cpp")
# Define installer based items for cpack.
include("${CMAKE_CURRENT_LIST_DIR}/CMake/CPackSetup.cmake")
+4 -32
View File
@@ -1,35 +1,8 @@
file(MAKE_DIRECTORY "${SM_SRC_DIR}/generated")
if(MSVC)
# Version Updater library.
add_subdirectory(version_updater)
# This part may move to a different file: it's the SM Data project.
add_custom_command(
OUTPUT ${SM_SRC_DIR}/generated/verstub.cpp
COMMAND VersionUpdater ${SM_SRC_DIR}/generated/verstub.cpp
DEPENDS VersionUpdater
)
# Add the mapconv program of the past to allow for debugging information.
include("CMakeProject-mapconv.cmake")
else()
# Version Stub generation. Needs fixing on Windows.
add_custom_command(
OUTPUT ${SM_SRC_DIR}/generated/verstub.cpp
COMMAND ${CMAKE_COMMAND}
ARGS -DSM_SRC_DIR=${SM_SRC_DIR} -P ${SM_SRC_DIR}/../CMake/VerStubUtil.cmake
WORKING_DIRECTORY "${SM_ROOT_DIR}"
DEPENDS ${SM_SRC_DIR}/generated/delete
)
add_custom_command(
OUTPUT ${SM_SRC_DIR}/generated/delete
COMMAND rm
ARGS -f ${SM_SRC_DIR}/generated/ver*
WORKING_DIRECTORY "${SM_ROOT_DIR}"
)
# Add the mapconv program of the past to allow for debugging information.
include("CMakeProject-mapconv.cmake")
endif()
# Main project is below.
@@ -39,6 +12,7 @@ list(APPEND SMDATA_GLOBAL_FILES_SRC
"global.cpp"
"SpecialFiles.cpp"
"StepMania.cpp" # TODO: Refactor into separate main project.
"${SM_SRC_DIR}/generated/verstub.cpp"
)
list(APPEND SMDATA_GLOBAL_FILES_HPP
@@ -148,7 +122,6 @@ list(APPEND SMDATA_FILE_TYPES_HPP
source_group("File Types" FILES ${SMDATA_FILE_TYPES_SRC} ${SMDATA_FILE_TYPES_HPP})
list(APPEND SMDATA_ALL_FILES_SRC
${SM_SRC_DIR}/generated/verstub.cpp
${SMDATA_GLOBAL_FILES_SRC}
${SMDATA_GLOBAL_SINGLETON_SRC}
${SMDATA_ALL_ACTORS_SRC}
@@ -306,8 +279,7 @@ if(WIN32)
)
if(MSVC)
# Allow for getting a virtualdub stack trace.
# Allow for getting a virtualdub stack trace.
add_custom_command(TARGET "${SM_EXE_NAME}"
POST_BUILD
COMMAND "mapconv" "${SM_PROGRAM_DIR}/$<$<CONFIG:DEBUG>:${SM_NAME_DEBUG}>$<$<CONFIG:MINSIZEREL>:${SM_NAME_MINSIZEREL}>$<$<CONFIG:RELWITHDEBINFO>:${SM_NAME_RELWITHDEBINFO}>$<$<CONFIG:RELEASE>:${SM_NAME_RELEASE}>.map" "${SM_PROGRAM_DIR}/$<$<CONFIG:DEBUG>:${SM_NAME_DEBUG}>$<$<CONFIG:MINSIZEREL>:${SM_NAME_MINSIZEREL}>$<$<CONFIG:RELWITHDEBINFO>:${SM_NAME_RELWITHDEBINFO}>$<$<CONFIG:RELEASE>:${SM_NAME_RELEASE}>.vdi"
+1 -1
View File
@@ -90,7 +90,7 @@ static void Version()
RString sProductID = ssprintf("%s", (string(PRODUCT_FAMILY) + product_version).c_str() );
RString sVersion = "(StepMania was built without HAVE_VERSION_INFO)";
#if defined(HAVE_VERSION_INFO)
sVersion = ssprintf("build %lu\nCompile Date: %s @ %s", version_num, version_date, version_time);
sVersion = ssprintf("build %s\nCompile Date: %s @ %s", ::sm_version_git_hash, version_date, version_time);
#endif // HAVE_VERSION_INFO
AllocConsole();
+4 -8
View File
@@ -32,11 +32,7 @@ void NetworkSyncManager::SelectUserSong() { }
RString NetworkSyncManager::MD5Hex( const RString &sInput ) { return RString(); }
int NetworkSyncManager::GetSMOnlineSalt() { return 0; }
void NetworkSyncManager::GetListOfLANServers( vector<NetServerInfo>& AllServers ) { }
#if defined(HAVE_VERSION_INFO)
unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) { return version_num; }
#else
unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) { return 0; }
#endif
unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) { return 0; }
#else
#include "ezsockets.h"
#include "ProfileManager.h"
@@ -849,7 +845,7 @@ void NetworkSyncManager::GetListOfLANServers( vector<NetServerInfo>& AllServers
// Aldo: Please move this method to a new class, I didn't want to create new files because I don't know how to properly update the files for each platform.
// I preferred to misplace code rather than cause unneeded headaches to non-windows users, although it would be nice to have in the wiki which files to
// update when adding new files and how (Xcode/stepmania_xcode4.3.xcodeproj has a really crazy structure :/).
#if !defined(HAVE_VERSION_INFO)
#if !defined(HAVE_VERSION_INFO) || defined(CMAKE_POWERED)
unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) { return 0; }
#else
unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld )
@@ -867,7 +863,7 @@ unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld )
ld->SetText("Checking for updates...");
}
unsigned long uCurrentSMBuild = version_num;
unsigned long uCurrentSMBuild = 0;
bool bSuccess = false;
EzSockets* socket = new EzSockets();
socket->create();
@@ -885,7 +881,7 @@ unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld )
"\r\n",
sResource.c_str(), sHost.c_str(),
sUserAgent.c_str(), sReferer.c_str(),
version_num
0
);
socket->SendData(sHTTPRequest);
+1 -2
View File
@@ -919,13 +919,12 @@ static void MountTreeOfZips( const RString &dir )
}
}
static void WriteLogHeader()
{
LOG->Info("%s%s", PRODUCT_FAMILY, product_version);
#if defined(HAVE_VERSION_INFO)
LOG->Info( "Compiled %s @ %s (build %lu)", version_date, version_time, version_num );
LOG->Info( "Compiled %s @ %s (build %s)", version_date, version_time, ::sm_version_git_hash);
#endif
time_t cur_time;
+4 -4
View File
@@ -412,13 +412,13 @@ namespace
{
if( !g_debugInfo.Loaded() )
return ssprintf( "debug resource file '%s': %s.\n", g_debugInfo.sFilename, g_debugInfo.sError.c_str() );
/*
if( g_debugInfo.nBuildNumber != int(version_num) )
{
return ssprintf( "Incorrect %s file (build %d, expected %d) for this version of " PRODUCT_FAMILY " -- call stack unavailable.\n",
g_debugInfo.sFilename, g_debugInfo.nBuildNumber, int(version_num) );
}
*/
RString sRet;
for( int i = 0; Backtrace[i]; ++i )
{
@@ -444,9 +444,9 @@ struct CompleteCrashData
static void MakeCrashReport( const CompleteCrashData &Data, RString &sOut )
{
sOut += ssprintf(
"%s crash report (build %d, %s @ %s)\n"
"%s crash report (build %s, %s @ %s)\n"
"--------------------------------------\n\n",
(string(PRODUCT_FAMILY) + product_version).c_str(), version_num, version_date, version_time );
(string(PRODUCT_FAMILY) + product_version).c_str(), ::sm_version_git_hash, version_date, version_time );
sOut += ssprintf( "Crash reason: %s\n", Data.m_CrashInfo.m_CrashReason );
sOut += ssprintf( "\n" );
+2 -8
View File
@@ -106,7 +106,6 @@ struct RVASorter {
};
int main(int argc, char **argv) {
int ver=0;
int i;
long load_addr;
@@ -115,13 +114,8 @@ int main(int argc, char **argv) {
return 0;
}
if (f=fopen("version.bin", "rb")) {
fread(&ver,4,1,f);
fclose(f);
} else {
printf("can't read version file\n");
return 20;
}
// TODO: Choose a better default for the vdi file.
int ver = 20151002;
if (!(f=fopen(argv[1], "r"))) {
printf("can't open listing file \"%s\"\n", argv[1]);
+5 -4
View File
@@ -4,13 +4,14 @@
#if !defined(CMAKE_POWERED) && ( defined(_MSC_VER) || defined(__MACOSX__) )
#define product_version "5.0-UNKNOWN"
#else
extern const char *const product_version;
extern char const * const product_version;
#endif
// XXX: These names are misnomers. This is actually the BUILD number, time and date.
// NOTE: In GNU toolchain these are defined in ver.cpp. In MSVC these are defined in archutils/Win32/verinc.c I think. Why? I don't know and I don't have MSVC. --root
extern const unsigned long version_num;
extern const char *const version_time;
extern const char *const version_date;
extern unsigned long const version_num;
extern char const * const version_time;
extern char const * const version_date;
extern char const * const sm_version_git_hash;
#endif
-22
View File
@@ -1,22 +0,0 @@
source_group("" FILES Main.cpp)
configure_file(
"version.hpp.in"
"${PROJECT_BINARY_DIR}/version.hpp"
)
include_directories(${PROJECT_BINARY_DIR})
add_executable("VersionUpdater" Main.cpp "${PROJECT_BINARY_DIR}/version.hpp")
if (WITH_FULL_RELEASE)
sm_add_compile_definition("VersionUpdater" IS_FULL_RELEASE)
message(STATUS "Full release mode engaged.")
endif()
set_property(TARGET "VersionUpdater" PROPERTY FOLDER "Internal Libraries")
if(MSVC)
sm_add_compile_definition("VersionUpdater" _CRT_SECURE_NO_WARNINGS)
endif()
-73
View File
@@ -1,73 +0,0 @@
/*
* This program was placed in the public domain by Avery,
* with some ideas implemented by AJ. Any C++ improvements
* are made by others.
*/
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "version.hpp"
int main(int argc, char *argv[]) {
if (argc < 2) {
return 1;
}
std::ifstream versionReadFile("version.bin", std::ios::in);
unsigned long build = 0;
// try to read the last version seen.
if (versionReadFile.is_open()) {
std::string line;
std::getline(versionReadFile, line);
if (!line.empty()) {
// TODO: Use stoul when C++11 is utilized.
build = std::atol(line.c_str());
}
versionReadFile.close();
}
// increment the build number and write it.
++build;
std::ofstream versionWriteFile("version.bin", std::ios::out);
if (versionWriteFile.is_open()) {
versionWriteFile << build;
versionWriteFile.close();
}
char strdate[10];
char strtime[64];
time_t tm;
std::time(&tm);
std::strftime(strdate, 15, "%Y%m%d", std::localtime(&tm));
std::strftime(strtime, 64, "%H:%M:%S %Z", std::localtime(&tm));
// zero out the newline.
strtime[sizeof(strtime) - 1] = 0;
std::ofstream versionDataFile(argv[1], std::ios::out);
if (versionDataFile.is_open()) {
versionDataFile << "extern unsigned long const version_num = " << build << ";" << std::endl;
versionDataFile << "extern int const sm_version_major = " << smVersionMajor << ";" << std::endl;
versionDataFile << "extern int const sm_version_minor = " << smVersionMinor << ";" << std::endl;
versionDataFile << "extern int const sm_version_patch = " << smVersionPatch << ";" << std::endl;
versionDataFile << "extern char const * const sm_version_git_hash = \"" << smVersionGitHash << "\";" << std::endl;
versionDataFile << "extern char const * const sm_version_traditional = \"" << smVersionTraditional << "\";" << std::endl;
versionDataFile << "extern char const * const version_date = \"" << strdate << "\";" << std::endl;
versionDataFile << "extern char const * const version_time = \"" << strtime << "\";" << std::endl;
versionDataFile << "extern char const * const product_version = \"" << smVersionFull << "\";" << std::endl;
versionDataFile.close();
}
return 0;
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef VERSION_UPDATER_HPP_
#define VERSION_UPDATER_HPP_
int smVersionMajor = @SM_VERSION_MAJOR@;
int smVersionMinor = @SM_VERSION_MINOR@;
int smVersionPatch = @SM_VERSION_PATCH@;
char const * const smVersionGitHash = "@SM_VERSION_GIT_HASH@";
#if defined(IS_FULL_RELEASE)
char const * const smVersionFull = "@SM_VERSION_TRADITIONAL@";
#else
char const * const smVersionFull = "@SM_VERSION_FULL@";
#endif
char const * const smVersionTraditional = "@SM_VERSION_TRADITIONAL@";
#endif
@@ -2,14 +2,7 @@ extern int const sm_version_major = @SM_VERSION_MAJOR@;
extern int const sm_version_minor = @SM_VERSION_MINOR@;
extern int const sm_version_patch = @SM_VERSION_PATCH@;
extern char const * const sm_version_git_hash = "@SM_VERSION_GIT_HASH@";
extern char const * const smVersionTraditional = "@SM_VERSION_TRADITIONAL@";
extern char const * const smVersionFull = "@SM_VERSION_FULL@";
extern char const * const sm_version_traditional = "@SM_VERSION_TRADITIONAL@";
extern char const * const version_date = "@SM_TIMESTAMP_DATE@";
extern char const * const version_time = "@SM_TIMESTAMP_TIME@";
#if defined(IS_FULL_RELEASE)
extern char const * const product_version = smVersionFull;
#else
extern char const * const product_version = smVersionTraditional;
#endif
extern int const version_num = 0; // will change
extern char const * const product_version = "@SM_VERSION_GIT@";