Commit 9fe22cf9 authored by Christoph Grüninger's avatar Christoph Grüninger

[CMake] Repair shared libraries for CMake < 3.0.

a) OBJECT is needed to avoid linking libdunegrid to itself.
b) Linking a library to itself will become an error in CMake 3.0.
c) Shared libraries build with OBJECT will fail for user code
   that links DUNE_LIBS but sets not the flags for the linked
   grids (e.g. in dune-localfunctions 2.3 or dune-pdelab).
   The order of libs is not correct, libdunegrid should be
   before the external grids.
d) Staying compatible with CMake 2.8.6 forces us to not
   use the linking stuff introduced by 2.8.9 and 2.8.12.
e) Maybe we can fix this in Dune's code, but not as fast
   as needed.
Due to a) - e) you cannot build shared libraries with external
grids and CMake 3.0.
Static libs do work.

(cherry picked from commit a21f4572)
Signed-off-by: Christoph Grüninger's avatarChristoph Grüninger <gruenich@dune-project.org>
parent 751a6b52
......@@ -5,14 +5,21 @@ if(UG_FOUND)
set(UGLIB _DUNE_TARGET_OBJECTS:uggrid_)
endif(UG_FOUND)
# OBJECT is needed since CMake 3.0.0
# but it conflicts with shared libs
set(_OBJECT_FLAG "OBJECT")
if(BUILD_SHARED_LIBS)
set(_OBJECT_FLAG "")
endif()
dune_add_library(dunegrid
_DUNE_TARGET_OBJECTS:onedgrid_
_DUNE_TARGET_OBJECTS:dgfparser_
_DUNE_TARGET_OBJECTS:dgfparserblocks_
${ALULIBS} ${UGLIB}
ADD_LIBS ${DUNE_LIBS})
add_dune_ug_flags(dunegrid OBJECT)
add_dune_alugrid_flags(dunegrid OBJECT)
add_dune_ug_flags(dunegrid ${_OBJECT_FLAG})
add_dune_alugrid_flags(dunegrid ${_OBJECT_FLAG})
foreach(_dim ${ALBERTA_WORLD_DIMS})
dune_add_library(dunealbertagrid_${_dim}d
......@@ -20,8 +27,8 @@ foreach(_dim ${ALBERTA_WORLD_DIMS})
_DUNE_TARGET_OBJECTS:dgfparser_
_DUNE_TARGET_OBJECTS:dgfparserblocks_
ADD_LIBS ${DUNE_LIBS})
add_dune_alberta_flags(dunealbertagrid_${_dim}d OBJECT GRIDDIM ${_dim})
list(APPEND DUNE_ALBERTA_LIBS dunealbertagrid_${dim}d)
add_dune_alberta_flags(dunealbertagrid_${_dim}d ${_OBJECT_FLAG} GRIDDIM ${_dim})
list(APPEND DUNE_ALBERTA_LIBS dunealbertagrid_${_dim}d)
endforeach(_dim "${ALBERTA_DIMS}")
install(FILES dunegridam2cmake.lib
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment