]> granicus.if.org Git - icinga2/commitdiff
CMake: Improve Perl detection and add ExtUtils::Embed CXX flags
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 21 Aug 2019 09:03:52 +0000 (11:03 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Wed, 21 Aug 2019 09:10:14 +0000 (11:10 +0200)
CMakeLists.txt
config.h.cmake
icinga-app/CMakeLists.txt

index 0a6e8247413cfb4d986dae3ed9de1362938247c8..3b5c3e22262c1a8faa5f04cd7ed9053ade63a8de 100644 (file)
@@ -20,6 +20,7 @@ option(ICINGA2_WITH_COMPAT "Build the compat module" ON)
 option(ICINGA2_WITH_LIVESTATUS "Build the Livestatus module" ON)
 option(ICINGA2_WITH_NOTIFICATION "Build the notification module" ON)
 option(ICINGA2_WITH_PERFDATA "Build the perfdata module" ON)
+option(ICINGA2_WITH_PERL "Build with embedded perl interpreter" ON)
 option(ICINGA2_WITH_TESTS "Run unit tests" ON)
 
 option (USE_SYSTEMD
@@ -219,14 +220,54 @@ if(WIN32)
 endif()
 
 # Perl
-# Note: Add this after everything else to prepend the header/lib lookup path
-include(FindPerlLibs)
-
-if (NOT MSVC)
-  if(PERLLIBS_FOUND)
-    message(STATUS "Found perl includes in '${PERL_INCLUDE_PATH}' and libs in '${PERL_LIBRARY}'")
-    list(APPEND base_DEPS ${PERL_LIBRARY})
-    include_directories(${PERL_INCLUDE_PATH})
+if(ICINGA2_WITH_PERL)
+  # Note: Add this after everything else to prepend the header/lib lookup path
+  # TODO: Figure out which dependencies are needed for building packages:
+  # - libperl-dev
+  # - ExtUtils-Embed
+  include(FindPerlLibs)
+
+  if (NOT MSVC)
+    if(PERLLIBS_FOUND)
+      message(STATUS "Found perl includes in '${PERL_INCLUDE_PATH}' and libs in '${PERL_LIBRARY}'")
+
+      # TODO: Figure out whether we want to move the Perl code into the icinga2 binary, or use a shim library like MySQL for dependencies
+      list(APPEND base_DEPS ${PERL_LIBRARY})
+      include_directories(${PERL_INCLUDE_PATH})
+
+      execute_process(
+        COMMAND ${PERL_EXECUTABLE} "-MExtUtils::Embed" -e ccopts
+        RESULT_VARIABLE RESULT
+        OUTPUT_VARIABLE PERL_CXX_FLAGS
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+      )
+
+      if (RESULT)
+        message(ERROR "Failed to detect compiler options for Perl with '${PERL_EXECUTABLE} -MExtUtils::Embed -e ccopts': ${RESULT}")
+      else()
+        message(STATUS "Compiler options for Perl: ${PERL_CXX_FLAGS}")
+      endif()
+
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PERL_CXX_FLAGS}")
+
+      execute_process(
+        COMMAND ${PERL_EXECUTABLE} "-MExtUtils::Embed" -e ldopts
+        RESULT_VARIABLE RESULT
+        OUTPUT_VARIABLE PERL_LINKER_FLAGS
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+      )
+
+      if (RESULT)
+        message(ERROR "Failed to detect linker options for Perl with '${PERL_EXECUTABLE} -MExtUtils::Embed -e ldopts': ${RESULT}")
+      else()
+        message(STATUS "Linker options for Perl: ${PERL_LINKER_FLAGS}")
+      endif()
+
+      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PERL_LINKER_FLAGS} ")
+      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PERL_LINKER_FLAGS} ")
+
+      set(HAVE_EMBEDDED_PERL TRUE)
+    endif()
   endif()
 endif()
 
index 16fa190f17e7ccf3b97ccfc2443ed1ad6fb16a0b..e15198c2757d3a5f0689030edb3ebb52e99fa485 100644 (file)
@@ -10,6 +10,7 @@
 #cmakedefine HAVE_NICE
 #cmakedefine HAVE_EDITLINE
 #cmakedefine HAVE_SYSTEMD
+#cmakedefine HAVE_EMBEDDED_PERL
 
 #cmakedefine ICINGA2_UNITY_BUILD
 
index ee3443b288f930ab5fda104bddf08021a5598520..a94d8b7dca398f5d78e213c2c72ac55a450cfc1c 100644 (file)
@@ -53,6 +53,10 @@ if(ICINGA2_WITH_PERFDATA)
   list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:perfdata>)
 endif()
 
+if(ICINGA2_WITH_PERL)
+  list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:perl>)
+endif()
+
 add_executable(icinga-app
   $<TARGET_OBJECTS:icingaloader>
   ${base_OBJS}