Skip to content

Commit 6c1bdcd

Browse files
committed
Add library versioning to Make/CMake build systems
See raysan5#401 for the discussion.
1 parent de78fa6 commit 6c1bdcd

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
project(raylib)
33
include("../utils.cmake")
44

5-
set(PROJECT_VERSION 1.9.1-dev)
5+
set(PROJECT_VERSION 1.9.2)
6+
set(API_VERSION 1)
67
set(RAYLIB raylib) # Name of the generated library
78

89
### Config options ###
@@ -123,7 +124,11 @@ if(${PLATFORM} MATCHES "PLATFORM_DESKTOP")
123124
set(CMAKE_MACOSX_RPATH ON)
124125

125126
target_link_libraries(${RAYLIB}_shared ${LIBS_PRIVATE})
126-
set_target_properties(${RAYLIB}_shared PROPERTIES PUBLIC_HEADER "raylib.h")
127+
set_target_properties(${RAYLIB}_shared PROPERTIES
128+
VERSION ${PROJECT_VERSION}
129+
SOVERSION ${API_VERSION}
130+
PUBLIC_HEADER "raylib.h"
131+
)
127132
if(WIN32)
128133
install(
129134
TARGETS ${RAYLIB}_shared

src/Makefile

+27-12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
.PHONY: all clean install uninstall
4343

4444
# Define required raylib variables
45+
VERSION = 1.9.2
46+
API_VERSION = 1
4547
PLATFORM ?= PLATFORM_DESKTOP
4648
RAYLIB_PATH = ..
4749

@@ -172,6 +174,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
172174
ifeq ($(PLATFORM_OS),OSX)
173175
# OSX default compiler
174176
CC = clang
177+
GLFW_CFLAGS = -x objective-c
175178
endif
176179
ifeq ($(PLATFORM_OS),FREEBSD)
177180
# FreeBSD default compiler
@@ -291,7 +294,7 @@ endif
291294

292295
# Define linker options
293296
ifeq ($(PLATFORM),PLATFORM_ANDROID)
294-
LDFLAGS = -Wl,-soname,libraylib.so -Wl,--exclude-libs,libatomic.a
297+
LDFLAGS = -Wl,-soname,libraylib.$(API_VERSION).so -Wl,--exclude-libs,libatomic.a
295298
LDFLAGS += -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings
296299
# Force linking of library module to define symbol
297300
LDFLAGS += -u ANativeActivity_onCreate
@@ -353,22 +356,30 @@ else
353356
ifeq ($(PLATFORM_OS),LINUX)
354357
# Compile raylib to shared library version for GNU/Linux.
355358
# WARNING: you should type "make clean" before doing this target
356-
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/libraylib.so $(OBJS) -lGL -lm -lpthread -ldl -lrt
357-
@echo "raylib shared library generated (libraylib.so)!"
359+
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/libraylib.$(VERSION).so $(OBJS) -Wl,-soname,libraylib.$(API_VERSION).so -lGL -lm -lpthread -ldl -lrt
360+
@echo "raylib shared library generated (libraylib.$(VERSION).so)!"
361+
cd $(RAYLIB_RELEASE_PATH) && ln -s libraylib.$(VERSION).so libraylib.$(API_VERSION).so
362+
cd $(RAYLIB_RELEASE_PATH) && ln -s libraylib.$(VERSION).so libraylib.so
358363
endif
359364
ifeq ($(PLATFORM_OS),OSX)
360-
$(CC) -dynamiclib -o $(RAYLIB_RELEASE_PATH)/libraylib.dylib $(OBJS) -L/usr/local/Cellar/glfw/3.2.1/lib -framework OpenGL -framework OpenAL -framework Cocoa
361-
install_name_tool -id "libraylib.dylib" $(RAYLIB_RELEASE_PATH)/libraylib.dylib
362-
@echo "raylib shared library generated (libraylib.dylib)!"
365+
$(CC) -dynamiclib -o $(RAYLIB_RELEASE_PATH)/libraylib.$(VERSION).dylib $(OBJS) -compatibility_version $(API_VERSION) -current_version $(VERSION) -framework OpenGL -framework OpenAL -framework IOKit -framework CoreVideo -framework Cocoa
366+
install_name_tool -id "libraylib.$(VERSION).dylib" $(RAYLIB_RELEASE_PATH)/libraylib.$(VERSION).dylib
367+
@echo "raylib shared library generated (libraylib.$(VERSION).dylib)!"
368+
cd $(RAYLIB_RELEASE_PATH) && ln -s libraylib.$(VERSION).dylib libraylib.$(API_VERSION).dylib
369+
cd $(RAYLIB_RELEASE_PATH) && ln -s libraylib.$(VERSION).dylib libraylib.dylib
363370
endif
364371
ifeq ($(PLATFORM_OS),FREEBSD)
365372
# WARNING: you should type "gmake clean" before doing this target
366-
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/libraylib.so $(OBJS) -lGL -lpthread
367-
@echo "raylib shared library generated (libraylib.so)!"
373+
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/libraylib.$(VERSION).so $(OBJS) -Wl,-soname,libraylib.$(API_VERSION).so -lGL -lpthread
374+
@echo "raylib shared library generated (libraylib.$(VERSION).so)!"
375+
cd $(RAYLIB_RELEASE_PATH) && ln -s libraylib.$(VERSION).so libraylib.$(API_VERSION).so
376+
cd $(RAYLIB_RELEASE_PATH) && ln -s libraylib.$(VERSION).so libraylib.so
368377
endif
369378
ifeq ($(PLATFORM),PLATFORM_ANDROID)
370-
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/libraylib.so $(OBJS) $(LDFLAGS) $(LDLIBS)
371-
@echo "raylib shared library generated (libraylib.so)!"
379+
$(CC) -shared -o $(RAYLIB_RELEASE_PATH)/libraylib.$(VERSION).so $(OBJS) $(LDFLAGS) $(LDLIBS)
380+
@echo "raylib shared library generated (libraylib.$(VERSION).so)!"
381+
cd $(RAYLIB_RELEASE_PATH) && ln -s libraylib.$(VERSION).so libraylib.$(API_VERSION).so
382+
cd $(RAYLIB_RELEASE_PATH) && ln -s libraylib.$(VERSION).so libraylib.so
372383
endif
373384
else
374385
# Compile raylib static library
@@ -386,7 +397,7 @@ core.o : core.c raylib.h rlgl.h utils.h raymath.h gestures.h
386397

387398
# Compile rglfw module
388399
rglfw.o : rglfw.c
389-
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
400+
$(CC) $(GLFW_CFLAGS) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
390401

391402
# Compile rlgl module
392403
rlgl.o : rlgl.c rlgl.h raymath.h
@@ -434,6 +445,8 @@ ifeq ($(ROOT),root)
434445
# /usr/local/include/) are for libraries that are installed
435446
# manually (without a package manager).
436447
ifeq ($(RAYLIB_LIBTYPE),SHARED)
448+
cp --update $(RAYLIB_RELEASE_PATH)/libraylib.$(VERSION).so /usr/local/lib/libraylib.$(VERSION).so
449+
cp --update $(RAYLIB_RELEASE_PATH)/libraylib.$(API_VERSION).so /usr/local/lib/libraylib.$(API_VERSION).so
437450
cp --update $(RAYLIB_RELEASE_PATH)/libraylib.so /usr/local/lib/libraylib.so
438451
else
439452
cp --update raylib.h /usr/local/include/raylib.h
@@ -455,6 +468,8 @@ ifeq ($(ROOT),root)
455468
rm --force /usr/local/include/raylib.h
456469
ifeq ($(RAYLIB_LIBTYPE),SHARED)
457470
rm --force /usr/local/lib/libraylib.so
471+
rm --force /usr/local/lib/libraylib.$(API_VERSION).so
472+
rm --force /usr/local/lib/libraylib.$(VERSION).so
458473
else
459474
rm --force /usr/local/lib/libraylib.a
460475
endif
@@ -471,7 +486,7 @@ clean:
471486
ifeq ($(PLATFORM_OS),WINDOWS)
472487
del *.o $(RAYLIB_RELEASE_PATH)/libraylib.a $(RAYLIB_RELEASE_PATH)/libraylib.bc $(RAYLIB_RELEASE_PATH)/libraylib.so external/stb_vorbis.o
473488
else
474-
rm -f *.o $(RAYLIB_RELEASE_PATH)/libraylib.a $(RAYLIB_RELEASE_PATH)/libraylib.bc $(RAYLIB_RELEASE_PATH)/libraylib.so external/stb_vorbis.o
489+
rm -f *.o $(RAYLIB_RELEASE_PATH)/libraylib.a $(RAYLIB_RELEASE_PATH)/libraylib.bc $(RAYLIB_RELEASE_PATH)/libraylib.so $(RAYLIB_RELEASE_PATH)/libraylib.$(API_VERSION).so $(RAYLIB_RELEASE_PATH)/libraylib.$(VERSION).so external/stb_vorbis.o
475490
endif
476491
ifeq ($(PLATFORM),PLATFORM_ANDROID)
477492
rm -rf $(ANDROID_TOOLCHAIN)

0 commit comments

Comments
 (0)