Skip to content

Commit 19ee69d

Browse files
committed
Merge pull request BVLC#3311 from lukeyeager/bvlc/versioning
Add versioning to build and mark version 1.0.0-rc3
2 parents a97300c + 67b497d commit 19ee69d

File tree

8 files changed

+42
-10
lines changed

8 files changed

+42
-10
lines changed

CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ endif()
99
# ---[ Caffe project
1010
project(Caffe C CXX)
1111

12+
# ---[ Caffe version
13+
set(CAFFE_TARGET_VERSION "1.0.0-rc3")
14+
set(CAFFE_TARGET_SOVERSION "1.0.0-rc3")
15+
add_definitions(-DCAFFE_VERSION=${CAFFE_TARGET_VERSION})
16+
1217
# ---[ Using cmake scripts and modules
1318
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
1419

Makefile

+21-9
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ SRC_DIRS := $(shell find * -type d -exec bash -c "find {} -maxdepth 1 \
2929
\( -name '*.cpp' -o -name '*.proto' \) | grep -q ." \; -print)
3030

3131
# The target shared library name
32+
LIBRARY_NAME := $(PROJECT)
3233
LIB_BUILD_DIR := $(BUILD_DIR)/lib
33-
STATIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).a
34-
DYNAMIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).so
34+
STATIC_NAME := $(LIB_BUILD_DIR)/lib$(LIBRARY_NAME).a
35+
DYNAMIC_VERSION_MAJOR := 1
36+
DYNAMIC_VERSION_MINOR := 0
37+
DYNAMIC_VERSION_REVISION := 0-rc3
38+
DYNAMIC_NAME_SHORT := lib$(LIBRARY_NAME).so
39+
#DYNAMIC_SONAME_SHORT := $(DYNAMIC_NAME_SHORT).$(DYNAMIC_VERSION_MAJOR)
40+
DYNAMIC_VERSIONED_NAME_SHORT := $(DYNAMIC_NAME_SHORT).$(DYNAMIC_VERSION_MAJOR).$(DYNAMIC_VERSION_MINOR).$(DYNAMIC_VERSION_REVISION)
41+
DYNAMIC_NAME := $(LIB_BUILD_DIR)/$(DYNAMIC_VERSIONED_NAME_SHORT)
42+
COMMON_FLAGS += -DCAFFE_VERSION=$(DYNAMIC_VERSION_MAJOR).$(DYNAMIC_VERSION_MINOR).$(DYNAMIC_VERSION_REVISION)
3543

3644
##############################
3745
# Get all source files
@@ -253,6 +261,7 @@ ifeq ($(LINUX), 1)
253261
# boost::thread is reasonably called boost_thread (compare OS X)
254262
# We will also explicitly add stdc++ to the link target.
255263
LIBRARIES += boost_thread stdc++
264+
VERSIONFLAGS += -Wl,-soname,$(DYNAMIC_VERSIONED_NAME_SHORT) -Wl,-rpath,$(ORIGIN)/../lib
256265
endif
257266

258267
# OS X:
@@ -276,6 +285,7 @@ ifeq ($(OSX), 1)
276285
# we need to explicitly ask for the rpath to be obeyed
277286
DYNAMIC_FLAGS := -install_name @rpath/libcaffe.so
278287
ORIGIN := @loader_path
288+
VERSIONFLAGS += -Wl,-install_name,$(DYNAMIC_VERSIONED_NAME_SHORT) -Wl,-rpath,$(ORIGIN)/../../build/lib
279289
else
280290
ORIGIN := \$$ORIGIN
281291
endif
@@ -478,7 +488,7 @@ py: $(PY$(PROJECT)_SO) $(PROTO_GEN_PY)
478488
$(PY$(PROJECT)_SO): $(PY$(PROJECT)_SRC) $(PY$(PROJECT)_HXX) | $(DYNAMIC_NAME)
479489
@ echo CXX/LD -o $@ $<
480490
$(Q)$(CXX) -shared -o $@ $(PY$(PROJECT)_SRC) \
481-
-o $@ $(LINKFLAGS) -l$(PROJECT) $(PYTHON_LDFLAGS) \
491+
-o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(PYTHON_LDFLAGS) \
482492
-Wl,-rpath,$(ORIGIN)/../../build/lib
483493

484494
mat$(PROJECT): mat
@@ -542,7 +552,8 @@ $(ALL_BUILD_DIRS): | $(BUILD_DIR_LINK)
542552

543553
$(DYNAMIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
544554
@ echo LD -o $@
545-
$(Q)$(CXX) -shared -o $@ $(OBJS) $(LINKFLAGS) $(LDFLAGS) $(DYNAMIC_FLAGS)
555+
$(Q)$(CXX) -shared -o $@ $(OBJS) $(VERSIONFLAGS) $(LINKFLAGS) $(LDFLAGS) $(DYNAMIC_FLAGS)
556+
@ cd $(BUILD_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT); ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_NAME_SHORT)
546557

547558
$(STATIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
548559
@ echo AR -o $@
@@ -573,19 +584,19 @@ $(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
573584
| $(DYNAMIC_NAME) $(TEST_BIN_DIR)
574585
@ echo CXX/LD -o $@ $<
575586
$(Q)$(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
576-
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib
587+
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
577588

578589
$(TEST_CU_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CU_BUILD_DIR)/%.o \
579590
$(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
580591
@ echo LD $<
581592
$(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \
582-
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib
593+
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
583594

584595
$(TEST_CXX_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CXX_BUILD_DIR)/%.o \
585596
$(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
586597
@ echo LD $<
587598
$(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \
588-
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib
599+
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
589600

590601
# Target for extension-less symlinks to tool binaries with extension '*.bin'.
591602
$(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)
@@ -594,12 +605,12 @@ $(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)
594605

595606
$(TOOL_BINS): %.bin : %.o | $(DYNAMIC_NAME)
596607
@ echo CXX/LD -o $@
597-
$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(PROJECT) $(LDFLAGS) \
608+
$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
598609
-Wl,-rpath,$(ORIGIN)/../lib
599610

600611
$(EXAMPLE_BINS): %.bin : %.o | $(DYNAMIC_NAME)
601612
@ echo CXX/LD -o $@
602-
$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(PROJECT) $(LDFLAGS) \
613+
$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
603614
-Wl,-rpath,$(ORIGIN)/../../lib
604615

605616
proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER)
@@ -661,6 +672,7 @@ $(DISTRIBUTE_DIR): all py | $(DISTRIBUTE_SUBDIRS)
661672
# add libraries
662673
cp $(STATIC_NAME) $(DISTRIBUTE_DIR)/lib
663674
install -m 644 $(DYNAMIC_NAME) $(DISTRIBUTE_DIR)/lib
675+
cd $(DISTRIBUTE_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT); ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_NAME_SHORT)
664676
# add python - it's not the standard way, indeed...
665677
cp -r python $(DISTRIBUTE_DIR)/python
666678

cmake/Summary.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function(caffe_print_configuration_summary)
101101
caffe_status("")
102102
caffe_status("******************* Caffe Configuration Summary *******************")
103103
caffe_status("General:")
104-
caffe_status(" Version : ${Caffe_VERSION}")
104+
caffe_status(" Version : ${CAFFE_TARGET_VERSION}")
105105
caffe_status(" Git : ${Caffe_GIT_VERSION}")
106106
caffe_status(" System : ${CMAKE_SYSTEM_NAME}")
107107
caffe_status(" C++ compiler : ${CMAKE_CXX_COMPILER}")

include/caffe/common.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
#include "caffe/util/device_alternate.hpp"
2020

21+
// Convert macro to string
22+
#define STRINGIFY(m) #m
23+
#define AS_STRING(m) STRINGIFY(m)
24+
2125
// gflags 2.1 issue: namespace google was changed to gflags without warning.
2226
// Luckily we will be able to use GFLAGS_GFLAGS_H_ to detect if it is version
2327
// 2.1. If yes, we will add a temporary solution to redirect the namespace.

python/caffe/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
22
from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list
3+
from ._caffe import __version__
34
from .proto.caffe_pb2 import TRAIN, TEST
45
from .classifier import Classifier
56
from .detector import Detector

python/caffe/_caffe.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(SolveOverloads, Solve, 0, 1);
212212
BOOST_PYTHON_MODULE(_caffe) {
213213
// below, we prepend an underscore to methods that will be replaced
214214
// in Python
215+
216+
bp::scope().attr("__version__") = AS_STRING(CAFFE_VERSION);
217+
215218
// Caffe utility functions
216219
bp::def("set_mode_cpu", &set_mode_cpu);
217220
bp::def("set_mode_gpu", &set_mode_gpu);

src/caffe/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ endif()
2020
add_library(caffe ${srcs})
2121
target_link_libraries(caffe proto ${Caffe_LINKER_LIBS})
2222
caffe_default_properties(caffe)
23+
set_target_properties(caffe PROPERTIES
24+
VERSION ${CAFFE_TARGET_VERSION}
25+
SOVERSION ${CAFFE_TARGET_SOVERSION}
26+
)
2327

2428
# ---[ Tests
2529
add_subdirectory(test)

tools/caffe.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace bp = boost::python;
44
#endif
55

6+
#include <gflags/gflags.h>
67
#include <glog/logging.h>
78

89
#include <cstring>
@@ -378,6 +379,8 @@ RegisterBrewFunction(time);
378379
int main(int argc, char** argv) {
379380
// Print output to stderr (while still logging).
380381
FLAGS_alsologtostderr = 1;
382+
// Set version
383+
gflags::SetVersionString(AS_STRING(CAFFE_VERSION));
381384
// Usage message.
382385
gflags::SetUsageMessage("command line brew\n"
383386
"usage: caffe <command> <args>\n\n"

0 commit comments

Comments
 (0)