Skip to content

Commit

Permalink
Import updated modules from cmake-3.5 and YCM and fix GTK2 c++11 issues
Browse files Browse the repository at this point in the history
All GTK related modules now use imported targets. This means that for
CMake 3.1 or later, c++11 is automatically enabled. for older versions,
it is manually enabled wherever it is required.

NOTE: conf/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake initial
comment changed from new style to old style.

Fixes robotology#598
CC-Issue: robotology/icub-main#232
  • Loading branch information
drdanz committed Nov 2, 2015
1 parent 2666c60 commit df015b0
Show file tree
Hide file tree
Showing 26 changed files with 1,462 additions and 163 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ project(YARP)
# Pick up our CMake scripts - they are all in the conf subdirectory.
set(YARP_MODULE_DIR ${PROJECT_SOURCE_DIR}/conf)
set(YARP_MODULE_PATH ${YARP_MODULE_DIR})
if(${CMAKE_VERSION} VERSION_LESS 3.5)
list(APPEND YARP_MODULE_PATH ${PROJECT_SOURCE_DIR}/conf/cmake-3.5/Modules)
endif()
if(${CMAKE_VERSION} VERSION_LESS 3.1)
list(APPEND YARP_MODULE_PATH ${PROJECT_SOURCE_DIR}/conf/cmake-3.1/Modules)
endif()
Expand Down
26 changes: 18 additions & 8 deletions conf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,33 @@ install(FILES ${YARP_TEMPLATE_FILES}
COMPONENT scripts
DESTINATION share/yarp/cmake/template)


# Files from CMake 3.1, available only if cmake is older
if(${CMAKE_VERSION} VERSION_LESS 3.1)
set(YARP_CMAKE_3_1_FILES cmake-3.1/Modules/FindGTK2.cmake
cmake-3.1/Modules/FindPackageHandleStandardArgs.cmake
cmake-3.1/Modules/FindPackageMessage.cmake
cmake-3.1/Modules/CMakeParseArguments.cmake
cmake-3.1/Modules/SelectLibraryConfigurations.cmake
cmake-3.1/Modules/FindFreetype.cmake
set(YARP_CMAKE_3_1_FILES cmake-3.1/Modules/CMakeFindDependencyMacro.cmake # 3.0
cmake-3.1/Modules/CMakePackageConfigHelpers.cmake
cmake-3.1/Modules/CMakeParseArguments.cmake
cmake-3.1/Modules/FeatureSummary.cmake
cmake-3.1/Modules/FindLua.cmake)
cmake-3.1/Modules/FindFreetype.cmake # 3.0
cmake-3.1/Modules/FindLua.cmake # 3.0
cmake-3.1/Modules/FindPackageHandleStandardArgs.cmake
cmake-3.1/Modules/FindPackageMessage.cmake
cmake-3.1/Modules/GNUInstallDirs.cmake)
install(FILES ${YARP_CMAKE_3_1_FILES}
COMPONENT scripts
DESTINATION share/yarp/cmake/cmake-3.1/Modules)
endif()

# Files from CMake 3.5, available only if cmake is older
if(${CMAKE_VERSION} VERSION_LESS 3.5)
set(YARP_CMAKE_3_5_FILES cmake-3.5/Modules/FindFreetype.cmake
cmake-3.5/Modules/FindGTK2.cmake
cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake
cmake-3.5/Modules/FindPackageMessage.cmake
cmake-3.5/Modules/SelectLibraryConfigurations.cmake)
install(FILES ${YARP_CMAKE_3_5_FILES}
COMPONENT scripts
DESTINATION share/yarp/cmake/cmake-3.5/Modules)
endif()

# Deprecated modules installed for compatibility
if(NOT YARP_NO_DEPRECATED)
Expand Down
11 changes: 9 additions & 2 deletions conf/FindGooCanvas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# GooCanvas_TWEAK_VERSION - GooCanvas tweak version

#=============================================================================
# Copyright 2012-2013 iCub Facility, Istituto Italiano di Tecnologia
# Copyright 2012-2015 iCub Facility, Istituto Italiano di Tecnologia
# Authors: Daniele E. Domenichelli <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
Expand All @@ -31,7 +31,14 @@


include(StandardFindModule)
standard_find_module(GooCanvas goocanvas)
include(ReplaceImportedTargets)
include(CMakeFindDependencyMacro)

find_dependency(GTK2)

standard_find_module(GooCanvas goocanvas
TARGET GooCanvas::goocanvas
REPLACE_TARGETS ${GTK2_LIBRARIES})

# Set package properties if FeatureSummary was included
if(COMMAND set_package_properties)
Expand Down
13 changes: 11 additions & 2 deletions conf/FindGooCanvasMM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# GooCanvasMM_TWEAK_VERSION - GooCanvasMM tweak version

#=============================================================================
# Copyright 2012-2013 iCub Facility, Istituto Italiano di Tecnologia
# Copyright 2012-2015 iCub Facility, Istituto Italiano di Tecnologia
# Authors: Daniele E. Domenichelli <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
Expand All @@ -31,7 +31,16 @@


include(StandardFindModule)
standard_find_module(GooCanvasMM goocanvasmm-1.0)
include(ReplaceImportedTargets)
include(CMakeFindDependencyMacro)

find_dependency(GTK2)
find_dependency(GooCanvas)

standard_find_module(GooCanvasMM goocanvasmm-1.0
TARGET GooCanvasMM::goocanvasmm
REPLACE_TARGETS ${GTK2_LIBRARIES}
${GooCanvas_LIBRARIES})

# Set package properties if FeatureSummary was included
if(COMMAND set_package_properties)
Expand Down
11 changes: 9 additions & 2 deletions conf/FindGtkDatabox.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# GtkDatabox_TWEAK_VERSION - GtkDatabox tweak version

#=============================================================================
# Copyright 2012-2013 iCub Facility, Istituto Italiano di Tecnologia
# Copyright 2012-2015 iCub Facility, Istituto Italiano di Tecnologia
# Authors: Daniele E. Domenichelli <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
Expand All @@ -31,7 +31,14 @@


include(StandardFindModule)
standard_find_module(GtkDatabox gtkdatabox)
include(ReplaceImportedTargets)
include(CMakeFindDependencyMacro)

find_dependency(GTK2)

standard_find_module(GtkDatabox gtkdatabox
TARGET GtkDatabox::gtkdatabox
REPLACE_TARGETS ${GTK2_LIBRARIES})

# Set package properties if FeatureSummary was included
if(COMMAND set_package_properties)
Expand Down
14 changes: 12 additions & 2 deletions conf/FindGtkDataboxMM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# GtkDataboxMM_TWEAK_VERSION - GtkDataboxMM tweak version

#=============================================================================
# Copyright 2012-2013 iCub Facility, Istituto Italiano di Tecnologia
# Copyright 2012-2015 iCub Facility, Istituto Italiano di Tecnologia
# Authors: Daniele E. Domenichelli <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
Expand All @@ -29,8 +29,18 @@
# (To distribute this file outside of YCM, substitute the full
# License text for the above reference.)


include(StandardFindModule)
standard_find_module(GtkDataboxMM gtkdataboxmm-0.9)
include(ReplaceImportedTargets)
include(CMakeFindDependencyMacro)

find_dependency(GTK2)
find_dependency(GtkDatabox)

standard_find_module(GtkDataboxMM gtkdataboxmm-0.9
TARGET GtkDataboxMM::gtkdataboxmm
REPLACE_TARGETS ${GTK2_LIBRARIES}
${GtkDatabox_LIBRARIES})

# Set package properties if FeatureSummary was included
if(COMMAND set_package_properties)
Expand Down
113 changes: 113 additions & 0 deletions conf/ReplaceImportedTargets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#.rst:
# ReplaceImportedTargets
# ----------------------
#
# Adds the :command:`replace_imported_targets` command that useful to
# replace paths with imported targets in link variables (like
# ``<FOO>_LIBRARIES``) and targets.
#
# .. command:: replace_imported_targets
#
# Replace imported targets in a list of and targets and paths::
#
# replace_imported_targets(<var> [target [target [...]]])
#
# Each path in ``var`` corrisponding to one of the ``targets`` will be
# replaced with the corrisponding ``target``, taking care to remove the
# relative ``optimized`` and ``debug`` keywords.
#
# For each existing target in ``var``, the following properties will be
# searched for imported locations of targets, and, if set, will be
# replaced in the same way::
#
# IMPORTED_LINK_DEPENDENT_LIBRARIES
# IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>
# IMPORTED_LINK_INTERFACE_LIBRARIES
# IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>
# INTERFACE_LINK_LIBRARIES
# LINK_INTERFACE_LIBRARIES
# LINK_INTERFACE_LIBRARIES_<CONFIG>
# LINK_LIBRARIES

#=============================================================================
# Copyright 2015 iCub Facility, Istituto Italiano di Tecnologia
# Authors: Daniele E. Domenichelli <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of YCM, substitute the full
# License text for the above reference.)


function(_REPLACE_IMPORTED_TARGETS_INTERNAL _var)
foreach(_target ${ARGN})
if(TARGET ${_target})
get_target_property(_imported ${_target} IMPORTED)
if(_imported)
get_target_property(_configurations ${_target} IMPORTED_CONFIGURATIONS)
foreach(_conf ${_configurations})
get_target_property(_location ${_target} IMPORTED_LOCATION_${_conf})
string(REGEX REPLACE "((optimized|debug);)?${_location}" ${_target} ${_var} "${${_var}}")
endforeach()
endif()
endif()
endforeach()
list(REMOVE_DUPLICATES ${_var})
set(${_var} ${${_var}} PARENT_SCOPE)
endfunction()


function(REPLACE_IMPORTED_TARGETS _var)
set(_replace_targets ${ARGN})

if(TARGET ${_var})
set(_tgt ${_var})
else()
set(_tgt ${${_var}})
endif()
foreach(_target ${_tgt})
if(TARGET ${_target})

# Replace in all link related properties.
set(_properties IMPORTED_LINK_DEPENDENT_LIBRARIES
IMPORTED_LINK_INTERFACE_LIBRARIES
INTERFACE_LINK_LIBRARIES
LINK_INTERFACE_LIBRARIES
LINK_LIBRARIES)
get_property(_configurations TARGET ${_target} PROPERTY IMPORTED_CONFIGURATIONS)
foreach(_config ${_configurations})
list(APPEND _properties IMPORTED_LINK_DEPENDENT_LIBRARIES_${_config}
IMPORTED_LINK_INTERFACE_LIBRARIES_${_config}
LINK_INTERFACE_LIBRARIES_${_config})
endforeach()

foreach(_prop ${_properties})
get_property(_prop_set TARGET ${_target} PROPERTY ${_prop} SET)
if(_prop_set)
get_property(_prop_value TARGET ${_target} PROPERTY ${_prop})
_replace_imported_targets_internal(_prop_value ${_replace_targets})

# CMake 3.0.x throws an exception when setting an empty
# property. All the other versions are fine with it.
# Remove this check when CMake minimum required version is
# 3.1 or higher.
if(NOT ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_EQUAL 3.0 AND "${_prop_value}" STREQUAL ""))
set_property(TARGET ${_target} PROPERTY ${_prop} ${_prop_value})
endif()
endif()
endforeach()
endif()
endforeach()

if(NOT TARGET ${_var})
# replace in the variable.
_replace_imported_targets_internal(${_var} ${_replace_targets})
set(${_var} ${${_var}} PARENT_SCOPE)
endif()

endfunction()
Loading

0 comments on commit df015b0

Please sign in to comment.