Skip to content

Commit db0244e

Browse files
author
befulton
committed
Make GIT information in the version optional
And off by default. Add a command to build a source distribution.
1 parent fc3da5a commit db0244e

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

CMakeLists.txt

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ set(OPTIMIZER_STRATEGY "NelderMead" CACHE STRING "Optimizer strategy (LBFGS, Nel
3838
set(DISCRETIZATION_RANGE "200" CACHE STRING "How finely to divide the continuous range")
3939
option(MODEL_GENE_EXPRESSION_LOGS "Perform calculations using log values rather than linear values" ON)
4040
option(USE_MAX_PROBABILITY "Evaluate probability as maximum value rather than cumulative" OFF)
41+
option(INCLUDE_GIT_IN_VERSION_INFO "Write information about the last GIT commit into version info" OFF)
4142

4243
if (MODEL_GENE_EXPRESSION_LOGS)
4344
add_definitions(-DMODEL_GENE_EXPRESSION_LOGS)
@@ -50,16 +51,20 @@ endif()
5051
add_definitions(-DOPTIMIZER_STRATEGY=${OPTIMIZER_STRATEGY})
5152
add_definitions(-DDISCRETIZATION_RANGE=${DISCRETIZATION_RANGE})
5253

53-
# Define the two required variables before including
54-
# the source code for watching a git repository.
55-
set(PRE_CONFIGURE_FILE "git_version.cpp.in")
56-
set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp")
57-
include(git_watcher.cmake)
5854

59-
# Create a library out of the compiled post-configure file.
60-
add_library(git STATIC ${POST_CONFIGURE_FILE})
61-
target_include_directories(git PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
62-
add_dependencies(git check_git)
55+
if (INCLUDE_GIT_IN_VERSION_INFO)
56+
# Define the two required variables before including
57+
# the source code for watching a git repository.
58+
set(PRE_CONFIGURE_FILE "git_version.cpp.in")
59+
set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp")
60+
include(git_watcher.cmake)
61+
62+
# Create a library out of the compiled post-configure file.
63+
add_definitions(-DINCLUDE_GIT_IN_VERSION_INFO)
64+
add_library(git STATIC ${POST_CONFIGURE_FILE})
65+
target_include_directories(git PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
66+
add_dependencies(git check_git)
67+
endif()
6368

6469
# add the executable
6570
add_executable(cagee main.cpp)
@@ -77,8 +82,10 @@ add_subdirectory(src)
7782

7883
link_libraries(Eigen3::Eigen)
7984

80-
target_link_libraries(cagee PRIVATE git)
81-
target_link_libraries(tests PRIVATE git)
85+
if (INCLUDE_GIT_IN_VERSION_INFO)
86+
target_link_libraries(cagee PRIVATE git)
87+
target_link_libraries(tests PRIVATE git)
88+
endif()
8289

8390
find_package(ZLIB)
8491
target_link_libraries(cagee PRIVATE ZLIB::ZLIB)

build_dist.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mkdir distro
2+
3+
tar --transform "s,^,CAGEE/," --owner=0 --group=0 -czf distro/CAGEE0.1.0.0.tar.gz src test.cpp main.cpp diffmat_precalc.cpp CHANGELOG.md LICENSE CMakeLists.txt README.md config.h.in examples LBFGSpp/

src/arguments.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ namespace po = boost::program_options;
1111

1212
#include "arguments.h"
1313
#include "io.h"
14+
15+
#ifdef INCLUDE_GIT_IN_VERSION_INFO
1416
#include "../git_version.h"
17+
#endif
1518

1619
using namespace std;
1720

@@ -33,6 +36,7 @@ void show_version()
3336
cout << PROJECT_NAME " " PROJECT_VER << endl;
3437
cout << desc;
3538

39+
#ifdef INCLUDE_GIT_IN_VERSION_INFO
3640
if (GitMetadata::Populated()) {
3741
cout << "Last git commit: \n";
3842
if (GitMetadata::AnyUncommittedChanges()) {
@@ -44,6 +48,7 @@ void show_version()
4448
<< "Date: " << GitMetadata::CommitDate() << "\n\n"
4549
<< GitMetadata::CommitSubject() << "\n" << GitMetadata::CommitBody() << std::endl;
4650
}
51+
#endif
4752
}
4853
void show_help(const po::options_description& gen, const po::options_description& required, const po::options_description& common, const po::options_description& rare)
4954
{

0 commit comments

Comments
 (0)