mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-17 11:45:50 +00:00
Add an option to compile the build date into dindexer's binary
This commit is contained in:
parent
cb9b1c3bee
commit
343c44add5
6 changed files with 80 additions and 1 deletions
|
@ -19,6 +19,7 @@ include(GetGitRevisionDescription)
|
|||
include(Buildlibpqtypes)
|
||||
include(gccversion)
|
||||
include(CPack)
|
||||
include(timestamp)
|
||||
|
||||
option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF)
|
||||
option(DINDEXER_WITH_MEDIA_AUTODETECT "Enable code that tries to autodetect the media type and sets --type automatically" ON)
|
||||
|
|
40
cmake/Modules/timestamp.cmake
Normal file
40
cmake/Modules/timestamp.cmake
Normal file
|
@ -0,0 +1,40 @@
|
|||
if (NOT bare_name)
|
||||
message(FATAL_ERROR "bare_name variable not defined")
|
||||
endif()
|
||||
|
||||
string(TOUPPER "${bare_name}" bare_name_upper)
|
||||
|
||||
option(${bare_name_upper}_WITH_BUILD_DATE "Compile the build date into the program. It will cause frequent rebuilds" OFF)
|
||||
string(TOUPPER ${${bare_name_upper}_WITH_BUILD_DATE} ${bare_name_upper}_WITH_BUILD_DATE PARENT_SCOPE)
|
||||
|
||||
#See:
|
||||
#http://stackoverflow.com/questions/24292898/compile-date-and-time-using-cmake#26214363
|
||||
function (make_timestamp project_name file_input)
|
||||
# if (${bare_name_upper}_WITH_BUILD_DATE)
|
||||
# string(TIMESTAMP ${bare_name_upper}_BUILD_DATE "%Y-%m-%d %H:%M:%S" UTC)
|
||||
# else()
|
||||
# set(${bare_name_upper}_BUILD_DATE "")
|
||||
# endif()
|
||||
get_filename_component(file_name "${file_input}" NAME)
|
||||
string(REGEX REPLACE "\\.in$" "" file_name "${file_name}")
|
||||
|
||||
FILE (WRITE ${CMAKE_CURRENT_BINARY_DIR}/timestamp.cmake
|
||||
"if (${bare_name_upper}_WITH_BUILD_DATE)
|
||||
# string(TIMESTAMP ${bare_name_upper}_BUILD_DATE \"%Y-%m-%d %H:%M:%S\" UTC)
|
||||
string(TIMESTAMP ${bare_name_upper}_BUILD_DATE \"%Y-%m-%d %H:%M:%S\" UTC)
|
||||
else()
|
||||
set(${bare_name_upper}_BUILD_DATE \"\")
|
||||
endif()
|
||||
#set(${bare_name_upper}_BUILD_DATE \"$\{${bare_name_upper}_BUILD_DATE}\" PARENT_SCOPE)
|
||||
configure_file(\"${CMAKE_CURRENT_SOURCE_DIR}/${file_input}\" \"${CMAKE_CURRENT_BINARY_DIR}/${file_name}\")\n"
|
||||
)
|
||||
|
||||
add_custom_target (
|
||||
timestamp
|
||||
COMMAND ${CMAKE_COMMAND} "-D${bare_name_upper}_WITH_BUILD_DATE=${${bare_name_upper}_WITH_BUILD_DATE}" -P ${CMAKE_CURRENT_BINARY_DIR}/timestamp.cmake
|
||||
ADD_DEPENDENCIES ${CMAKE_CURRENT_BINARY_DIR}/timestamp.cmake
|
||||
)
|
||||
|
||||
add_dependencies(${project_name} timestamp)
|
||||
#set_source_files_properties("${PROJECT_BINARY_DIR}/${bare_name}Config.h" OBJECT_DEPENDS timestamp)
|
||||
endfunction()
|
|
@ -17,6 +17,6 @@ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /u
|
|||
echo 3 | sudo update-alternatives --config gcc
|
||||
mkdir dindexer_build
|
||||
cd dindexer_build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ../dindexer
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DDINDEXER_WITH_BUILD_DATE=on ../dindexer
|
||||
make
|
||||
make package
|
||||
|
|
|
@ -10,9 +10,11 @@ add_executable(${PROJECT_NAME}
|
|||
utf8_ops.c
|
||||
)
|
||||
|
||||
make_timestamp(${bare_name} timestamp.h.in)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/include
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/lib/pbl/pbl/src/src
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "builtin_feats.h"
|
||||
#include <stdio.h>
|
||||
#include "dindexerConfig.h"
|
||||
#include "timestamp.h"
|
||||
|
||||
void print_builtin_feats() {
|
||||
print_version();
|
||||
|
@ -42,6 +43,9 @@ void print_builtin_feats() {
|
|||
printf(" %s %s\n", CMAKE_CXX_COMPILER, CMAKE_CXX_FLAGS);
|
||||
printf(" %s %s\n", CMAKE_C_COMPILER, CMAKE_C_FLAGS);
|
||||
printf("DB_OWNER_NAME = \"%s\"\n", DB_OWNER_NAME);
|
||||
#if defined(DINDEXER_BUILD_DATE)
|
||||
printf("BUILD_DATE = %s\n", DINDEXER_BUILD_DATE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void print_version() {
|
||||
|
|
32
src/main/timestamp.h.in
Normal file
32
src/main/timestamp.h.in
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Copyright 2015, 2016, Michele Santullo
|
||||
* This file is part of "dindexer".
|
||||
*
|
||||
* "dindexer" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "dindexer" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef id4A9E94ACFA43498097637025A5BA69E5
|
||||
#define id4A9E94ACFA43498097637025A5BA69E5
|
||||
|
||||
#if !defined(CMAKE_ON)
|
||||
# define CMAKE_ON 1
|
||||
#endif
|
||||
#if !defined(CMAKE_OFF)
|
||||
# define CMAKE_OFF 0
|
||||
#endif
|
||||
|
||||
#if CMAKE_@DINDEXER_WITH_BUILD_DATE@
|
||||
# define DINDEXER_BUILD_DATE "@DINDEXER_BUILD_DATE@"
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue