changeset 2478:1e2d5e14b3d3 lua_dll

New CMake option: ENABLE_LUA_MODULES to enable Lua modules
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Feb 2018 11:14:59 +0100
parents 1c1716adaf26
children 8437607835ef 813ab664f7fe
files NEWS Resources/CMake/LuaConfiguration.cmake Resources/CMake/OrthancFrameworkParameters.cmake
diffstat 3 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Feb 19 21:52:04 2018 +0100
+++ b/NEWS	Tue Feb 20 11:14:59 2018 +0100
@@ -12,6 +12,12 @@
 * New URI: "/tools/create-media-extended" to generate a DICOMDIR
   archive from several resources, including additional type-3 tags
 
+Lua
+---
+
+* New CMake option: "-DENABLE_LUA_MODULES=ON" to enable support for
+  loading external Lua modules if the Lua engine is statically linked
+
 Maintenance
 -----------
 
--- a/Resources/CMake/LuaConfiguration.cmake	Mon Feb 19 21:52:04 2018 +0100
+++ b/Resources/CMake/LuaConfiguration.cmake	Tue Feb 20 11:14:59 2018 +0100
@@ -5,17 +5,28 @@
 
   DownloadPackage(${LUA_MD5} ${LUA_URL} "${LUA_SOURCES_DIR}")
 
-  if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
-      ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
-      ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
-      ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
-    add_definitions(-DLUA_DL_DLOPEN=1)    # enable dynamic libraries loading (for linux)
-  elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
-    add_definitions(-DLUA_DL_DLL=1)       # enable dynamic libraries loading (for windows)
-  elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
-    add_definitions(-LUA_DL_DYLD=1)       # enable dynamic libraries loading (for OSX)
-  else()
-    message(FATAL_ERROR "Support your platform here")
+  if (ENABLE_LUA_MODULES)
+    if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
+        ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
+        ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
+        ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
+      # Enable loading of shared libraries (for UNIX-like)
+      add_definitions(-DLUA_USE_DLOPEN=1)
+
+      # Publish the functions of the Lua engine (that are built within
+      # the Orthanc binary) as global symbols, so that the external
+      # shared libraries can call them
+      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--export-dynamic")
+
+    elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+      add_definitions(-DLUA_DL_DLL=1)       # Enable loading of shared libraries (for Microsoft Windows)
+      
+    elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+      add_definitions(-LUA_DL_DYLD=1)       # Enable loading of shared libraries (for Apple OS X)
+      
+    else()
+      message(FATAL_ERROR "Support your platform here")
+    endif()
   endif()
 
   include_directories(
--- a/Resources/CMake/OrthancFrameworkParameters.cmake	Mon Feb 19 21:52:04 2018 +0100
+++ b/Resources/CMake/OrthancFrameworkParameters.cmake	Tue Feb 20 11:14:59 2018 +0100
@@ -34,6 +34,7 @@
 set(ENABLE_PKCS11 OFF CACHE BOOL "Enable PKCS#11 for HTTPS client authentication using hardware security modules and smart cards")
 set(ENABLE_PROFILING OFF CACHE BOOL "Whether to enable the generation of profiling information with gprof")
 set(ENABLE_SSL ON CACHE BOOL "Include support for SSL")
+set(ENABLE_LUA_MODULES OFF CACHE BOOL "Enable support for loading external Lua modules (only meaningful if using static version of the Lua engine)")
 
 # Parameters to fine-tune linking against system libraries
 set(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost")