diff --git a/cmake/Templates/opm-project-config.cmake.in b/cmake/Templates/opm-project-config.cmake.in index ccc982536..331910810 100644 --- a/cmake/Templates/opm-project-config.cmake.in +++ b/cmake/Templates/opm-project-config.cmake.in @@ -41,8 +41,10 @@ if(NOT @opm-project_NAME@_FOUND) if (NOT "@opm-project_TARGET@" STREQUAL "") # add the library as a target, so that other things in the project including # this file may depend on it and get rebuild if this library changes. - add_library (@opm-project_TARGET@ UNKNOWN IMPORTED) - set_property (TARGET @opm-project_TARGET@ PROPERTY IMPORTED_LOCATION "${@opm-project_NAME@_LIBRARY}") + if(NOT TARGET @opm-project_TARGET@) + add_library (@opm-project_TARGET@ UNKNOWN IMPORTED) + set_property (TARGET @opm-project_TARGET@ PROPERTY IMPORTED_LOCATION "${@opm-project_NAME@_LIBRARY}") + endif() endif (NOT "@opm-project_TARGET@" STREQUAL "") # ensure that we build with support for C++11 to preserve ABI