changeset 389:9aa8ecbeeeb9

dynamically linking against Mongoose
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Apr 2013 12:36:39 +0200
parents ff647eedfbe1
children 2b189a3d8e94
files CMakeLists.txt Resources/CMake/MongooseConfiguration.cmake
diffstat 2 files changed, 41 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Mon Apr 22 15:59:33 2013 +0200
+++ b/CMakeLists.txt	Mon Apr 29 12:36:39 2013 +0200
@@ -18,6 +18,7 @@
 SET(USE_DYNAMIC_GOOGLE_LOG ON CACHE BOOL "Use the dynamic version of Google Log")
 SET(USE_DYNAMIC_GOOGLE_TEST ON CACHE BOOL "Use the dynamic version of Google Test (not for Debian sid)")
 SET(USE_DYNAMIC_SQLITE ON CACHE BOOL "Use the dynamic version of SQLite")
+SET(USE_DYNAMIC_MONGOOSE OFF CACHE BOOL "Use the dynamic version of Mongoose")
 SET(DEBIAN_FORCE_HARDENING OFF CACHE BOOL "Force the injection of Debian hardening flags (unrecommended)")
 SET(DEBIAN_USE_GTEST_SOURCE_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (only for Debian sid)")
 SET(ONLY_CORE_LIBRARY OFF CACHE BOOL "Only build the core library")
@@ -33,6 +34,7 @@
 # Some basic inclusions
 include(CheckIncludeFiles)
 include(CheckIncludeFileCXX)
+include(CheckLibraryExists)
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/AutoGeneratedCode.cmake)
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/DownloadPackage.cmake)
 include(${CMAKE_SOURCE_DIR}/Resources/CMake/Compiler.cmake)
--- a/Resources/CMake/MongooseConfiguration.cmake	Mon Apr 22 15:59:33 2013 +0200
+++ b/Resources/CMake/MongooseConfiguration.cmake	Mon Apr 29 12:36:39 2013 +0200
@@ -1,33 +1,48 @@
-SET(MONGOOSE_SOURCES_DIR ${CMAKE_BINARY_DIR}/mongoose)
-DownloadPackage("http://mongoose.googlecode.com/files/mongoose-3.1.tgz" "${MONGOOSE_SOURCES_DIR}" "" "")
+if (STATIC_BUILD OR NOT USE_DYNAMIC_MONGOOSE)
+  SET(MONGOOSE_SOURCES_DIR ${CMAKE_BINARY_DIR}/mongoose)
+  DownloadPackage("http://mongoose.googlecode.com/files/mongoose-3.1.tgz" "${MONGOOSE_SOURCES_DIR}" "" "")
 
-# Patch mongoose
-execute_process(
-  COMMAND patch mongoose.c ${CMAKE_SOURCE_DIR}/Resources/Patches/mongoose-patch.diff
-  WORKING_DIRECTORY ${MONGOOSE_SOURCES_DIR}
-  )
+  # Patch mongoose
+  execute_process(
+    COMMAND patch mongoose.c ${CMAKE_SOURCE_DIR}/Resources/Patches/mongoose-patch.diff
+    WORKING_DIRECTORY ${MONGOOSE_SOURCES_DIR}
+    )
 
-include_directories(
-  ${MONGOOSE_SOURCES_DIR}
-  )
+  include_directories(
+    ${MONGOOSE_SOURCES_DIR}
+    )
 
-list(APPEND THIRD_PARTY_SOURCES
-  ${MONGOOSE_SOURCES_DIR}/mongoose.c
-  )
+  list(APPEND THIRD_PARTY_SOURCES
+    ${MONGOOSE_SOURCES_DIR}/mongoose.c
+    )
 
 
-if (${ENABLE_SSL})
-  add_definitions(
-    -DNO_SSL_DL=1
-    )
-  if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
-    link_libraries(dl)
+  if (${ENABLE_SSL})
+    add_definitions(
+      -DNO_SSL_DL=1
+      )
+    if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+      link_libraries(dl)
+    endif()
+
+  else()
+    add_definitions(
+      -DNO_SSL=1   # Remove SSL support from mongoose
+      )
   endif()
 
+  source_group(ThirdParty\\Mongoose REGULAR_EXPRESSION ${MONGOOSE_SOURCES_DIR}/.*)
+
 else()
-  add_definitions(
-    -DNO_SSL=1   # Remove SSL support from mongoose
-    )
+  CHECK_INCLUDE_FILE_CXX(mongoose.h HAVE_MONGOOSE_H)
+  if (NOT HAVE_MONGOOSE_H)
+    message(FATAL_ERROR "Please install the mongoose-devel package")
+  endif()
+
+  CHECK_LIBRARY_EXISTS(mongoose "mg_start" HAVE_MONGOOSE_LIB)
+  if (NOT HAVE_MONGOOSE_LIB)
+    message(FATAL_ERROR "Please install the mongoose-devel package")
+  endif()
+
+  link_libraries(mongoose)
 endif()
-
-source_group(ThirdParty\\Mongoose REGULAR_EXPRESSION ${MONGOOSE_SOURCES_DIR}/.*)