replace the existing build system with cmake
authorFelix Fietkau <nbd@openwrt.org>
Sat, 26 Mar 2011 20:40:51 +0000 (21:40 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 26 Mar 2011 20:40:51 +0000 (21:40 +0100)
.gitignore
CMakeLists.txt [new file with mode: 0644]
Makefile [deleted file]
Makefile.inc [deleted file]
lua/CMakeLists.txt [new file with mode: 0644]
lua/Makefile [deleted file]
uci_config.h.in [new file with mode: 0644]

index 4534261..c3e50e0 100644 (file)
@@ -1,10 +1,15 @@
+Makefile
+CMakeCache.txt
+CMakeFiles
+*.cmake
+*.o
+*.a
+*.so
+*.dylib
+install_manifest.txt
+
 uci
 uci-static
 ucimap-example
-*.[oa]
-*.so*
-*.dylib*
-.*.swp
-.gdb*
 uci_config.h
 test/save
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0857d4e
--- /dev/null
@@ -0,0 +1,46 @@
+cmake_minimum_required(VERSION 2.6)
+
+PROJECT(uci C)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+
+ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")
+
+OPTION(UCI_PLUGIN_SUPPORT "plugin support" ON)
+OPTION(UCI_DEBUG "debugging support" OFF)
+OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
+OPTION(BUILD_LUA "build Lua plugin" ON)
+
+CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/uci_config.h.in ${CMAKE_SOURCE_DIR}/uci_config.h )
+
+SET(LIB_SOURCES libuci.c file.c ucimap.c util.c delta.c)
+
+ADD_LIBRARY(uci-shared SHARED ${LIB_SOURCES})
+SET_TARGET_PROPERTIES(uci-shared PROPERTIES OUTPUT_NAME uci)
+
+ADD_LIBRARY(uci-static STATIC ${LIB_SOURCES})
+SET_TARGET_PROPERTIES(uci-static PROPERTIES OUTPUT_NAME uci)
+
+ADD_EXECUTABLE(cli cli.c)
+SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME uci)
+TARGET_LINK_LIBRARIES(cli uci-shared)
+
+ADD_EXECUTABLE(cli-static cli.c)
+SET_TARGET_PROPERTIES(cli-static PROPERTIES OUTPUT_NAME uci-static)
+TARGET_LINK_LIBRARIES(cli-static uci-static)
+
+ADD_EXECUTABLE(ucimap-example ucimap-example.c)
+TARGET_LINK_LIBRARIES(ucimap-example uci-static)
+
+ADD_SUBDIRECTORY(lua)
+
+INSTALL(FILES uci.h uci_config.h ucimap.h
+       DESTINATION include/libubox
+)
+
+INSTALL(TARGETS uci-shared uci-static cli cli-static
+       ARCHIVE DESTINATION lib
+       LIBRARY DESTINATION lib
+       RUNTIME DESTINATION bin
+)
+
diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index 8062bd4..0000000
--- a/Makefile
+++ /dev/null
@@ -1,95 +0,0 @@
-VERSION=0.8
-
-# optional features
-PLUGIN_SUPPORT=1
-DEBUG=0
-DEBUG_TYPECAST=0
-
-include Makefile.inc
-
-LIBS=-lc -ldl
-SHLIB_FILE=libuci.$(SHLIB_EXT).$(VERSION)
-
-define add_feature
-       @echo "$(if $(findstring 1,$($(1))),#define UCI_$(1) 1,#undef UCI_$(1))" >> $@.tmp
-endef
-
-define add_dep
-$(1).shared.o: $(2)
-$(1).static.o: $(2)
-endef
-
-SOURCES = libuci.c file.c ucimap.c util.c delta.c
-
-all: uci libuci.$(SHLIB_EXT) uci-static ucimap-example
-
-$(eval $(call add_dep,libuci,list.c uci.h uci_config.h uci_internal.h))
-$(eval $(call add_dep,ucimap,uci.h uci_config.h ucimap.h))
-
-cli.o: cli.c uci.h uci_config.h
-
-uci_config.h: FORCE
-       @rm -f "$@.tmp"
-       @echo "#define UCI_PREFIX \"$(prefix)\"" > "$@.tmp"
-       $(call add_feature,PLUGIN_SUPPORT)
-       $(call add_feature,DEBUG)
-       $(call add_feature,DEBUG_TYPECAST)
-       @if [ \! -f "$@" ] || ! cmp "$@.tmp" "$@" >/dev/null; then \
-               mv "$@.tmp" "$@"; \
-       else \
-               rm -f "$@.tmp"; \
-       fi
-
-%.o: %.c
-       $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
-
-%.static.o: %.c
-       $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
-
-%.shared.o: %.c
-       $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(FPIC) $<
-
-uci: cli.o libuci.$(SHLIB_EXT)
-       $(CC) -o $@ $< -L. -luci $(LIBS)
-
-uci-static: cli.o libuci.a
-       $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-ucimap.c: ucimap.h uci.h
-
-libuci.a: $(patsubst %.c,%.static.o, $(SOURCES))
-       rm -f $@
-       $(AR) rc $@ $^
-       $(RANLIB) $@
-
-libuci.$(SHLIB_EXT): $(patsubst %.c,%.shared.o, $(SOURCES))
-       $(LINK) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ $(LIBS)
-       ln -sf $(SHLIB_FILE) $@
-
-ucimap-example.c: list.h
-ucimap-example: ucimap-example.o libuci.a
-       $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-clean:
-       rm -f uci uci-static *.[oa] *.so* *.dylib* uci_config.h ucimap-example
-
-install: install-bin install-dev
-
-install-dev: all
-       $(MKDIR) -p $(DESTDIR)$(prefix)/$(LIBDIRNAME)
-       $(MKDIR) -p $(DESTDIR)$(prefix)/include
-       $(INSTALL) -m0644 libuci.a $(DESTDIR)$(prefix)/$(LIBDIRNAME)/
-       $(INSTALL) -m0644 uci_config.h uci.h ucimap.h $(DESTDIR)$(prefix)/include/
-
-install-bin: all
-       $(MKDIR) -p $(DESTDIR)$(prefix)/$(LIBDIRNAME)
-       $(INSTALL) -m0755 $(SHLIB_FILE) $(DESTDIR)$(prefix)/$(LIBDIRNAME)/
-       ln -sf $(SHLIB_FILE) $(DESTDIR)$(prefix)/$(LIBDIRNAME)/libuci.$(SHLIB_EXT)
-       $(MKDIR) -p $(DESTDIR)$(prefix)/bin
-       $(INSTALL) -m0755 uci $(DESTDIR)$(prefix)/bin/
-
-test: all ucimap-example
-       make -C test
-
-FORCE: ;
-.PHONY: FORCE
diff --git a/Makefile.inc b/Makefile.inc
deleted file mode 100644 (file)
index 2cfce43..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-prefix=/usr
-DESTDIR=
-LIBDIRNAME=lib
-
-COPTS=-O2
-WOPTS=-pedantic -Werror -Wall
-FPIC=-fPIC
-CFLAGS=$(COPTS) $(WOPTS) -std=gnu99
-CPPFLAGS=-I.
-
-AR=ar
-LD=ld
-CC=gcc
-RANLIB=ranlib
-INSTALL=install
-MKDIR=mkdir
-
-ifeq ($(DEBUG),1)
-  COPTS = -O0
-  CFLAGS += -g3
-endif
-OS=$(shell uname)
-ifeq ($(OS),Darwin)
-  LINK=$(LD)
-  SHLIB_EXT=dylib
-  SHLIB_FLAGS=-dylib
-  ifeq ($(shell gcc -dumpmachine),i686-apple-darwin10)
-    SHLIB_FLAGS += -arch x86_64
-  endif
-else
-  LINK=$(CC)
-  SHLIB_EXT=so
-  SHLIB_FLAGS=-shared -Wl,-soname,$(SHLIB_FILE)
-endif
-
diff --git a/lua/CMakeLists.txt b/lua/CMakeLists.txt
new file mode 100644 (file)
index 0000000..69079c9
--- /dev/null
@@ -0,0 +1,33 @@
+cmake_minimum_required(VERSION 2.6)
+
+PROJECT(uci C)
+
+SET(CMAKE_INSTALL_PREFIX /)
+
+ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3)
+
+IF(APPLE)
+       SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup")
+ENDIF(APPLE)
+
+EXECUTE_PROCESS(
+       COMMAND  lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end"
+       OUTPUT_VARIABLE LUAPATH
+       RESULT_VARIABLE LUA_CHECK_RES
+       OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+IF(NOT ${LUA_CHECK_RES} EQUAL 0 OR ${LUAPATH} EQUAL "")
+       MESSAGE(SEND_ERROR "Lua was not found on your system")
+ENDIF()
+
+ADD_LIBRARY(uci_lua MODULE uci.c)
+SET_TARGET_PROPERTIES(uci_lua PROPERTIES
+       OUTPUT_NAME uci
+       PREFIX ""
+)
+TARGET_LINK_LIBRARIES(uci_lua uci)
+
+INSTALL(TARGETS uci_lua
+       LIBRARY DESTINATION ${LUAPATH}
+)
diff --git a/lua/Makefile b/lua/Makefile
deleted file mode 100644 (file)
index ba5205f..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-include ../Makefile.inc
-LUA_VERSION=5.1
-PREFIX_SEARCH=/usr /usr/local /opt/local
-LUA_PLUGINDIR=$(firstword \
-       $(foreach ldir,$(subst ;, ,$(shell lua -e 'print(package.cpath)')), \
-               $(if $(findstring lib/lua/,$(ldir)),$(patsubst %/?.so,%,$(ldir))) \
-       ) \
-)
-
-# find lua prefix
-LUA_PREFIX=$(firstword \
-       $(foreach prefix,$(PREFIX_SEARCH),\
-               $(if $(wildcard $(prefix)/include/lua.h),$(prefix)) \
-       ) \
-)
-
-libdir=$(prefix)/libs
-luadir=$(if $(LUA_PLUGINDIR),$(LUA_PLUGINDIR),$(libdir)/lua/$(LUA_VERSION))
-luainc=$(shell pkg-config --silence-errors --cflags lua$(LUA_VERSION))
-
-CPPFLAGS=-I.. $(if $(luainc),$(luainc), -I$(LUA_PREFIX)/include)
-LIBS=-L.. -luci $(shell pkg-config --silence-errors --libs lua$(LUA_VERSION))
-
-PLUGIN_LD=$(CC)
-ifeq ($(OS),Darwin)
-  PLUGIN_LDFLAGS=-bundle -undefined dynamic_lookup
-else
-  PLUGIN_LDFLAGS=-shared -Wl,-soname,$(SHLIB_FILE)
-endif
-
-all: uci.so
-
-uci.so: uci.o
-       $(PLUGIN_LD) $(PLUGIN_LDFLAGS) -o $@ $^ $(LIBS)
-
-%.o: %.c
-       $(CC) $(CPPFLAGS) $(CFLAGS) $(FPIC) -c -o $@ $<
-
-install:
-       mkdir -p $(DESTDIR)$(luadir)
-       $(INSTALL) -m0644 uci.so $(DESTDIR)$(luadir)/
-
-clean:
-       rm -f *.so *.o uci.so
diff --git a/uci_config.h.in b/uci_config.h.in
new file mode 100644 (file)
index 0000000..5161f18
--- /dev/null
@@ -0,0 +1,3 @@
+#cmakedefine UCI_PLUGIN_SUPPORT        1
+#cmakedefine UCI_DEBUG 1
+#cmakedefine UCI_DEBUG_TYPECAST 1