summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2015-04-10 19:02:25 +0200
committerTimo Dritschler <timo.dritschler@kit.edu>2015-04-14 15:40:36 +0200
commitb0ffd9f0a5278f2ef81a267af3c8f72ab8d0f7c2 (patch)
treeef4ae05af135a850ec89b303a558af29e65c8284
parentde68b48a1ff110e965f2c02fc930201ece9980d2 (diff)
downloadkiro-b0ffd9f0a5278f2ef81a267af3c8f72ab8d0f7c2.tar.gz
kiro-b0ffd9f0a5278f2ef81a267af3c8f72ab8d0f7c2.tar.bz2
kiro-b0ffd9f0a5278f2ef81a267af3c8f72ab8d0f7c2.tar.xz
kiro-b0ffd9f0a5278f2ef81a267af3c8f72ab8d0f7c2.zip
Heavily changed cmake build scripts
Added gi-introspection module to build chain
-rw-r--r--CMakeLists.txt123
-rw-r--r--common/cmake/PkgConfigVars.cmake30
-rw-r--r--src/CMakeLists.txt100
-rw-r--r--src/kiro-enums.c.template43
-rw-r--r--src/kiro-enums.h.template25
-rw-r--r--src/kiro.pc.in2
-rw-r--r--test/CMakeLists.txt15
7 files changed, 289 insertions, 49 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0912636..7f0bbf4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
-project(KIRO)
-
cmake_minimum_required(VERSION 2.6)
+project(KIRO C)
+
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
set(TARNAME "kiro")
@@ -12,58 +12,111 @@ set(LIBKIRO_VERSION_STRING "${LIBKIRO_VERSION_MAJOR}.${LIBKIRO_VERSION_MINOR}.${
set(VERSION "${LIBKIRO_VERSION_STRING}")
set(LIBKIRO_DESCRIPTION "Small InfiniBand communication Server and Client")
-set(LIBKIRO_ABI_VERSION "${LIBKIRO_VERSION_MAJOR}.${LIBKIRO_VERSION_MINOR}")
-set(LIBKIRO_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
+# Increase the ABI version when binary compatibility cannot be guaranteed, e.g.
+# symbols have been removed, function signatures, structures, constants etc.
+# changed.
+set(LIBKIRO_ABI_VERSION "1")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/common/cmake")
+# create_enums
+# @prefix: prefix of the output enum files
+# @template_prefix: prefix of the template (should be src/kiro-enums)
+# @header_list: list with header files that should be searched for enums
+macro(create_enums prefix template_prefix header_list)
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${prefix}.h
+ COMMAND ${GLIB2_MKENUMS}
+ ARGS
+ --template ${template_prefix}.h.template
+ ${header_list} > ${CMAKE_CURRENT_BINARY_DIR}/${prefix}.h
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS ${header_list})
+
+ add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${prefix}.c
+ COMMAND ${GLIB2_MKENUMS}
+ ARGS
+ --template ${template_prefix}.c.template
+ ${header_list} > ${CMAKE_CURRENT_BINARY_DIR}/${prefix}.c
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS ${header_list}
+ ${CMAKE_CURRENT_BINARY_DIR}/${prefix}.h
+ )
+endmacro()
+
+include(ConfigurePaths)
+include(PkgConfigVars)
+configure_paths(KIRO)
+
+find_package(PkgConfig)
+find_program(GLIB2_MKENUMS glib-mkenums REQUIRED)
+pkg_check_modules(GLIB2 glib-2.0>=2.32 REQUIRED)
+pkg_check_modules(GOBJECT2 gobject-2.0>=2.32 REQUIRED)
+pkg_check_modules(GMODULE2 gmodule-2.0>=2.32 REQUIRED)
+pkg_check_modules(GIO2 gio-2.0>=2.32 REQUIRED)
+
message(STATUS "checking for rdmacm-devel library")
find_path(RDMACM_DIR rdma/rdma_verbs.h)
if(NOT RDMACM_DIR)
- message( FATAL_ERROR "rdma/rdma_verbs.h Not Found! Probably your version of rdmacm-devel is too old. (Needs to be 1.0.15 or newer)" )
+ message( FATAL_ERROR "rdma/rdma_verbs.h Not Found! Probably your version of rdmacm-devel is too old. (Needs to be 1.0.15 or newer)" )
else()
- message(STATUS " found rdma/rdma_verbs.h")
+ message(STATUS " found rdma/rdma_verbs.h")
endif()
-find_package(PkgConfig)
-pkg_check_modules(GLIB2 glib-2.0>=2.32 REQUIRED)
-pkg_check_modules(GOBJECT2 gobject-2.0>=2.32 REQUIRED)
include_directories(
- SYSTEM
- ${GLIB2_INCLUDE_DIRS}
- ${GOBJECT2_INCLUDE_DIRS}
-)
+ SYSTEM
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ ${GLIB2_INCLUDE_DIRS}
+ ${GOBJECT2_INCLUDE_DIRS}
+ ${GMODULE2_INCLUDE_DIRS}
+ ${GIO2_INCLUDE_DIRS}
+ ${RDMACM_DIR})
+
+set(KIRO_DEPS
+ rdmacm
+ ibverbs
+ ${GLIB2_LIBRARIES}
+ ${GOBJECT2_LIBRARIES}
+ ${GMODULE2_LIBRARIES}
+ ${GIO2_LIBRARIES})
-add_definitions(-Wall -Wextra -std=c99)
-
-include(ConfigurePaths)
-configure_paths(KIRO)
+set(LIBKIRO_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
+add_definitions(-Wall -Wextra -std=c99)
add_subdirectory(src)
add_subdirectory(test)
-set(CPACK_PACKAGE_DESCRIPTION ${LIBKIRO_DESCRIPTION})
-set(CPACK_PACKAGE_NAME ${TARNAME})
-set(CPACK_PACKAGE_CONTACT "Timo Dritschler <timo.dritschler@kit.edu>")
-set(CPACK_PACKAGE_VENDOR "Karlsruhe Institute of Technology")
-set(CPACK_PACKAGE_VERSION_MAJOR "${LIBKIRO_VERSION_MAJOR}")
-set(CPACK_PACKAGE_VERSION_MINOR "${LIBKIRO_VERSION_MINOR}")
-set(CPACK_PACKAGE_VERSION_PATCH "${LIBKIRO_VERSION_PATCH}")
-set(CPACK_PACKAGE_RELEASE "${LIBKIRO_VERSION_RELEASE}")
-
-set(CPACK_GENERATOR "TGZ;RPM;")
-set(CPACK_SOURCE_GENERATOR "TGZ")
-set(CPACK_SOURCE_IGNORE_FILES "tags" ".git")
-set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
-set(CPACK_SOURCE_PACKAGE_FILE_NAME "LIBKIRO-${LIBKIRO_VERSION_STRING}" CACHE INTERNAL "tarball basename")
-set(CPACK_PACKAGE_FILE_NAME
- "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}")
-
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/kiro.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/kiro.pc" @ONLY IMMEDIATE)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kiro.pc DESTINATION ${KIRO_PKGCONFIGDIR})
-include(CPack)
+#"{{{CPAK
+if(WITH_PACKAGE)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package.sh.in
+ ${CMAKE_CURRENT_BINARY_DIR}/package.sh)
+
+ set(CPACK_PACKAGE_DESCRIPTION ${LIBKIRO_DESCRIPTION})
+ set(CPACK_PACKAGE_NAME ${TARNAME})
+ set(CPACK_PACKAGE_CONTACT "Timo Dritschler <timo.dritschler@kit.edu>")
+ set(CPACK_PACKAGE_VENDOR "Karlsruhe Institute of Technology")
+ set(CPACK_PACKAGE_VERSION_MAJOR "${LIBKIRO_VERSION_MAJOR}")
+ set(CPACK_PACKAGE_VERSION_MINOR "${LIBKIRO_VERSION_MINOR}")
+ set(CPACK_PACKAGE_VERSION_PATCH "${LIBKIRO_VERSION_PATCH}")
+ set(CPACK_PACKAGE_RELEASE "${LIBKIRO_VERSION_RELEASE}")
+
+ set(CPACK_GENERATOR "TGZ;RPM;")
+ set(CPACK_SOURCE_GENERATOR "TGZ")
+ set(CPACK_SOURCE_IGNORE_FILES "tags" ".git")
+ set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
+ set(CPACK_SOURCE_PACKAGE_FILE_NAME "LIBKIRO-${LIBKIRO_VERSION_STRING}" CACHE INTERNAL "tarball basename")
+ set(CPACK_PACKAGE_FILE_NAME
+ "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}")
+
+
+ include(CPack)
+endif()
+#}}}
diff --git a/common/cmake/PkgConfigVars.cmake b/common/cmake/PkgConfigVars.cmake
new file mode 100644
index 0000000..f295457
--- /dev/null
+++ b/common/cmake/PkgConfigVars.cmake
@@ -0,0 +1,30 @@
+# - determine variables defined in pkg-config files
+#
+# Usage:
+# pkg_check_variable(<PKG_NAME> <VARIABLE_NAME>)
+#
+# Checks for a variable in the given package and translates to a call such as
+# `pkg-config --variable=<VARIABLE_NAME> <PKG_NAME>`. The output is a cached
+# variable named
+#
+# <PKG_NAME>_<VARIABLE_NAME>
+#
+# Note that both names are uppercased and any dashes replaced by underscores.
+#
+
+find_package(PkgConfig REQUIRED)
+
+function(pkg_check_variable _pkg _name)
+ string(TOUPPER ${_pkg} _pkg_upper)
+ string(TOUPPER ${_name} _name_upper)
+ string(REPLACE "-" "_" _pkg_upper ${_pkg_upper})
+ string(REPLACE "-" "_" _name_upper ${_name_upper})
+ set(_output_name "${_pkg_upper}_${_name_upper}")
+
+ execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=${_name} ${_pkg}
+ OUTPUT_VARIABLE _pkg_result
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ set("${_output_name}" "${_pkg_result}" CACHE STRING "pkg-config variable
+ ${_name} of ${_pkg}")
+endfunction()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a9e5d96..7b6eb8f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,13 +1,99 @@
-add_library(kiro SHARED kiro-trb.c kiro-client.c kiro-server.c kiro-sb.c)
+cmake_minimum_required(VERSION 2.6)
+project(KIRO C)
+
+set(kiro_SRCS
+ kiro-server.c
+ kiro-client.c
+ kiro-trb.c
+ kiro-sb.c
+ )
+
+set(kiro_HDRS
+ kiro-server.h
+ kiro-client.h
+ kiro-trb.h
+ kiro-sb.h
+ )
+
+create_enums(kiro-enums
+ ${CMAKE_CURRENT_SOURCE_DIR}/kiro-enums
+ ${kiro_HDRS}
+ kiro-rdma.h
+ )
+
+add_library(kiro SHARED
+ ${kiro_SRCS}
+ ${CMAKE_CURRENT_BINARY_DIR}/kiro-enums.c)
+
set_target_properties(kiro PROPERTIES
VERSION "${LIBKIRO_VERSION_MAJOR}.${LIBKIRO_VERSION_MINOR}"
SOVERSION ${LIBKIRO_VERSION_PATCH}
)
-target_link_libraries(kiro m rdmacm ibverbs pthread)
+target_link_libraries(kiro m ${KIRO_DEPS})
-install(FILES kiro-rdma.h kiro-trb.h kiro-client.h kiro-server.h kiro-sb.h
- DESTINATION ${KIRO_INCLUDEDIR}/kiro)
-install(TARGETS kiro
- LIBRARY DESTINATION ${KIRO_LIBDIR}
-)
+pkg_check_modules(GOBJECT_INTROSPECTION gobject-introspection-1.0)
+
+if (GOBJECT_INTROSPECTION_FOUND)
+
+ option(WITH_GIR "Build introspection files" ON)
+
+ if (WITH_GIR)
+ find_program(INTROSPECTION_SCANNER "g-ir-scanner")
+ find_program(INTROSPECTION_COMPILER "g-ir-compiler")
+ pkg_check_variable(gobject-introspection-1.0 g_ir_scanner)
+ pkg_check_variable(gobject-introspection-1.0 g_ir_compiler)
+
+ set(GIR_PREFIX "Kiro-${LIBKIRO_ABI_VERSION}.0")
+ set(GIR_XML "${GIR_PREFIX}.gir")
+ set(GIR_TYPELIB "${GIR_PREFIX}.typelib")
+ set(_gir_input)
+
+ foreach(_src ${kiro_SRCS} ${kiro_HDRS})
+ list(APPEND _gir_input "${CMAKE_CURRENT_SOURCE_DIR}/${_src}")
+ endforeach()
+
+ #list(APPEND _gir_input "${CMAKE_CURRENT_BINARY_DIR}/kiro-enums.h")
+ #list(APPEND _gir_input "${CMAKE_CURRENT_BINARY_DIR}/kiro-enums.c")
+
+ add_custom_command(OUTPUT ${GIR_XML}
+ COMMAND ${INTROSPECTION_SCANNER}
+ --namespace=Kiro
+ --nsversion=${LIBKIRO_ABI_VERSION}
+ --library=kiro
+ --no-libtool
+ --include=GObject-2.0
+ --include=GModule-2.0
+ --output ${GIR_XML}
+ --warn-all
+ --quiet
+ ${_gir_input}
+ DEPENDS ${kiro_SRCS}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+
+ add_custom_command(OUTPUT ${GIR_TYPELIB}
+ COMMAND ${INTROSPECTION_COMPILER}
+ -o ${GIR_TYPELIB}
+ ${GIR_XML}
+ DEPENDS ${GIR_XML}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+
+ add_custom_target(gir ALL DEPENDS ${GIR_XML} ${GIR_TYPELIB})
+ add_dependencies(gir kiro)
+
+ endif()
+endif()
+
+
+install(FILES ${kiro_HDRS} kiro-rdma.h DESTINATION ${KIRO_INCLUDEDIR}/kiro)
+install(TARGETS kiro LIBRARY DESTINATION ${KIRO_LIBDIR})
+
+if(WITH_GIR)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${GIR_XML}
+ DESTINATION ${KIRO_GIRDIR}
+ COMPONENT libraries)
+
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${GIR_TYPELIB}
+ DESTINATION ${KIRO_TYPELIBDIR}
+ COMPONENT libraries)
+endif()
diff --git a/src/kiro-enums.c.template b/src/kiro-enums.c.template
new file mode 100644
index 0000000..f68f0ff
--- /dev/null
+++ b/src/kiro-enums.c.template
@@ -0,0 +1,43 @@
+/*** BEGIN file-header ***/
+
+#include "kiro-enums.h"
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+#include "@filename@"
+/*** END file-production ***/
+
+
+/*** BEGIN value-header ***/
+GType
+@enum_name@_get_type (void)
+{
+ static volatile gsize g_define_type_id__volatile = 0;
+
+ if (g_once_init_enter (&g_define_type_id__volatile)) {
+ static const G@Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+ { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+ { 0, NULL, NULL }
+ };
+ GType g_define_type_id =
+ g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+
+ g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+ }
+
+ return g_define_type_id__volatile;
+}
+
+/*** END value-tail ***/
+
+/*** BEGIN file-tail ***/
+
+/*** END file-tail ***/
diff --git a/src/kiro-enums.h.template b/src/kiro-enums.h.template
new file mode 100644
index 0000000..12f7fca
--- /dev/null
+++ b/src/kiro-enums.h.template
@@ -0,0 +1,25 @@
+/*** BEGIN file-header ***/
+
+#ifndef KIRO_ENUMS_H
+#define KIRO_ENUMS_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType @enum_name@_get_type (void) G_GNUC_CONST;
+#define KIRO_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* !KIRO_ENUMS_H */
+/*** END file-tail ***/
diff --git a/src/kiro.pc.in b/src/kiro.pc.in
index cc3fa94..7318e6b 100644
--- a/src/kiro.pc.in
+++ b/src/kiro.pc.in
@@ -5,6 +5,6 @@ includedir=@KIRO_INCLUDEDIR@
Name: @TARNAME@
Description: @LIBKIRO_DESCRIPTION_SUMMARY@
-Version: @LIBKIRO_ABI_VERSION@
+Version: @LIBKIRO_VERSION_MAJOR@.@LIBKIRO_VERSION_MINOR@.@LIBKIRO_VERSION_PATCH@
Libs: -L${libdir} -lkiro
Cflags: -I${includedir}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 4ae047b..161bc9f 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -6,20 +6,23 @@ pkg_check_modules(SDL sdl>=1.2.15)
if (SDL_FOUND)
add_executable(kiro-client-sdl test-client.c)
- target_link_libraries(kiro-client-sdl kiro SDL m gobject-2.0 glib-2.0)
+ target_link_libraries(kiro-client-sdl kiro SDL m ${KIRO_DEPS})
install(TARGETS kiro-client-sdl RUNTIME DESTINATION ${KIRO_BINDIR})
else ()
message("SDL not found: Won't build kiro-client-sdl binary.")
endif ()
+add_executable(kiro-server test-server.c)
+target_link_libraries(kiro-server kiro m ${KIRO_DEPS})
+
add_executable(kiro-test-latency test-client-latency.c)
-target_link_libraries(kiro-test-latency kiro gobject-2.0 glib-2.0)
+target_link_libraries(kiro-test-latency kiro ${KIRO_DEPS})
+
add_executable(kiro-test-bandwidth test-client-bandwidth.c)
-target_link_libraries(kiro-test-bandwidth kiro gobject-2.0 glib-2.0)
-add_executable(kiro-server test-server.c)
-target_link_libraries(kiro-server kiro gobject-2.0 glib-2.0)
+target_link_libraries(kiro-test-bandwidth kiro ${KIRO_DEPS})
+
add_executable(kiro-test-partial test-partial.c)
-target_link_libraries(kiro-test-partial kiro gobject-2.0 glib-2.0)
+target_link_libraries(kiro-test-partial kiro ${KIRO_DEPS})
install(TARGETS kiro-test-bandwidth kiro-test-latency kiro-server
RUNTIME DESTINATION ${KIRO_BINDIR})