Skip to content

Commit 2812b9c

Browse files
committed
Mark version 1.0.0
Add versioning to: * shared library (libcaffe.so) * both build systems * caffe binary (caffe --version) * python module (caffe.__version__) TODO: matlab
1 parent 5a302a2 commit 2812b9c

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-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")
14+
set(CAFFE_TARGET_SOVERSION "1.0")
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

+23-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
38+
DYNAMIC_NAME_SHORT := lib$(LIBRARY_NAME).so
39+
DYNAMIC_SONAME_SHORT := $(DYNAMIC_NAME_SHORT).$(DYNAMIC_VERSION_MAJOR).$(DYNAMIC_VERSION_MINOR)
40+
DYNAMIC_VERSIONED_NAME_SHORT := $(DYNAMIC_SONAME_SHORT).$(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_SONAME_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_SONAME_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,9 @@ $(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_SONAME_SHORT); ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_SONAME_SHORT)
557+
@ cd $(BUILD_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT); ln -s $(DYNAMIC_SONAME_SHORT) $(DYNAMIC_NAME_SHORT)
546558

547559
$(STATIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
548560
@ echo AR -o $@
@@ -573,19 +585,19 @@ $(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
573585
| $(DYNAMIC_NAME) $(TEST_BIN_DIR)
574586
@ echo CXX/LD -o $@ $<
575587
$(Q)$(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
576-
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib
588+
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
577589

578590
$(TEST_CU_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CU_BUILD_DIR)/%.o \
579591
$(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
580592
@ echo LD $<
581593
$(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \
582-
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib
594+
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
583595

584596
$(TEST_CXX_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CXX_BUILD_DIR)/%.o \
585597
$(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
586598
@ echo LD $<
587599
$(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \
588-
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib
600+
-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
589601

590602
# Target for extension-less symlinks to tool binaries with extension '*.bin'.
591603
$(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)
@@ -594,12 +606,12 @@ $(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)
594606

595607
$(TOOL_BINS): %.bin : %.o | $(DYNAMIC_NAME)
596608
@ echo CXX/LD -o $@
597-
$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(PROJECT) $(LDFLAGS) \
609+
$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
598610
-Wl,-rpath,$(ORIGIN)/../lib
599611

600612
$(EXAMPLE_BINS): %.bin : %.o | $(DYNAMIC_NAME)
601613
@ echo CXX/LD -o $@
602-
$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(PROJECT) $(LDFLAGS) \
614+
$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
603615
-Wl,-rpath,$(ORIGIN)/../../lib
604616

605617
proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER)
@@ -661,6 +673,8 @@ $(DISTRIBUTE_DIR): all py | $(DISTRIBUTE_SUBDIRS)
661673
# add libraries
662674
cp $(STATIC_NAME) $(DISTRIBUTE_DIR)/lib
663675
cp $(DYNAMIC_NAME) $(DISTRIBUTE_DIR)/lib
676+
cd $(DISTRIBUTE_DIR)/lib; rm -f $(DYNAMIC_SONAME_SHORT); ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_SONAME_SHORT)
677+
cd $(DISTRIBUTE_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT); ln -s $(DYNAMIC_SONAME_SHORT) $(DYNAMIC_NAME_SHORT)
664678
# add python - it's not the standard way, indeed...
665679
cp -r python $(DISTRIBUTE_DIR)/python
666680

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}")

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 CAFFE_VERSION as __version__
34
from .proto.caffe_pb2 import TRAIN, TEST
45
from .classifier import Classifier
56
from .detector import Detector

python/caffe/_caffe.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#define PyArray_SetBaseObject(arr, x) (PyArray_BASE(arr) = (x))
2626
#endif
2727

28+
// Hack to convert macro to string
29+
#define STRINGIZE(m) #m
30+
#define STRINGIZE2(m) STRINGIZE(m)
31+
2832
namespace bp = boost::python;
2933

3034
namespace caffe {
@@ -211,6 +215,9 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(SolveOverloads, Solve, 0, 1);
211215
BOOST_PYTHON_MODULE(_caffe) {
212216
// below, we prepend an underscore to methods that will be replaced
213217
// in Python
218+
219+
bp::scope().attr("CAFFE_VERSION") = STRINGIZE2(CAFFE_VERSION);
220+
214221
// Caffe utility functions
215222
bp::def("set_mode_cpu", &set_mode_cpu);
216223
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

+7
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>
@@ -63,6 +64,10 @@ class __Registerer_##func { \
6364
__Registerer_##func g_registerer_##func; \
6465
}
6566

67+
// Hack to convert macro to string
68+
#define STRINGIZE(m) #m
69+
#define STRINGIZE2(m) STRINGIZE(m)
70+
6671
static BrewFunction GetBrewFunction(const caffe::string& name) {
6772
if (g_brew_map.count(name)) {
6873
return g_brew_map[name];
@@ -378,6 +383,8 @@ RegisterBrewFunction(time);
378383
int main(int argc, char** argv) {
379384
// Print output to stderr (while still logging).
380385
FLAGS_alsologtostderr = 1;
386+
// Set version
387+
gflags::SetVersionString(STRINGIZE2(CAFFE_VERSION));
381388
// Usage message.
382389
gflags::SetUsageMessage("command line brew\n"
383390
"usage: caffe <command> <args>\n\n"

0 commit comments

Comments
 (0)