Skip to content

Commit caf79f8

Browse files
ceejatecavsej
authored andcommitted
Prevent full rebuild on every run of cmake
config.h is generated by CMake's configure_file(), which is normally smart enough to not update the file's timestamp if the file is unchanged. However, config.h.in #defines LCB_BUILD_TIMESTAMP which will be different every time CMake is run. This means config.h will be updated every time, and since most .cc files directly or indirectly include config.h, this causes almost everything to be recompiled. This change introduces a separate build-timestamp.h.in, which contains only #define LCB_BUILD_TIMESTAMP. This in turn is only included by a new file cbc-timestamp.cc, which defines a const global variable lcb_build_timestamp with that value. Thus, only this tiny file will get rebuilt every time CMake is run. Change-Id: I67c78fed4c33be911427dfe1dfd97a258eb2e197 Reviewed-on: https://review.couchbase.org/c/libcouchbase/+/201943 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
1 parent 42c6854 commit caf79f8

7 files changed

Lines changed: 59 additions & 3 deletions

File tree

cmake/Modules/GenerateConfigDotH.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ ENDIF()
3434
CONFIGURE_FILE(
3535
${PROJECT_SOURCE_DIR}/cmake/config-cmake.h.in
3636
${LCB_GENSRCDIR}/config.h)
37+
CONFIGURE_FILE(
38+
${PROJECT_SOURCE_DIR}/cmake/build-timestamp.h.in
39+
${LCB_GENSRCDIR}/build-timestamp.h)

cmake/build-timestamp.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define LCB_BUILD_TIMESTAMP "${LCB_BUILD_TIMESTAMP}"

cmake/config-cmake.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
#define LCB_CXX_FLAGS "${CMAKE_CXX_FLAGS}"
6969
#define LCB_C_COMPILER "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}"
7070
#define LCB_C_FLAGS "${CMAKE_C_FLAGS}"
71-
#define LCB_BUILD_TIMESTAMP "${LCB_BUILD_TIMESTAMP}"
7271

7372
#define LCB_CLIENT_ID \
7473
"libcouchbase/" LCB_VERSION_STRING " (" LCB_SYSTEM "; " LCB_SYSTEM_PROCESSOR "; " LCB_C_COMPILER ")"

tools/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ INCLUDE_DIRECTORIES(${SOURCE_ROOT}/contrib/cliopts)
22
FILE(GLOB T_COMMONSRC common/*.cc)
33
ADD_LIBRARY(lcbtools OBJECT ${T_COMMONSRC})
44

5-
ADD_EXECUTABLE(cbc cbc.cc
5+
ADD_EXECUTABLE(cbc cbc.cc cbc-timestamp.cc
66
$<TARGET_OBJECTS:lcbtools> $<TARGET_OBJECTS:cliopts> $<TARGET_OBJECTS:lcb_jsoncpp>)
77
TARGET_LINK_LIBRARIES(cbc couchbase)
88

tools/cbc-timestamp.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2011-2020 Couchbase, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "cbc-timestamp.h"
19+
#include "build-timestamp.h"
20+
21+
namespace cbc {
22+
23+
const char *const lcb_build_timestamp = LCB_BUILD_TIMESTAMP;
24+
25+
} // namespace cbc

tools/cbc-timestamp.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2011-2020 Couchbase, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef CBC_TIMESTAMP_H
19+
#define CBC_TIMESTAMP_H
20+
21+
namespace cbc {
22+
23+
extern const char *const lcb_build_timestamp;
24+
25+
} // namespace cbc
26+
27+
#endif

tools/cbc.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "common/options.h"
3636
#include "common/histogram.h"
3737
#include "cbc-handlers.h"
38+
#include "cbc-timestamp.h"
3839
#include "connspec.h"
3940
#include "rnd.h"
4041
#include "contrib/lcb-jsoncpp/lcb-jsoncpp.h"
@@ -1227,7 +1228,7 @@ void VersionHandler::run()
12271228
printf("cbc:\n");
12281229
printf(" Runtime: Version=%s, Changeset=%s\n", lcb_get_version(nullptr), changeset);
12291230
printf(" Headers: Version=%s, Changeset=%s\n", LCB_VERSION_STRING, LCB_VERSION_CHANGESET);
1230-
printf(" Build Timestamp: %s\n", LCB_BUILD_TIMESTAMP);
1231+
printf(" Build Timestamp: %s\n", lcb_build_timestamp);
12311232
#ifdef CMAKE_BUILD_TYPE
12321233
printf(" CMake Build Type: %s\n", CMAKE_BUILD_TYPE);
12331234
#endif

0 commit comments

Comments
 (0)