Browse Source

* use cmake

master
Alex 'AdUser' Z 9 years ago
parent
commit
b83c53a86a
  1. 14
      CMakeLists.txt
  2. 20
      src/CMakeLists.txt
  3. 50
      src/Makefile
  4. 5
      tests/CMakeLists.txt
  5. 14
      tests/Makefile

14
CMakeLists.txt

@ -0,0 +1,14 @@
set(CNAME "libimgdup")
set(VERSION 0.3)
project($CNAME C)
cmake_minimum_required(VERSION 2.6)
include(CTest)
set(CMAKE_INSTALL_PREFIX "/usr/local")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c99")
add_subdirectory(src)
add_subdirectory("tests")
set_property(DIRECTORY "tests" PROPERTY COMPILE_FLAGS "-g;-ggdb;-Wall;-Wextra;-pedantic;-O0")

20
src/CMakeLists.txt

@ -0,0 +1,20 @@
set(LIB_SOURCES "database.c" "bitmap.c")
add_library("imgdup" SHARED ${LIB_SOURCES})
set_property(TARGET "imgdup" PROPERTY SONAME ${VERSION})
install(TARGETS "imgdup" LIBRARY DESTINATION "lib")
add_executable("imdb-1to2" "imdb-1to2.c")
install(TARGETS "imdb-1to2" RUNTIME DESTINATION "bin")
add_executable("imdb-query" "imdb-query.c")
target_link_libraries("imdb-query" "imgdup")
install(TARGETS "imdb-query" RUNTIME DESTINATION "bin")
find_package(ImageMagick COMPONENTS MagickCore MagickWand)
add_executable("imdb-write" "imdb-write.c" "sample.c")
target_link_libraries("imdb-write" "imgdup")
target_link_libraries("imdb-write" ${ImageMagick_MagickCore_LIBRARY})
target_link_libraries("imdb-write" ${ImageMagick_MagickWand_LIBRARY})
install(TARGETS "imdb-write" RUNTIME DESTINATION "bin")

50
src/Makefile

@ -1,50 +0,0 @@
CFLAGS=-Wall -Wextra -O2 -g -std=c99 -pedantic -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security
CPPFLAGS=-D_FORTIFY_SOURCE=2
SONAME=libimgdup.so.3
LDFLAGS=-Wl,-soname,$(SONAME) -fPIC
PREFIX ?= /usr/local
all: libs utils
%.o: %.c
gcc $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -c $<
libimgdup.so: database.o bitmap.o
gcc $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -o $(SONAME) $^
ln -sf $(SONAME) libimgdup.so
libimgdup.a: database.o bitmap.o
ar rcs libimgdup.a $^
libs: libimgdup.so libimgdup.a
imdb-query: imdb-query.o libimgdup.so
gcc $(CFLAGS) $(CPPFLAGS) -L. $< -o $@ -limgdup
imdb-query-st: imdb-query.o libimgdup.a
gcc $(CFLAGS) $(CPPFLAGS) -L. $^ -o $@ -static
imdb-1to2: imdb-1to2.c
gcc $(CFLAGS) $(CPPFLAGS) -o $@ $^
GMFLAGS=$(shell GraphicsMagickWand-config --cppflags --ldflags --libs)
imdb-write: imdb-write.c sample.c bitmap.c database.c
gcc $(CFLAGS) $(CPPFLAGS) -L. $(GMFLAGS) -o $@ $^ -limgdup
utils: imdb-query imdb-query-st imdb-write imdb-1to2
install: libimgdup.so utils
install -m755 -s -o root imdb-query $(PREFIX)/bin
install -m755 -s -o root imdb-write $(PREFIX)/bin
install -m755 -s -o root imdb-1to2 $(PREFIX)/bin
install -m644 -s -o root $(SONAME) $(PREFIX)/lib
(cd $(PREFIX)/lib && ln -sf $(SONAME) libimgdup.so)
ldconfig
clean:
rm -f *.o
rm -f imdb-1to2
rm -f imdb-query
rm -f imdb-query-st
rm -f imdb-write
rm -f libimgdup*

5
tests/CMakeLists.txt

@ -0,0 +1,5 @@
add_executable("test-bitmap" "bitmap.c" "../src/bitmap.c")
add_test("test/bitmap" "test-bitmap")
add_executable("test-database" "database.c" "../src/database.c" "../src/bitmap.c")
add_test("test/database" "test-database")

14
tests/Makefile

@ -1,14 +0,0 @@
TESTS=test-bitmap test-database
all: $(TESTS)
CFLAGS=-Wall -Wextra -O0 -g -ggdb -pedantic
%.o: %.c
gcc $(CFLAGS) -o $@ $<
test-%: ../src/%.c %.c
gcc $(CFLAGS) $(SRC) -o $@ $^
clean:
rm -f $(TESTS)
Loading…
Cancel
Save