# HG changeset patch # User Tero Marttila # Date 1236467814 -7200 # Node ID 527d23bf64415ac61900f8fd6e05ab54ef4aaec4 # Parent 9dfc861273e588d38b563007afef586783581e1b move to CMake from old crufty Makefile diff -r 9dfc861273e5 -r 527d23bf6441 .hgignore --- a/.hgignore Sun Mar 08 00:19:12 2009 +0200 +++ b/.hgignore Sun Mar 08 01:16:54 2009 +0200 @@ -1,6 +1,4 @@ type: re -^bin/ -^obj/ -^build/deps/ +^build \.[^/]+.sw[op]$ diff -r 9dfc861273e5 -r 527d23bf6441 CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CMakeLists.txt Sun Mar 08 01:16:54 2009 +0200 @@ -0,0 +1,15 @@ +# policy +cmake_minimum_required (VERSION 2.6) + +# project attributes +project (evsql C) + +# cmake paths +set(CMAKE_MODULE_PATH "${evsql_SOURCE_DIR}/cmake/Modules/") + +# dependancies +find_package(LibEvent REQUIRED) + +# add the src subdir +add_subdirectory (src) + diff -r 9dfc861273e5 -r 527d23bf6441 Makefile --- a/Makefile Sun Mar 08 00:19:12 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -LIBEVENT_PATH = ../libs/libevent-dev -LIBFUSE_PATH = ../libs/libfuse-2.7.4 - -LIBRARY_PATHS = -L${LIBEVENT_PATH}/lib -L${LIBFUSE_PATH}/lib -INCLUDE_PATHS = -I${LIBEVENT_PATH}/include -I${LIBFUSE_PATH}/include -LDLIBS = -levent -lfuse -lpq - -# default is test -ifndef MODE -MODE = test -endif - -ifeq ($(MODE), debug) -MODE_CFLAGS = -g -DDEBUG_ENABLED -else ifeq ($(MODE), dev) -MODE_CFLAGS = -g -else ifeq ($(MODE), test) -MODE_CFLAGS = -g -DINFO_DISABLED -else ifeq ($(MODE), release) -MODE_CFLAGS = -DINFO_DISABLED -O2 -endif - -# XXX: ugh... use `pkg-config fuse` -DEFINES = -D_FILE_OFFSET_BITS=64 -FIXED_CFLAGS = -Wall -std=gnu99 - -BIN_NAMES = helloworld hello simple_hello evpq_test url_test dbfs -BIN_PATHS = $(addprefix bin/,$(BIN_NAMES)) - -# modules -module_objs = $(patsubst src/%.c,obj/%.o,$(wildcard src/$(1)/*.c)) - -# complex modules -EVSQL_OBJS = $(call module_objs,evsql) obj/evpq.o -DBFS_OBJS = $(call module_objs,dbfs) obj/dirbuf.o - -# first target -all: ${BIN_PATHS} - -# binaries -bin/helloworld: -bin/hello: obj/evfuse.o obj/dirbuf.o obj/lib/log.o obj/lib/signals.o -bin/simple_hello: obj/evfuse.o obj/dirbuf.o obj/lib/log.o obj/lib/signals.o obj/simple.o -bin/evpq_test: obj/evpq.o obj/lib/log.o -bin/url_test: obj/lib/url.o obj/lib/lex.o obj/lib/log.o -bin/dbfs: ${DBFS_OBJS} ${EVSQL_OBJS} obj/evfuse.o obj/lib/log.o obj/lib/signals.o - -# computed -LDFLAGS = ${LIBRARY_PATHS} - -CPPFLAGS = ${INCLUDE_PATHS} ${DEFINES} -CFLAGS = ${MODE_CFLAGS} ${FIXED_CFLAGS} - -SRC_PATHS = $(wildcard src/*.c) $(wildcard src/*/*.c) -SRC_NAMES = $(patsubst src/%,%,$(SRC_PATHS)) -SRC_DIRS = $(dir $(SRC_NAMES)) - -# other targets -clean : - -rm obj/*.o obj/*/*.o - -rm bin/* - -rm build/deps/*.d build/deps/*/*.d - -clean-deps: - -rm build/deps/*/*.d - -rm build/deps/*.d - -#obj-dirs: -# python build/make_obj_dirs.py $(BIN_PATHS) - -build/deps/%.d : src/%.c - @set -e; rm -f $@; \ - $(CC) -MM -MT __ $(CPPFLAGS) $< > $@.$$$$; \ - sed 's,__[ :]*,obj/$*.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ - -include $(SRC_NAMES:%.c=build/deps/%.d) - -obj/%.o : src/%.c - $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - -bin/% : obj/%.o - $(CC) $(LDFLAGS) $+ $(LOADLIBES) $(LDLIBS) -o $@ - diff -r 9dfc861273e5 -r 527d23bf6441 cmake/Modules/FindLibEvent.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/Modules/FindLibEvent.cmake Sun Mar 08 01:16:54 2009 +0200 @@ -0,0 +1,27 @@ +# Find libevent +# Once done, this will define: +# +# LibEvent_FOUND +# LibEvent_INCLUDE_DIRS +# LibEvent_LIBRARIES +# +# Currently, this only supports libevent-svn (i.e. 1.5/2.0), so it's kind of useless for real use :) + +include (LibFindMacros) + +# include dir +find_path (LibEvent_INCLUDE_DIR + NAMES "event2/event.h" + PATHS "$ENV{LIBEVENT_PREFIX}/include" +) + +# library +find_library (LibEvent_LIBRARY + NAMES "event" + PATHS "$ENV{LIBEVENT_PREFIX}/lib" +) + +# set the external vars +set (LibEvent_PROCESS_INCLUDES LibEvent_INCLUDE_DIR) +set (LibEvent_PROCESS_LIBS LibEvent_LIBRARY) +libfind_process (LibEvent) diff -r 9dfc861273e5 -r 527d23bf6441 cmake/Modules/LibFindMacros.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/Modules/LibFindMacros.cmake Sun Mar 08 01:16:54 2009 +0200 @@ -0,0 +1,99 @@ +# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments +# used for the current package. For this to work, the first parameter must be the +# prefix of the current package, then the prefix of the new package etc, which are +# passed to find_package. +macro (libfind_package PREFIX) + set (LIBFIND_PACKAGE_ARGS ${ARGN}) + if (${PREFIX}_FIND_QUIETLY) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) + endif (${PREFIX}_FIND_QUIETLY) + if (${PREFIX}_FIND_REQUIRED) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) + endif (${PREFIX}_FIND_REQUIRED) + find_package(${LIBFIND_PACKAGE_ARGS}) +endmacro (libfind_package) + +# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6) +# where they added pkg_check_modules. Consequently I need to support both in my scripts +# to avoid those deprecated warnings. Here's a helper that does just that. +# Works identically to pkg_check_modules, except that no checks are needed prior to use. +macro (libfind_pkg_check_modules PREFIX PKGNAME) + if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + include(UsePkgConfig) + pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) + else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(${PREFIX} ${PKGNAME}) + endif (PKG_CONFIG_FOUND) + endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) +endmacro (libfind_pkg_check_modules) + +# Do the final processing once the paths have been detected. +# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain +# all the variables, each of which contain one include directory. +# Ditto for ${PREFIX}_PROCESS_LIBS and library files. +# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. +# Also handles errors in case library detection was required, etc. +macro (libfind_process PREFIX) + # Skip processing if already processed during this run + if (NOT ${PREFIX}_FOUND) + # Start with the assumption that the library was found + set (${PREFIX}_FOUND TRUE) + + # Process all includes and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_INCLUDES}) + if (${i}) + set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Process all libraries and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_LIBS}) + if (${i}) + set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Print message and/or exit on fatal error + if (${PREFIX}_FOUND) + if (NOT ${PREFIX}_FIND_QUIETLY) + message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") + endif (NOT ${PREFIX}_FIND_QUIETLY) + else (${PREFIX}_FOUND) + if (${PREFIX}_FIND_REQUIRED) + foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) + message("${i}=${${i}}") + endforeach (i) + message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") + endif (${PREFIX}_FIND_REQUIRED) + endif (${PREFIX}_FOUND) + endif (NOT ${PREFIX}_FOUND) +endmacro (libfind_process) + +macro(libfind_library PREFIX basename) + set(TMP "") + if(MSVC80) + set(TMP -vc80) + endif(MSVC80) + if(MSVC90) + set(TMP -vc90) + endif(MSVC90) + set(${PREFIX}_LIBNAMES ${basename}${TMP}) + if(${ARGC} GREATER 2) + set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) + string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) + set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) + endif(${ARGC} GREATER 2) + find_library(${PREFIX}_LIBRARY + NAMES ${${PREFIX}_LIBNAMES} + PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} + ) +endmacro(libfind_library) + diff -r 9dfc861273e5 -r 527d23bf6441 src/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CMakeLists.txt Sun Mar 08 01:16:54 2009 +0200 @@ -0,0 +1,15 @@ +# add our include path +include_directories (${evsql_SOURCE_DIR}/include ${LibEvent_INCLUDE_DIRS}) + +# define our source code modules +set (LIB_SOURCES "lib/log.c") +set (EVPQ_SOURCES evpq.c) +set (EVSQL_SOURCES core.c util.c) + +# XXX: silly cmake does silly things when you SET with only one arg +set (SOURCES lib/log.c evpq.c core.c util.c) + +# add our library +add_library (evsql STATIC ${SOURCES}) +target_link_libraries (evsql ${LibEvent_LIBRARIES}) +