summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--TestCInline.cmake28
-rw-r--r--librabbitmq/CMakeLists.txt47
3 files changed, 67 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cb1646d..dee6e43 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 2.6)
+project(rabbitmq-c)
#detect amqp_codegen directory
find_path(AMQP_CODEGEN_DIR "amqp-rabbitmq-0.9.1.json"
@@ -26,5 +27,8 @@ if(CHECK_PYTHON_JSON_FAILED AND CHECK_PYTHON_SIMPLEJSON_FAILED)
message(FATAL_ERROR "could not find a python that can 'import simplejson")
endif()
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
+include(TestCInline)
+
add_subdirectory(librabbitmq)
add_subdirectory(examples)
diff --git a/TestCInline.cmake b/TestCInline.cmake
new file mode 100644
index 0000000..4fdd4c5
--- /dev/null
+++ b/TestCInline.cmake
@@ -0,0 +1,28 @@
+#Inspired from http://www.cmake.org/Wiki/CMakeTestInline
+
+IF(NOT DEFINED C_INLINE_DETECTED)
+
+ SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
+static inline int static_foo() {return 0\;}
+int main(int argc, char *argv[]){return 0\;}
+")
+
+ FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c ${INLINE_TEST_SRC})
+
+ FOREACH(KEYWORD "inline" "__inline__" "__inline")
+ IF(NOT DEFINED C_INLINE)
+ TRY_COMPILE(C_HAS_${KEYWORD}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
+ COMPILE_DEFINITIONS "-Dinline=${KEYWORD}"
+ )
+ IF(C_HAS_${KEYWORD})
+ SET(C_INLINE ${KEYWORD})
+ ENDIF(C_HAS_${KEYWORD})
+ ENDIF(NOT DEFINED C_INLINE)
+ ENDFOREACH(KEYWORD)
+
+ SET(C_INLINE_DETECTED True CACHE BOOL INTERNAL)
+
+ENDIF(NOT DEFINED C_INLINE_DETECTED)
+
diff --git a/librabbitmq/CMakeLists.txt b/librabbitmq/CMakeLists.txt
index d6af3da..eb6ba74 100644
--- a/librabbitmq/CMakeLists.txt
+++ b/librabbitmq/CMakeLists.txt
@@ -2,33 +2,56 @@ project(librabbitmq "C")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
-file(COPY "${AMQP_CODEGEN_DIR}/amqp_codegen.py" "codegen.py"
- DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
-)
-file(COPY "${AMQP_CODEGEN_DIR}/amqp_codegen.py"
- DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
-)
+# Stuff dealing with code generation
+configure_file(codegen.py ${CMAKE_CURRENT_BINARY_DIR}/codegen.py)
+configure_file(${AMQP_CODEGEN_DIR}/amqp_codegen.py ${CMAKE_CURRENT_BINARY_DIR}/amqp_codegen.py)
+
+set(AMQP_CODEGEN_PY "${CMAKE_CURRENT_BINARY_DIR}/amqp_codegen.py")
set(CODEGEN_PY "${CMAKE_CURRENT_BINARY_DIR}/codegen.py")
#generate amqp_framing.h/amqp_framing.c
add_custom_command(
- OUTPUT "amqp_framing.h" "amqp_framing.c"
+ OUTPUT "amqp_framing.h"
COMMAND ${PYTHON_EXECUTABLE} ARGS ${CODEGEN_PY} header ${AMQP_SPEC_JSON_PATH} "amqp_framing.h"
+ DEPENDS ${AMQP_SPEC_JSON_PATH} ${CODEGEN_PY} ${AMQP_CODEGEN_PY}
+ VERBATIM)
+
+add_custom_command(
+ OUTPUT "amqp_framing.c"
COMMAND ${PYTHON_EXECUTABLE} ARGS ${CODEGEN_PY} body ${AMQP_SPEC_JSON_PATH} "amqp_framing.c"
- DEPENDS ${AMQP_SPEC_JSON_PATH}
+ DEPENDS ${AMQP_SPEC_JSON_PATH} ${CODEGEN_PY} ${AMQP_CODEGEN_PY}
VERBATIM)
+
+SET(CONFIG_CONTENTS "#define VERSION \"0.0.1\"
+#ifndef __cplusplus
+# define inline ${C_INLINE}
+#endif // __cplusplus
+")
+
#prepare config.h
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config.h" "#define VERSION \"0.0.1\"")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config.h" ${CONFIG_CONTENTS})
-include_directories("unix")
+if(WIN32)
+ set(SOCKET_IMPL "windows")
+ set(MSINTTYPES_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/../msinttypes")
+else(WIN32)
+ set(SOCKET_IMPL "unix")
+endif(WIN32)
+
+include_directories(${SOCKET_IMPL} ${MSINTTYPES_INCLUDE})
+add_definitions(-DBUILDING_LIBRABBITMQ)
set(RABBITMQ_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.h
${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.c
amqp_api.c amqp.h
amqp_connection.c amqp_mem.c amqp_private.h amqp_socket.c amqp_table.c
- unix/socket.h unix/socket.c
+ ${SOCKET_IMPL}/socket.h ${SOCKET_IMPL}/socket.c
)
-add_library(rabbitmq ${RABBITMQ_SOURCES})
+add_library(rabbitmq SHARED ${RABBITMQ_SOURCES})
+
+if(WIN32)
+ target_link_libraries(rabbitmq ws2_32)
+endif(WIN32)