]> granicus.if.org Git - icinga2/commitdiff
Implement support for unity builds
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 30 Aug 2014 16:08:28 +0000 (18:08 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 30 Aug 2014 18:02:12 +0000 (20:02 +0200)
fixes #7034
fixes #7035

26 files changed:
CMakeLists.txt
INSTALL.md
components/checker/CMakeLists.txt
components/compat/CMakeLists.txt
components/db_ido_mysql/CMakeLists.txt
components/db_ido_pgsql/CMakeLists.txt
components/demo/CMakeLists.txt
components/livestatus/CMakeLists.txt
components/notification/CMakeLists.txt
components/perfdata/CMakeLists.txt
config.h.cmake
lib/base/CMakeLists.txt
lib/base/i2-base.hpp
lib/base/initialize.hpp
lib/base/type.hpp
lib/base/utility.hpp
lib/config/CMakeLists.txt
lib/db_ido/CMakeLists.txt
lib/hello/CMakeLists.txt
lib/icinga/CMakeLists.txt
lib/methods/CMakeLists.txt
lib/remote/CMakeLists.txt
test/CMakeLists.txt
tools/CMakeLists.txt
tools/mkunity/CMakeLists.txt [new file with mode: 0644]
tools/mkunity/mkunity.c [new file with mode: 0644]

index 19518eba1b7dc14cab30077215480adc9909f8e5..5dfbd11c6587cce06389ff45d863ea3e07141496 100644 (file)
@@ -40,6 +40,7 @@ set(ICINGA2_COMMAND_GROUP "icingacmd" CACHE STRING "Icinga 2 command group")
 set(ICINGA2_RUNDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run" CACHE STRING "/run directory")
 set(ICINGA2_PLUGINDIR "/usr/lib/nagios/plugins" CACHE STRING "Path for the check plugins")
 set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe")
+set(ICINGA2_UNITY_BUILD OFF CACHE BOOL "Whether to perform a unity build")
 
 file(READ "${CMAKE_CURRENT_SOURCE_DIR}/COPYING" ICINGA2_LICENSE_GPL)
 file(READ "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.Exceptions" ICINGA2_LICENSE_ADDITIONS)
index 893233cf45fb736666ffda8e09aed864cf0bbf2f..ead71cfad5e3d9a7e3b64b142e969deb5000478f 100644 (file)
@@ -139,6 +139,7 @@ variables are supported:
 - `ICINGA2_COMMAND_USER`: The command user Icinga 2 should use; defaults to `icinga`
 - `ICINGA2_GIT_VERSION_INFO`: Whether to use Git to determine the version number; defaults to `ON`
 - `ICINGA2_COMMAND_GROUP`: The command group Icinga 2 should use; defaults to `icingacmd`
+- `ICINGA2_UNITY_BUILD`: Whether to perform a unity build
 - `ICINGA2_PLUGINDIR`: The path for the Monitoring Plugins project binaries; defaults to `/usr/lib/nagios/plugins`
 - `ICINGA2_RUNDIR`: The location of the "run" directory; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/run`
 - `CMAKE_INSTALL_SYSCONFDIR`: The configuration directory; defaults to `CMAKE_INSTALL_PREFIX/etc`
index 1790ecc31aa98ca55e9637b37618c79b2943d7dd..2c60df7510d713df297b5a0be404864ffe8ada97 100644 (file)
@@ -19,7 +19,15 @@ mkclass_target(checkercomponent.ti checkercomponent.thpp)
 
 mkembedconfig_target(checker-type.conf checker-type.cpp)
 
-add_library(checker SHARED checkercomponent.cpp checkercomponent.thpp checker-type.cpp)
+set(checker_SOURCES
+  checkercomponent.cpp checkercomponent.thpp checker-type.cpp
+)
+
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(checker checker_SOURCES)
+endif()
+
+add_library(checker SHARED ${checker_SOURCES})
 
 target_link_libraries(checker ${Boost_LIBRARIES} base config icinga remote)
 
index 2efab5f20195091829851be02f0f1a0b34b25458..ad7f9ec8aea6b5eb0abdb0cd3ff0b0e47d2d2485 100644 (file)
@@ -22,7 +22,17 @@ mkclass_target(statusdatawriter.ti statusdatawriter.thpp)
 
 mkembedconfig_target(compat-type.conf compat-type.cpp)
 
-add_library(compat SHARED checkresultreader.cpp checkresultreader.thpp compatlogger.cpp compatlogger.thpp externalcommandlistener.cpp externalcommandlistener.thpp statusdatawriter.cpp statusdatawriter.thpp compat-type.cpp)
+set(compat_SOURCES
+  checkresultreader.cpp checkresultreader.thpp compatlogger.cpp
+  compatlogger.thpp externalcommandlistener.cpp externalcommandlistener.thpp
+  statusdatawriter.cpp statusdatawriter.thpp compat-type.cpp
+)
+
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(compat compat_SOURCES)
+endif()
+
+add_library(compat SHARED ${compat_SOURCES})
 
 target_link_libraries(compat ${Boost_LIBRARIES} base config icinga)
 
index 59f2def0e94fecf27252fd64db5da4cdd6ec19cf..a2799ac39c2b91c7287c64b8eb58ee98044579b2 100644 (file)
@@ -22,7 +22,15 @@ if(MYSQL_FOUND)
 
     mkembedconfig_target(db_ido_mysql-type.conf db_ido_mysql-type.cpp)
 
-    add_library(db_ido_mysql SHARED idomysqlconnection.cpp idomysqlconnection.thpp db_ido_mysql-type.cpp)
+    set(db_ido_mysql_SOURCES
+      idomysqlconnection.cpp idomysqlconnection.thpp db_ido_mysql-type.cpp
+    )
+
+    if(ICINGA2_UNITY_BUILD)
+        mkunity_target(db_ido_mysql db_ido_mysql_SOURCES)
+    endif()
+
+    add_library(db_ido_mysql SHARED ${db_ido_mysql_SOURCES})
 
     include_directories(${MYSQL_INCLUDE_DIR})
     target_link_libraries(db_ido_mysql ${Boost_LIBRARIES} ${MYSQL_CLIENT_LIBS} base config icinga db_ido)
index 7e589a27e617aac7a6538aa7ee42758f773f1ff8..0136a6d5ad9c525a6ff06600f5bdcbb83ec9dcb3 100644 (file)
@@ -25,7 +25,15 @@ if(PostgreSQL_FOUND)
     link_directories(${PostgreSQL_LIBRARY_DIRS})
     include_directories(${PostgreSQL_INCLUDE_DIRS})
 
-    add_library(db_ido_pgsql SHARED idopgsqlconnection.cpp idopgsqlconnection.thpp db_ido_pgsql-type.cpp)
+    set(db_ido_pgsql_SOURCES
+      idopgsqlconnection.cpp idopgsqlconnection.thpp db_ido_pgsql-type.cpp
+    )
+
+    if(ICINGA2_UNITY_BUILD)
+        mkunity_target(db_ido_pgsql db_ido_pgsql_SOURCES)
+    endif()
+
+    add_library(db_ido_pgsql SHARED ${db_ido_pgsql_SOURCES})
 
     target_link_libraries(db_ido_pgsql ${Boost_LIBRARIES} ${PostgreSQL_LIBRARIES} base config icinga db_ido)
 
index 5bd7b94f32bdfaeb463e55d51da4572f2b7ea298..ac926c9d02366a92b2577e5b2a711a23382ba252 100644 (file)
@@ -19,7 +19,15 @@ mkclass_target(demo.ti demo.thpp)
 
 mkembedconfig_target(demo-type.conf demo-type.cpp)
 
-add_library(demo SHARED demo.cpp demo.thpp demo-type.cpp)
+set(demo_SOURCES
+  demo.cpp demo.thpp demo-type.cpp
+)
+
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(demo demo_SOURCES)
+endif()
+
+add_library(demo SHARED ${demo_SOURCES})
 
 target_link_libraries(demo ${Boost_LIBRARIES} base config icinga remote)
 
index 42d2682710d4b4ae9e7fea09a38554bf8ed6d5d0..38b5915fb00ca645be56cd9a62a71f248e3f26c0 100644 (file)
@@ -19,7 +19,8 @@ mkclass_target(livestatuslistener.ti livestatuslistener.thpp)
 
 mkembedconfig_target(livestatus-type.conf livestatus-type.cpp)
 
-add_library(livestatus SHARED aggregator.cpp andfilter.cpp attributefilter.cpp
+set(livestatus_SOURCES
+  aggregator.cpp andfilter.cpp attributefilter.cpp
   avgaggregator.cpp column.cpp combinerfilter.cpp commandstable.cpp
   commentstable.cpp contactgroupstable.cpp contactstable.cpp countaggregator.cpp
   downtimestable.cpp endpointstable.cpp filter.cpp historytable.cpp
@@ -29,7 +30,14 @@ add_library(livestatus SHARED aggregator.cpp andfilter.cpp attributefilter.cpp
   minaggregator.cpp negatefilter.cpp orfilter.cpp
   servicegroupstable.cpp servicestable.cpp statehisttable.cpp
   statustable.cpp stdaggregator.cpp sumaggregator.cpp table.cpp
-  timeperiodstable.cpp livestatus-type.cpp)
+  timeperiodstable.cpp livestatus-type.cpp
+)
+
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(livestatus livestatus_SOURCES)
+endif()
+
+add_library(livestatus SHARED ${livestatus_SOURCES})
 
 target_link_libraries(livestatus ${Boost_LIBRARIES} base config icinga remote)
 
index cff9f0505e45bd8569b86f256b3e3fb122c18a3e..8da77f79d5bdefc1d719e2f97ad18a20dd5a6736 100644 (file)
@@ -19,7 +19,15 @@ mkclass_target(notificationcomponent.ti notificationcomponent.thpp)
 
 mkembedconfig_target(notification-type.conf notification-type.cpp)
 
-add_library(notification SHARED notificationcomponent.cpp notificationcomponent.thpp notification-type.cpp)
+set(notification_SOURCES
+  notificationcomponent.cpp notificationcomponent.thpp notification-type.cpp
+)
+
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(notification notification_SOURCES)
+endif()
+
+add_library(notification SHARED ${notification_SOURCES})
 
 target_link_libraries(notification ${Boost_LIBRARIES} base config icinga)
 
index 0914923ccdee5bda2704b3e36b0747859245f560..16dda3518bbac27cf7a1f09b541cd8df6983d684 100644 (file)
@@ -20,7 +20,15 @@ mkclass_target(perfdatawriter.ti perfdatawriter.thpp)
 
 mkembedconfig_target(perfdata-type.conf perfdata-type.cpp)
 
-add_library(perfdata SHARED graphitewriter.cpp graphitewriter.thpp perfdatawriter.cpp perfdatawriter.thpp perfdata-type.cpp)
+set(perfdata_SOURCES
+  graphitewriter.cpp graphitewriter.thpp perfdatawriter.cpp perfdatawriter.thpp perfdata-type.cpp
+)
+
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(perfdata perfdata_SOURCES)
+endif()
+
+add_library(perfdata SHARED ${perfdata_SOURCES})
 
 target_link_libraries(perfdata ${Boost_LIBRARIES} base config icinga)
 
index cde13a1735ff7b5cc4424f2318bbe1531682bb96..8f0f3f3495eb908f209ec42c777d6df8804409dd 100644 (file)
@@ -7,6 +7,8 @@
 #cmakedefine HAVE_DLADDR
 #cmakedefine HAVE_LIBEXECINFO
 
+#cmakedefine ICINGA2_UNITY_BUILD
+
 #define ICINGA_PREFIX "${CMAKE_INSTALL_PREFIX}"
 #define ICINGA_SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}"
 #define ICINGA_RUNDIR "${ICINGA2_RUNDIR}"
index 4dbf4d2fe84f8d2b69ebc56d94e71f20b4bae4a5..fa79a8dc1da1500db181934450f864223933353b 100644 (file)
@@ -22,7 +22,7 @@ mkclass_target(logger.ti logger.thpp)
 mkclass_target(streamlogger.ti streamlogger.thpp)
 mkclass_target(sysloglogger.ti sysloglogger.thpp)
 
-add_library(base SHARED
+set(base_SOURCES
   application.cpp application.thpp array.cpp context.cpp
   convert.cpp dictionary.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp
   exception.cpp fifo.cpp filelogger.cpp filelogger.thpp logger.cpp logger.thpp
@@ -35,10 +35,16 @@ add_library(base SHARED
   value-operators.cpp workqueue.cpp
 )
 
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(base base_SOURCES)
+endif()
+
+add_library(base SHARED ${base_SOURCES})
+
 target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cJSON mmatch)
 
 if(HAVE_LIBEXECINFO)
-  target_link_libraries(base execinfo)
+    target_link_libraries(base execinfo)
 endif()
 
 include_directories(${icinga2_SOURCE_DIR}/third-party/cJSON)
index 3d5f5baf972ae1fda48739d1119458fb21c4c3b7..19f20363439fac8d8ba0aee090c6d22da92e46cd 100644 (file)
 #      pragma warning(disable:4251)
 #      pragma warning(disable:4275)
 #      pragma warning(disable:4345)
-#else /* _MSC_VER */
-#      include "config.h"
 #endif /* _MSC_VER */
 
+#include "config.h"
+
 #ifdef _WIN32
 #      include "base/win32.hpp"
 #else
index ceb3554502b9cdf4045eeb7a9a677a7bed9ba69c..5baf050e71226554c3a9d2142f107d71abbb7329 100644 (file)
@@ -35,9 +35,9 @@ inline bool InitializeOnceHelper(InitializeFunc func)
 }
 
 #define INITIALIZE_ONCE(func) \
-       namespace { \
+       namespace { namespace TOKENPASTE2(io, __COUNTER__) { \
                I2_EXPORT bool l_InitializeOnce(icinga::InitializeOnceHelper(func)); \
-       }
+       } }
 
 }
 
index b4966c0a9c7a1acd0ba3ef529a5932a542c34052..4656796ac2f2a12243f789122410be19a84ee227 100644 (file)
@@ -24,6 +24,7 @@
 #include "base/qstring.hpp"
 #include "base/object.hpp"
 #include "base/initialize.hpp"
+#include "base/utility.hpp"
 #include <boost/function.hpp>
 
 namespace icinga
@@ -99,7 +100,7 @@ struct FactoryHelper
 };
 
 #define REGISTER_TYPE(type) \
-       namespace { \
+       namespace { namespace TOKENPASTE2(rt, __COUNTER__) { \
                void RegisterType(void) \
                { \
                        icinga::Type *t = new TypeImpl<type>(); \
@@ -108,7 +109,7 @@ struct FactoryHelper
                } \
                \
                INITIALIZE_ONCE(RegisterType); \
-       }
+       } }
 
 }
 
index c49beeb54247d0595214dcfbd6a9a2a78d7b055f..bd3dc8021981b1c231b360c660f2cef057903f72 100644 (file)
 namespace icinga
 {
 
+#define TOKENPASTE(x, y) x ## y
+#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
+
+#if defined(ICINGA2_UNITY_BUILD) && !defined(__COUNTER__)
+#      error "Your compiler needs to support __COUNTER__ in order to do unity builds."
+#endif /* ICINGA2_UNITY_BUILD && !defined(__COUNTER__) */
+
 #ifdef _WIN32
 #define MS_VC_EXCEPTION 0x406D1388
 
index 30dafd5a2ed1d6a79932b58e00118b66b8b9e4c0..1929b824a4a3c5b624631f41048088f92895a453 100644 (file)
@@ -26,13 +26,19 @@ mkembedconfig_target(base-type.conf base-type.cpp)
 
 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
 
-add_library(config SHARED
+set(config_SOURCES
   aexpression.cpp applyrule.cpp base-type.conf base-type.cpp
   configcompilercontext.cpp configcompiler.cpp configerror.cpp configitembuilder.cpp
   configitem.cpp ${FLEX_config_lexer_OUTPUTS} ${BISON_config_parser_OUTPUTS}
   configtype.cpp debuginfo.cpp objectrule.cpp typerule.cpp typerulelist.cpp
 )
 
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(config config_SOURCES)
+endif()
+
+add_library(config SHARED ${config_SOURCES})
+
 target_link_libraries(config ${Boost_LIBRARIES} base) 
 
 set_target_properties (
index 43f7b6548a27f3943479f6d84af6c40b40e22932..222d906f1e1fc89e9bddd40ef17898fd990a9274 100644 (file)
@@ -19,7 +19,7 @@ mkclass_target(dbconnection.ti dbconnection.thpp)
 
 mkembedconfig_target(db_ido-type.conf db_ido-type.cpp)
 
-add_library(db_ido SHARED
+set(db_ido_SOURCES
   commanddbobject.cpp dbconnection.cpp dbconnection.thpp dbconnection.thpp
   db_ido-type.cpp dbevents.cpp dbobject.cpp dbquery.cpp dbreference.cpp dbtype.cpp
   dbvalue.cpp endpointdbobject.cpp hostdbobject.cpp hostgroupdbobject.cpp
@@ -27,6 +27,12 @@ add_library(db_ido SHARED
   userdbobject.cpp usergroupdbobject.cpp
 )
 
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(db_ido db_ido_SOURCES)
+endif()
+
+add_library(db_ido SHARED ${db_ido_SOURCES})
+
 include_directories(${Boost_INCLUDE_DIRS})
 target_link_libraries(db_ido ${Boost_LIBRARIES} base config icinga remote)
 
index 04dda707166c11dba16f9b906c1f6bc8c2a3deca..ce92e30f05555fbfa1f09e6d4453fc3ddbc01aa4 100644 (file)
@@ -19,10 +19,16 @@ mkclass_target(hello.ti hello.thpp)
 
 mkembedconfig_target(hello-type.conf hello-type.cpp)
 
-add_library(hello SHARED
+set(hello_SOURCES
   hello.cpp hello.thpp hello-type.cpp
 )
 
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(hello hello_SOURCES)
+endif()
+
+add_library(hello SHARED ${hello_SOURCES})
+
 target_link_libraries(hello ${Boost_LIBRARIES} base config)
 
 set_target_properties (
index 95363441f63e1eaf4cc9a13981b148b39107c797..cc61297c31306f27911de6888e400871f817d0fb 100644 (file)
@@ -40,7 +40,7 @@ mkclass_target(user.ti user.thpp)
 
 mkembedconfig_target(icinga-type.conf icinga-type.cpp)
 
-add_library(icinga SHARED
+set(icinga_SOURCES
   api.cpp apievents.cpp checkable.cpp checkable.thpp checkable-dependency.cpp checkable-downtime.cpp checkable-event.cpp
   checkable-flapping.cpp checkcommand.cpp checkcommand.thpp checkresult.cpp checkresult.thpp
   cib.cpp command.cpp command.thpp comment.cpp comment.thpp compatutility.cpp dependency.cpp dependency.thpp
@@ -54,6 +54,12 @@ add_library(icinga SHARED
   user.cpp user.thpp usergroup.cpp usergroup.thpp icinga-type.cpp
 )
 
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(icinga icinga_SOURCES)
+endif()
+
+add_library(icinga SHARED ${icinga_SOURCES})
+
 target_link_libraries(icinga ${Boost_LIBRARIES} base config remote)
 
 set_target_properties (
index 3ec48730c35f0f19044a9b45ba19e275f022bf78..35b5571388ef189841fa942386fd068a6bd50ad9 100644 (file)
@@ -21,13 +21,19 @@ else()
   set(WindowsSources "")
 endif()
 
-add_library(methods SHARED
+set(methods_SOURCES
   castfuncs.cpp clusterchecktask.cpp clusterzonechecktask.cpp
   icingachecktask.cpp nullchecktask.cpp nulleventtask.cpp
   pluginchecktask.cpp plugineventtask.cpp pluginnotificationtask.cpp
   randomchecktask.cpp timeperiodtask.cpp ${WindowsSources}
 )
 
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(methods methods_SOURCES)
+endif()
+
+add_library(methods SHARED ${methods_SOURCES})
+
 target_link_libraries(methods ${Boost_LIBRARIES} base config icinga)
 
 set_target_properties (
index 5bff6e4da3d5b13abc956a1d23ea2d4b3da65ab2..b30b8dbfa26eb87b77fae56d1c968b1f48ea9d3e 100644 (file)
@@ -21,12 +21,18 @@ mkclass_target(zone.ti zone.thpp)
 
 mkembedconfig_target(remote-type.conf remote-type.cpp)
 
-add_library(remote SHARED
+set(remote_SOURCES
   apiclient.cpp apifunction.cpp apilistener.cpp apilistener-sync.cpp
   apilistener.thpp authority.cpp endpoint.cpp endpoint.thpp jsonrpc.cpp
   messageorigin.cpp remote-type.cpp zone.cpp zone.thpp
 )
 
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(remote remote_SOURCES)
+endif()
+
+add_library(remote SHARED ${remote_SOURCES})
+
 include_directories(${Boost_INCLUDE_DIRS})
 target_link_libraries(remote ${Boost_LIBRARIES} base config)
 
index cea166d0d68226d289d13a9b31e1dd2251605e6d..29f480794d31a58a239b085fed4fc49061ce102e 100644 (file)
 
 include(BoostTestTargets)
 
+set(base_test_SOURCES
+  base-array.cpp base-convert.cpp base-dictionary.cpp base-fifo.cpp
+  base-match.cpp base-netstring.cpp base-object.cpp base-serialize.cpp
+  base-shellescape.cpp base-stacktrace.cpp base-stream.cpp
+  base-string.cpp base-timer.cpp base-type.cpp base-value.cpp
+  icinga-perfdata.cpp test.cpp
+)
+
+if(ICINGA2_UNITY_BUILD)
+    mkunity_target(test base_test_SOURCES)
+endif()
+
 add_boost_test(base
-  SOURCES base-array.cpp base-convert.cpp base-dictionary.cpp base-fifo.cpp
-          base-match.cpp base-netstring.cpp base-object.cpp base-serialize.cpp
-          base-shellescape.cpp base-stacktrace.cpp base-stream.cpp
-          base-string.cpp base-timer.cpp base-type.cpp base-value.cpp
-          icinga-perfdata.cpp test.cpp
+  SOURCES test.cpp ${base_test_SOURCES}
   LIBRARIES base config icinga
   TESTS base_array/construct
         base_array/getset
index cc799f845aaa56450bb9df877ef5608bc58dceb2..cefbb7012eea583337536c85dfae69b875bd34bc 100644 (file)
@@ -17,6 +17,7 @@
 
 add_subdirectory(mkclass)
 add_subdirectory(mkembedconfig)
+add_subdirectory(mkunity)
 
 if(UNIX OR CYGWIN)
   configure_file(icinga2-enable-feature.cmake ${CMAKE_CURRENT_BINARY_DIR}/icinga2-enable-feature @ONLY)
diff --git a/tools/mkunity/CMakeLists.txt b/tools/mkunity/CMakeLists.txt
new file mode 100644 (file)
index 0000000..18e331b
--- /dev/null
@@ -0,0 +1,47 @@
+# Icinga 2
+# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+add_executable(mkunity mkunity.c)
+
+set_target_properties (
+  mkunity PROPERTIES
+  FOLDER Bin
+)
+
+function(MKUNITY_TARGET Prefix UnityInputRef)
+    set(UnityInput ${${UnityInputRef}})
+    set(UnityOutput ${CMAKE_CURRENT_BINARY_DIR}/${Prefix}_unity.cpp)
+    set(RealSources "")
+    set(UnitySources "")
+    foreach(UnitySource ${UnityInput})
+        if(${UnitySource} MATCHES "\\.cpp\$")
+            list(APPEND UnitySources ${UnitySource})
+        else()
+            list(APPEND RealSources ${UnitySource})
+        endif()
+    endforeach()
+    add_custom_command(
+        OUTPUT ${UnityOutput}
+        COMMAND mkunity
+        ARGS ${Prefix} ${UnitySources} >${UnityOutput}
+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        DEPENDS mkunity ${UnityInput}
+    )
+    list(APPEND RealSources ${UnityOutput})
+    set(${UnityInputRef} ${RealSources} PARENT_SCOPE)
+endfunction()
+
diff --git a/tools/mkunity/mkunity.c b/tools/mkunity/mkunity.c
new file mode 100644 (file)
index 0000000..fb24fd4
--- /dev/null
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
+ *                                                                            *
+ * This program is free software; you can redistribute it and/or              *
+ * modify it under the terms of the GNU General Public License                *
+ * as published by the Free Software Foundation; either version 2             *
+ * of the License, or (at your option) any later version.                     *
+ *                                                                            *
+ * This program is distributed in the hope that it will be useful,            *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ * GNU General Public License for more details.                               *
+ *                                                                            *
+ * You should have received a copy of the GNU General Public License          *
+ * along with this program; if not, write to the Free Software Foundation     *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
+ ******************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+       int i;
+
+       if (argc < 3) {
+               fprintf(stderr, "Syntax: %s <prefix> [<file> ...]\n", argv[0]);
+               return EXIT_FAILURE;
+       }
+
+       for (i = 2; i < argc; i++) {
+               printf("#include \"%s/%s\"\n", argv[1], argv[i]);
+       }
+
+       return EXIT_SUCCESS;
+}