Generate version info and timestamp at build time
* Print this info from `p21read -v` and in a comment in generated source, not just from `fedex_plus -v` * Use a function `const char* scl_version()`, instead of using the macro `SCL_COMMIT_ID` * Fail gracefully if the `.git` directory does not exist (thanks CY!) * Fixes issue #89
This commit is contained in:
parent
fa615a1786
commit
dc30ee21fd
8 changed files with 105 additions and 32 deletions
|
|
@ -48,7 +48,7 @@ ENDIF(COMMAND CMAKE_POLICY)
|
||||||
PROJECT(SCL)
|
PROJECT(SCL)
|
||||||
|
|
||||||
if( CMAKE_BUILD_TYPE STREQUAL "" )
|
if( CMAKE_BUILD_TYPE STREQUAL "" )
|
||||||
message( "Debug build - to override, rerun cmake with '-DCMAKE_BUILD_TYPE=Release'." )
|
message( "-- Debug build - to override, rerun cmake with '-DCMAKE_BUILD_TYPE=Release'." )
|
||||||
set( CMAKE_BUILD_TYPE Debug )
|
set( CMAKE_BUILD_TYPE Debug )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
@ -176,8 +176,8 @@ IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||||
IF ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
|
IF ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
|
||||||
SET(CMAKE_INSTALL_PREFIX "/usr")
|
SET(CMAKE_INSTALL_PREFIX "/usr")
|
||||||
ELSEIF ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
|
ELSEIF ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
|
||||||
MESSAGE("setting debug output dir")
|
|
||||||
SET(CMAKE_INSTALL_PREFIX "${SCL_SOURCE_DIR}/../scl-install")
|
SET(CMAKE_INSTALL_PREFIX "${SCL_SOURCE_DIR}/../scl-install")
|
||||||
|
MESSAGE("--- Setting debug install dir to ${CMAKE_INSTALL_PREFIX}")
|
||||||
ELSE("${CMAKE_BUILD_TYPE}" MATCHES "Release")
|
ELSE("${CMAKE_BUILD_TYPE}" MATCHES "Release")
|
||||||
SET(CMAKE_INSTALL_PREFIX "/usr/local")
|
SET(CMAKE_INSTALL_PREFIX "/usr/local")
|
||||||
ENDIF ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
|
ENDIF ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
|
||||||
|
|
@ -213,23 +213,26 @@ CHECK_FUNCTION_EXISTS(memmove HAVE_MEMMOVE)
|
||||||
|
|
||||||
CHECK_TYPE_SIZE("ssize_t" SSIZE_T)
|
CHECK_TYPE_SIZE("ssize_t" SSIZE_T)
|
||||||
|
|
||||||
#set GIT_COMMIT_ID to the output of `git describe`
|
|
||||||
find_package(Git)
|
|
||||||
if(GIT_FOUND)
|
|
||||||
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags RESULT_VARIABLE res_var OUTPUT_VARIABLE GIT_COM_ID )
|
|
||||||
if( NOT ${res_var} EQUAL 0 )
|
|
||||||
set( GIT_COMMIT_ID "unknown (git failed!)")
|
|
||||||
message( WARNING "Git failed (not a repo?). Build will not contain git revision info." )
|
|
||||||
endif()
|
|
||||||
string( REPLACE "\n" "" GIT_COMMIT_ID ${GIT_COM_ID} )
|
|
||||||
else()
|
|
||||||
set( GIT_COMMIT_ID "unknown (git not found!)")
|
|
||||||
message( WARNING "Git not found. Build will not contain git revision info." )
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Now that all the tests are done, configure the scl_cf.h file:
|
# Now that all the tests are done, configure the scl_cf.h file:
|
||||||
configure_file(${SCL_BINARY_DIR}/include/scl_cf.h.in ${SCL_BINARY_DIR}/include/scl_cf.h)
|
configure_file(${SCL_BINARY_DIR}/include/scl_cf.h.in ${SCL_BINARY_DIR}/include/scl_cf.h)
|
||||||
|
|
||||||
|
################ create scl_version_string.h, http://stackoverflow.com/questions/3780667
|
||||||
|
# Using 'ver_string' instead of 'scl_version_string.h' is a trick to force the
|
||||||
|
# command to always execute when the custom target is built. It works because
|
||||||
|
# a file by that name never exists.
|
||||||
|
add_custom_target(version_string ALL
|
||||||
|
DEPENDS ver_string )
|
||||||
|
# creates scl_version_string.h using cmake script
|
||||||
|
add_custom_command(OUTPUT ver_string ${CMAKE_CURRENT_BINARY_DIR}/include/scl_version_string.h
|
||||||
|
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${SCL_SOURCE_DIR}
|
||||||
|
-DBINARY_DIR=${SCL_BINARY_DIR}
|
||||||
|
-P ${SCL_CMAKE_DIR}/scl_version_string.cmake)
|
||||||
|
# scl_version_string.h is a generated file
|
||||||
|
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/include/scl_version_string.h
|
||||||
|
PROPERTIES GENERATED TRUE
|
||||||
|
HEADER_FILE_ONLY TRUE )
|
||||||
|
################
|
||||||
|
|
||||||
add_definitions( -pedantic -W -Wall -Wundef -Wfloat-equal -Wshadow -Winline -Wno-long-long )
|
add_definitions( -pedantic -W -Wall -Wundef -Wfloat-equal -Wshadow -Winline -Wno-long-long )
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
|
|
||||||
59
cmake/scl_version_string.cmake
Normal file
59
cmake/scl_version_string.cmake
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#use git for a pretty commit id
|
||||||
|
#uses 'git describe --tags', so tags are required in the repo
|
||||||
|
#create a tag with 'git tag <name>' and 'git push --tags'
|
||||||
|
|
||||||
|
# http://stackoverflow.com/questions/3780667
|
||||||
|
# http://www.cmake.org/pipermail/cmake/2009-February/027014.html
|
||||||
|
|
||||||
|
#scl_version_string.h defines scl_version() which returns a pretty commit description and a build timestamp.
|
||||||
|
if( EXISTS ${SOURCE_DIR}/.git )
|
||||||
|
find_package(Git QUIET)
|
||||||
|
if(GIT_FOUND)
|
||||||
|
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags RESULT_VARIABLE res_var OUTPUT_VARIABLE GIT_COM_ID )
|
||||||
|
if( NOT ${res_var} EQUAL 0 )
|
||||||
|
set( GIT_COMMIT_ID "unknown (no tags?)")
|
||||||
|
message( WARNING "Git failed (invalid repo, or no tags). Build will not contain git revision info." )
|
||||||
|
endif()
|
||||||
|
string( REPLACE "\n" "" GIT_COMMIT_ID ${GIT_COM_ID} )
|
||||||
|
else(GIT_FOUND)
|
||||||
|
set( GIT_COMMIT_ID "unknown (git not found!)")
|
||||||
|
message( WARNING "Git not found. Build will not contain git revision info." )
|
||||||
|
endif(GIT_FOUND)
|
||||||
|
else()
|
||||||
|
set( GIT_COMMIT_ID "unknown (not a repository!)")
|
||||||
|
message( WARNING "Git failed (.git not found). Build will not contain git revision info." )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set( res_var 1 )
|
||||||
|
IF (WIN32)
|
||||||
|
EXECUTE_PROCESS(COMMAND "date" "/T" RESULT_VARIABLE res_var OUTPUT_VARIABLE TIMESTAMP )
|
||||||
|
ELSEIF(UNIX)
|
||||||
|
EXECUTE_PROCESS(COMMAND "date" RESULT_VARIABLE res_var OUTPUT_VARIABLE TIMESTAMP )
|
||||||
|
ELSE()
|
||||||
|
MESSAGE(WARNING "Unknown platform: date not included in version string")
|
||||||
|
ENDIF()
|
||||||
|
if( NOT ${res_var} EQUAL 0 )
|
||||||
|
SET( TIMESTAMP "000000" )
|
||||||
|
else()
|
||||||
|
string( REPLACE "\n" "" TIMESTAMP ${TIMESTAMP} )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set( vstring "//scl_version_string.h - written by cmake. Changes will be lost!\n"
|
||||||
|
"#ifndef SCL_VERSION_STRING\n"
|
||||||
|
"#define SCL_VERSION_STRING\n\n"
|
||||||
|
"/*\n** Returns a string like \"test-1-g5e1fb47, built on <timestamp>\", where test is the\n"
|
||||||
|
"** name of the last tagged git revision, 1 is the number of commits since that tag,\n"
|
||||||
|
"** 'g' is unknown, 5e1fb47 is the first 7 chars of the git sha1 commit id, and\n"
|
||||||
|
"** <timestamp> is the output of your system's 'date' command.\n*/\n\n"
|
||||||
|
"const char* scl_version() {\n"
|
||||||
|
" return \"git commit id ${GIT_COMMIT_ID}, built on ${TIMESTAMP}\"\;\n"
|
||||||
|
"}\n\n"
|
||||||
|
"#endif\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
file(WRITE scl_version_string.h.txt ${vstring} )
|
||||||
|
# copy the file to the final header only if the version changes
|
||||||
|
# reduces needless rebuilds
|
||||||
|
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
scl_version_string.h.txt ${BINARY_DIR}/include/scl_version_string.h)
|
||||||
|
message("-- scl_version_string.h is up-to-date.")
|
||||||
|
|
@ -86,6 +86,7 @@ FUNCTION(BUILD_A_SCHEMA SCHEMA_FILE)
|
||||||
set_tests_properties( build_cpp_${PROJECT_NAME} PROPERTIES DEPENDS generate_cpp_${SCHEMA_SHORT_NAME} LABELS cpp_schema_build )
|
set_tests_properties( build_cpp_${PROJECT_NAME} PROPERTIES DEPENDS generate_cpp_${SCHEMA_SHORT_NAME} LABELS cpp_schema_build )
|
||||||
|
|
||||||
add_executable( p21read_${PROJECT_NAME} ${SCL_SOURCE_DIR}/src/test/p21read/p21read.cc )
|
add_executable( p21read_${PROJECT_NAME} ${SCL_SOURCE_DIR}/src/test/p21read/p21read.cc )
|
||||||
|
add_dependencies( p21read_${PROJECT_NAME} version_string )
|
||||||
target_link_libraries( p21read_${PROJECT_NAME} ${PROJECT_NAME} )
|
target_link_libraries( p21read_${PROJECT_NAME} ${PROJECT_NAME} )
|
||||||
set_target_properties( p21read_${PROJECT_NAME} PROPERTIES COMPILE_FLAGS
|
set_target_properties( p21read_${PROJECT_NAME} PROPERTIES COMPILE_FLAGS
|
||||||
${${PROJECT_NAME}_COMPILE_FLAGS} )
|
${${PROJECT_NAME}_COMPILE_FLAGS} )
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,3 @@
|
||||||
#cmakedefine HAVE_MEMMOVE 1
|
#cmakedefine HAVE_MEMMOVE 1
|
||||||
#cmakedefine HAVE_SSIZE_T 1
|
#cmakedefine HAVE_SSIZE_T 1
|
||||||
|
|
||||||
//cmake updates this at build time
|
|
||||||
#define SCL_COMMIT_ID "@GIT_COMMIT_ID@"
|
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "scl_cf.h"
|
#include "scl_cf.h"
|
||||||
|
#include "scl_version_string.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -91,7 +92,7 @@ char EXPRESSgetopt_options[256] = "Bbd:e:i:w:p:u:l:nrvz";
|
||||||
int no_need_to_work = 0; /* TRUE if we can exit gracefully without doing any work */
|
int no_need_to_work = 0; /* TRUE if we can exit gracefully without doing any work */
|
||||||
|
|
||||||
void print_fedex_version( void ) {
|
void print_fedex_version( void ) {
|
||||||
printf( "%s\nSCL version id (from git): %s\nhttp://github.com/mpictor/StepClassLibrary\n", EXPRESSprogram_name, SCL_COMMIT_ID );
|
fprintf( stderr, "Build info for %s: %s\nhttp://github.com/mpictor/StepClassLibrary\n", EXPRESSprogram_name, scl_version() );
|
||||||
no_need_to_work = 1;
|
no_need_to_work = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,4 @@ ENDIF()
|
||||||
|
|
||||||
SCL_ADDEXEC(fedex_plus "${fedex_plus_SOURCES}" "libexppp express")
|
SCL_ADDEXEC(fedex_plus "${fedex_plus_SOURCES}" "libexppp express")
|
||||||
|
|
||||||
|
add_dependencies( fedex_plus version_string )
|
||||||
|
|
@ -18,6 +18,8 @@ for the STEP Standard Data Access Interface as defined in document
|
||||||
N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
|
N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
|
||||||
*******************************************************************/
|
*******************************************************************/
|
||||||
|
|
||||||
|
extern char* scl_version();
|
||||||
|
|
||||||
extern int multiple_inheritance;
|
extern int multiple_inheritance;
|
||||||
/*extern int corba_binding; */
|
/*extern int corba_binding; */
|
||||||
|
|
||||||
|
|
@ -125,9 +127,9 @@ FILEcreate( const char * filename ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf( file, "#ifndef %s\n", fn = StrToConstant( filename ) );
|
fprintf( file, "#ifndef %s\n", fn = StrToConstant( filename ) );
|
||||||
fprintf( file, "#define %s\n", fn );
|
fprintf( file, "#define %s\n\n", fn );
|
||||||
|
|
||||||
fprintf( file, "// This file was generated by fedex_plus %s.\n", scl_version() );
|
fprintf( file, "// This file was generated by fedex_plus,\n// %s.\n", scl_version() );
|
||||||
fprintf( file, "// You probably don't want to edit it since your modifications\n" );
|
fprintf( file, "// You probably don't want to edit it since your modifications\n" );
|
||||||
fprintf( file, "// will be lost if fedex_plus is used to regenerate it.\n" );
|
fprintf( file, "// will be lost if fedex_plus is used to regenerate it.\n" );
|
||||||
return ( file );
|
return ( file );
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern void SchemaInit( class Registry & );
|
extern void SchemaInit( class Registry & );
|
||||||
|
#include "scl_version_string.h"
|
||||||
#include <STEPfile.h>
|
#include <STEPfile.h>
|
||||||
#include <sdai.h>
|
#include <sdai.h>
|
||||||
#include <STEPattribute.h>
|
#include <STEPattribute.h>
|
||||||
|
|
@ -82,12 +83,18 @@ void checkSchemaName( Registry & reg, STEPfile & sf, bool ignoreErr ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printVersion(const char * exe) {
|
||||||
|
std::cout << exe << " build info: " << scl_version() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void printUse(const char * exe) {
|
void printUse(const char * exe) {
|
||||||
std::cout << "p21read - read a STEP Part 21 exchange file using SCL, and write the data to another file." << std::endl;
|
std::cout << "p21read - read a STEP Part 21 exchange file using SCL, and write the data to another file." << std::endl;
|
||||||
std::cout << "Syntax: " << exe << " [-i] [-s] infile [outfile]" << std::endl;
|
std::cout << "Syntax: " << exe << " [-i] [-s] infile [outfile]" << std::endl;
|
||||||
std::cout << "Use '-i' to ignore a schema name mismatch." << std::endl;
|
std::cout << "Use '-i' to ignore a schema name mismatch." << std::endl;
|
||||||
std::cout << "Use '-s' for strict interpretation (attributes that are \"missing and required\" will cause errors)." << std::endl;
|
std::cout << "Use '-s' for strict interpretation (attributes that are \"missing and required\" will cause errors)." << std::endl;
|
||||||
|
std::cout << "Use '-v' to print the version info below and exit." << std::endl;
|
||||||
std::cout << "Use '--' as the last argument if a file name starts with a dash." << std::endl;
|
std::cout << "Use '--' as the last argument if a file name starts with a dash." << std::endl;
|
||||||
|
printVersion(exe);
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +105,7 @@ int main( int argc, char * argv[] ) {
|
||||||
if( argc > 4 || argc < 2 ) {
|
if( argc > 4 || argc < 2 ) {
|
||||||
printUse(argv[0]);
|
printUse(argv[0]);
|
||||||
}
|
}
|
||||||
while( ( c = getopt( argc, argv, "is" ) ) != -1 ) {
|
while( ( c = getopt( argc, argv, "isv" ) ) != -1 ) {
|
||||||
switch( c ) {
|
switch( c ) {
|
||||||
case 'i':
|
case 'i':
|
||||||
ignoreErr = true;
|
ignoreErr = true;
|
||||||
|
|
@ -106,6 +113,9 @@ int main( int argc, char * argv[] ) {
|
||||||
case 's':
|
case 's':
|
||||||
strict = true;
|
strict = true;
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
printVersion(argv[0]);
|
||||||
|
exit(0);
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
printUse(argv[0]);
|
printUse(argv[0]);
|
||||||
|
|
@ -113,16 +123,14 @@ int main( int argc, char * argv[] ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// You have to initialize the schema before you do anything else.
|
// You have to initialize the schema before you do anything else.
|
||||||
// This initializes all of the registry information for the schema you
|
// This initializes all of the registry information for the schema you
|
||||||
// plan to use. The SchemaInit() function is generated by fedex_plus.
|
// plan to use. The SchemaInit() function is generated by fedex_plus.
|
||||||
// See the 'extern' stmt above.
|
// See the 'extern' stmt above.
|
||||||
//
|
//
|
||||||
// The registry is always going to be in memory.
|
// The registry is always going to be in memory.
|
||||||
//
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
Registry registry( SchemaInit );
|
Registry registry( SchemaInit );
|
||||||
InstMgr instance_list;
|
InstMgr instance_list;
|
||||||
STEPfile sfile( registry, instance_list, "", strict );
|
STEPfile sfile( registry, instance_list, "", strict );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue