From 6e7600278ff36ab767b6a809d88a0774c9c89968 Mon Sep 17 00:00:00 2001 From: Timo Lotterbach Date: Wed, 2 Jan 2013 04:59:21 -0800 Subject: [PATCH] CMake: improved dependency handling using add_subdirectory_once macro each component now just builds all components it dependes on using the custom macro 'add_subdirectory_once'. During the first call, add_subdirectory_once will add the subdirectory to the current build. all subsequent calls are silently ignored. This solves the basic problem of double definition of components which result in cmake errors. Signed-off-by: Timo Lotterbach --- 3rdParty/{ => gmock}/CMakeLists.txt | 36 ++++------- 3rdParty/gtest/CMakeLists.txt | 28 ++++++++ 3rdParty/systemd/CMakeLists.txt | 25 ++++++++ CMakeLists.txt | 124 +++++++++++++++++------------------- cmake/modules/CustomMacros.txt | 26 ++++++++ 5 files changed, 152 insertions(+), 87 deletions(-) rename 3rdParty/{ => gmock}/CMakeLists.txt (59%) create mode 100644 3rdParty/gtest/CMakeLists.txt create mode 100644 3rdParty/systemd/CMakeLists.txt create mode 100644 cmake/modules/CustomMacros.txt diff --git a/3rdParty/CMakeLists.txt b/3rdParty/gmock/CMakeLists.txt similarity index 59% rename from 3rdParty/CMakeLists.txt rename to 3rdParty/gmock/CMakeLists.txt index 4b342f0..32d51d9 100644 --- a/3rdParty/CMakeLists.txt +++ b/3rdParty/gmock/CMakeLists.txt @@ -1,18 +1,18 @@ ############################################################################ -# -# Copyright 2010, 2011 BMW Car IT GmbH -# -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# Copyright 2010-2012 BMW Car IT GmbH # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. # ############################################################################ @@ -22,15 +22,7 @@ set (CMAKE_C_FLAGS "") set (CMAKE_CXX_FLAGS "") # include base path to 3rdParty code -include_directories (".") - -# build systemd reference client library -if (WITH_SYSTEMD_HEALTH_MONITOR) - add_library(systemd systemd/sd-daemon.c) -endif (WITH_SYSTEMD_HEALTH_MONITOR) +include_directories ("..") # build unit test frameworks, if tests are enabled -if (WITH_TESTS) - add_library(gtest gtest/gtest-all.cc gtest/gtest_main.cc) - add_library(gmock gmock/gmock-gtest-all.cc gmock/gmock_main.cc) -endif(WITH_TESTS) +add_library(gmock STATIC gmock-gtest-all.cc gmock_main.cc) diff --git a/3rdParty/gtest/CMakeLists.txt b/3rdParty/gtest/CMakeLists.txt new file mode 100644 index 0000000..2e5e675 --- /dev/null +++ b/3rdParty/gtest/CMakeLists.txt @@ -0,0 +1,28 @@ +############################################################################ +# +# Copyright 2010-2012 BMW Car IT GmbH +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################ + +# set default compiler flags for 3rdParty code +set (CMAKE_C_FLAGS "") +set (CMAKE_CXX_FLAGS "") + +# include base path to 3rdParty code +include_directories ("..") + +# build unit test frameworks, if tests are enabled +add_library(gtest STATIC gtest-all.cc gtest_main.cc) diff --git a/3rdParty/systemd/CMakeLists.txt b/3rdParty/systemd/CMakeLists.txt new file mode 100644 index 0000000..63c196c --- /dev/null +++ b/3rdParty/systemd/CMakeLists.txt @@ -0,0 +1,25 @@ +############################################################################ +# +# Copyright 2012 BMW Car IT GmbH +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################ + +# set default compiler flags for 3rdParty code +set (CMAKE_C_FLAGS "") +set (CMAKE_CXX_FLAGS "") + +# build systemd reference client library +add_library(systemd STATIC sd-daemon.c) diff --git a/CMakeLists.txt b/CMakeLists.txt index 074d4a8..12b8d14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,9 +21,12 @@ cmake_minimum_required (VERSION 2.6) project (LayerManager) +#============================================================================== +# cmake configuration +#============================================================================== set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") - include(${CMAKE_MODULE_PATH}/CMakeVersions.txt) +include(${CMAKE_MODULE_PATH}/CustomMacros.txt) #============================================================================== # set default build type, if not defined by user @@ -35,7 +38,6 @@ if (NOT CMAKE_BUILD_TYPE) message(STATUS "Build type not defined. Using default build type 'Release'.") endif (NOT CMAKE_BUILD_TYPE) - #============================================================================== # Platforms / A set of indiviual options at once #============================================================================== @@ -62,16 +64,12 @@ option (WITH_EXAMPLE_SCENE_PROVIDER "Build scene provider plugin for examples" option (WITH_STATIC_LIBRARIES "Link all libraries statically" OFF) option (WITH_TEXT_RENDERER "Build text renderer (only logging)" OFF) - #============================================================================== # Internal global settings not available to user #============================================================================== set (WITH_WAYLAND OFF) -set (BUILD_UTILS_LIB OFF) -set (INSTALL_UTILS_LIB OFF) set (STATICALLY_LINKED_PLUGINS "" CACHE INTERNAL "list of static plugins" FORCE) - #============================================================================== # make sure, only one wayland based renderer was selected #============================================================================== @@ -110,13 +108,16 @@ include_directories ("${PROJECT_SOURCE_DIR}/3rdParty/") # ilm_types are used internally to LM, so we can include them by default include_directories ("${PROJECT_SOURCE_DIR}/LayerManagerClient/ilmClient/include") - #============================================================================== -# default compiler settings for 3rd party components +# enable ctest if building with tests +# run 'make test' after build to run all tests +# be aware that some tests require a running layermanager #============================================================================== - -add_subdirectory (3rdParty) - +if (WITH_TESTS) + enable_testing() + add_subdirectory_once (3rdParty/gtest) + add_subdirectory_once (3rdParty/gmock) +endif(WITH_TESTS) #============================================================================== # use strict compiler settings for examples and tools @@ -126,32 +127,37 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") #============================================================================== if (WITH_EGL_EXAMPLE) - add_subdirectory (LayerManagerExamples/EGLX11ApplicationExample) - add_subdirectory (LayerManagerExamples/EGLX11MockNavigation) - set (BUILD_UTILS_LIB ON) + add_subdirectory_once (LayerManagerUtils) + add_subdirectory_once (LayerManagerClient/ilmClient) + add_subdirectory_once (LayerManagerExamples/EGLX11ApplicationExample) + add_subdirectory_once (LayerManagerExamples/EGLX11MockNavigation) endif(WITH_EGL_EXAMPLE) if (WITH_GLX_EXAMPLE) - add_subdirectory (LayerManagerExamples/GLXApplicationExample) - set (BUILD_UTILS_LIB ON) + add_subdirectory_once (LayerManagerUtils) + add_subdirectory_once (LayerManagerClient/ilmClient) + add_subdirectory_once (LayerManagerExamples/GLXApplicationExample) endif(WITH_GLX_EXAMPLE) if (WITH_CLIENTEXAMPLES) - add_subdirectory (LayerManagerExamples/LayerManagerClientExample) - set (BUILD_UTILS_LIB ON) + add_subdirectory_once (LayerManagerUtils) + add_subdirectory_once (LayerManagerClient/ilmClient) + add_subdirectory_once (LayerManagerExamples/LayerManagerClientExample) endif(WITH_CLIENTEXAMPLES) if (WITH_WL_EXAMPLE) - add_subdirectory (LayerManagerExamples/EGLWLApplicationExample) - add_subdirectory (LayerManagerExamples/EGLWLMockNavigation) - add_subdirectory (LayerManagerExamples/WLChromakeyExample) - add_subdirectory (LayerManagerExamples/EGLWLInputEventExample) - set (BUILD_UTILS_LIB ON) + add_subdirectory_once (LayerManagerUtils) + add_subdirectory_once (LayerManagerClient/ilmClient) + add_subdirectory_once (LayerManagerExamples/EGLWLApplicationExample) + add_subdirectory_once (LayerManagerExamples/EGLWLMockNavigation) + add_subdirectory_once (LayerManagerExamples/WLChromakeyExample) + add_subdirectory_once (LayerManagerExamples/EGLWLInputEventExample) endif(WITH_WL_EXAMPLE) if (WITH_CONTROL_BIN) - add_subdirectory (LayerManagerControl) - set (BUILD_UTILS_LIB ON) + add_subdirectory_once (LayerManagerUtils) + add_subdirectory_once (LayerManagerClient/ilmClient) + add_subdirectory_once (LayerManagerControl) endif(WITH_CONTROL_BIN) #============================================================================== @@ -163,70 +169,58 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function") #============================================================================== if (WITH_EXAMPLE_SCENE_PROVIDER) - add_subdirectory (LayerManagerPlugins/SceneProvider/ExampleSceneProvider) + add_subdirectory_once (LayerManagerCommands) + add_subdirectory_once (LayerManagerBase) + add_subdirectory_once (LayerManagerPlugins/SceneProvider/ExampleSceneProvider) endif(WITH_EXAMPLE_SCENE_PROVIDER) if (WITH_SYSTEMD_HEALTH_MONITOR) - add_subdirectory (LayerManagerPlugins/HealthMonitor/SystemdHealthMonitor) + add_subdirectory_once (3rdParty/systemd) + add_subdirectory_once (LayerManagerUtils) + add_subdirectory_once (LayerManagerBase) + add_subdirectory_once (LayerManagerPlugins/HealthMonitor/SystemdHealthMonitor) endif(WITH_SYSTEMD_HEALTH_MONITOR) if (WITH_GENERIC_COMMUNICATOR) - add_subdirectory (LayerManagerCommands) - add_subdirectory (LayerManagerPlugins/Communicators/GenericCommunicator) + add_subdirectory_once (LayerManagerPlugins/IpcModules) + add_subdirectory_once (LayerManagerCommands) + add_subdirectory_once (LayerManagerPlugins/Communicators/GenericCommunicator) endif(WITH_GENERIC_COMMUNICATOR) if (WITH_DESKTOP) set (WITH_GLX_LIB ON CACHE BOOL "Build X11 GLX development lib" FORCE) - add_subdirectory (LayerManagerPlugins/Renderers/Platform/GLXRenderer) + add_subdirectory_once (LayerManagerPlugins/Renderers/Graphic) + add_subdirectory_once (LayerManagerPlugins/Renderers/Platform/GLXRenderer) endif(WITH_DESKTOP) if (WITH_WAYLAND) - add_subdirectory (LayerManagerPlugins/Renderers/Platform/WaylandGLESRenderer) + add_subdirectory_once (LayerManagerPlugins/Renderers/Platform/WaylandGLESRenderer) endif(WITH_WAYLAND) if (WITH_X11_GLES) set (WITH_GLESv2_LIB ON CACHE BOOL "Build X11 GLES development lib" FORCE) - add_subdirectory (LayerManagerPlugins/Renderers/Platform/X11GLESRenderer) + add_subdirectory_once (LayerManagerPlugins/Renderers/Graphic) + add_subdirectory_once (LayerManagerPlugins/Renderers/Platform/X11GLESRenderer) endif(WITH_X11_GLES) if (WITH_TEXT_RENDERER) - add_subdirectory (LayerManagerPlugins/Renderers/Platform/TextRenderer) + add_subdirectory_once (LayerManagerPlugins/Renderers/Platform/TextRenderer) endif(WITH_TEXT_RENDERER) -if (WITH_SERVICE_BIN OR WITH_CLIENT_LIB) - add_subdirectory (LayerManagerPlugins/IpcModules) +if (WITH_SERVICE_BIN) + add_subdirectory_once (LayerManagerUtils) + add_subdirectory_once (LayerManagerPlugins/IpcModules) + add_subdirectory_once (LayerManagerPlugins/Renderers/Graphic) + add_subdirectory_once (LayerManagerBase) + add_subdirectory_once (LayerManagerService) +endif (WITH_SERVICE_BIN) - if (WITH_SERVICE_BIN) - add_subdirectory (LayerManagerPlugins/Renderers/Graphic) - add_subdirectory (LayerManagerBase) - add_subdirectory (LayerManagerService) - set (BUILD_UTILS_LIB ON) - set (INSTALL_UTILS_LIB ON) - endif (WITH_SERVICE_BIN) - - if (WITH_CLIENT_LIB) - add_subdirectory (LayerManagerClient/ilmClient) - endif (WITH_CLIENT_LIB) - -endif (WITH_SERVICE_BIN OR WITH_CLIENT_LIB) - -#============================================================================== -# build internal libraries, if required by other components -#============================================================================== -if (BUILD_UTILS_LIB) - add_subdirectory (LayerManagerUtils) -endif (BUILD_UTILS_LIB) - -#============================================================================== -# enable ctest if building with tests -# run 'make test' after build to run all tests -# be aware that some tests require a running layermanager -#============================================================================== -if (WITH_TESTS) - enable_testing() -endif(WITH_TESTS) +if (WITH_CLIENT_LIB) + add_subdirectory_once (LayerManagerPlugins/IpcModules) + add_subdirectory_once (LayerManagerClient/ilmClient) +endif (WITH_CLIENT_LIB) #============================================================================== # store used build configuration #============================================================================== -add_subdirectory(config) +add_subdirectory_once(config) diff --git a/cmake/modules/CustomMacros.txt b/cmake/modules/CustomMacros.txt new file mode 100644 index 0000000..0010a7b --- /dev/null +++ b/cmake/modules/CustomMacros.txt @@ -0,0 +1,26 @@ +############################################################################ +# +# Copyright 2010-2012 BMW Car IT GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################ + +MACRO(add_subdirectory_once path) + get_filename_component(subdir ${path} NAME) + if (NOT ${subdir}_already_built) + set(${subdir}_already_built 1) + add_subdirectory(${path}) + endif (NOT ${subdir}_already_built) +ENDMACRO(add_subdirectory_once) + -- 2.7.4