Salome HOME
Copyright update: 2016
[modules/kernel.git] / salome_adm / cmake_files / FindCppUnit.cmake
index b34e80a3598e088b8be02634830ba0c4ab2bfef2..d5796b936df774d0621f37220ae85fde28c44e6d 100644 (file)
@@ -11,7 +11,7 @@
 #
 
 #########################################################################
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -19,7 +19,7 @@
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -60,20 +60,28 @@ ELSE(WIN32)
     MESSAGE(FATAL_ERROR "Error in CPPUNIT detection ! cppunit-config executable not found !")
   ENDIF(NOT CPPUNIT_CONFIG_BIN)
   EXECUTE_PROCESS(COMMAND ${CPPUNIT_CONFIG_BIN} --libs OUTPUT_VARIABLE CPPUNIT_LDFLAGS)
-  STRING( REGEX MATCHALL "-L([^\" ]+|\"[^\"]+\")" CPPUNIT_TMP4 "${CPPUNIT_LDFLAGS}" )
-  IF(CPPUNIT_TMP4)
-    STRING( REGEX REPLACE "^-L" "" CPPUNIT_LIBRARY_DIRS ${CPPUNIT_TMP4})
-    LIST(APPEND CMAKE_LIBRARY_PATH ${CPPUNIT_LIBRARY_DIRS})
-  ENDIF(CPPUNIT_TMP4)
-  STRING( REGEX MATCHALL "-l([^\", \n]+)" CPPUNIT_TMP5 "${CPPUNIT_LDFLAGS}" )
-  FOREACH(LIB ${CPPUNIT_TMP5})
-    STRING(REGEX REPLACE "^-l" "" LIB2 ${LIB})
-    FIND_LIBRARY(CPPUNIT_SUBLIB_${LIB2} ${LIB2})
-    IF(NOT CPPUNIT_SUBLIB_${LIB2})
-      MESSAGE(FATAL_ERROR "Error in CPPUNIT detection ! Fail to locate the needed library ${LIB2} !")
-    ENDIF(NOT CPPUNIT_SUBLIB_${LIB2})
-    LIST(APPEND CPPUNIT_LIBRARIES ${CPPUNIT_SUBLIB_${LIB2}})
-  ENDFOREACH(LIB ${CPPUNIT_TMP5})
+  STRING(STRIP ${CPPUNIT_LDFLAGS} CPPUNIT_LDFLAGS)
+  STRING(REPLACE " " ";" LDFLAGS_LIST ${CPPUNIT_LDFLAGS})
+  FOREACH(LDFLAG ${LDFLAGS_LIST})
+    STRING(REGEX MATCH "^-L.*" LIBDIR "${LDFLAG}")
+    STRING(REGEX MATCH "^-l.*" LIB "${LDFLAG}")
+    IF(LIBDIR)
+      STRING(REGEX REPLACE "^-L" "" LIBDIR ${LIBDIR})
+      LIST(APPEND CMAKE_LIBRARY_PATH ${LIBDIR})
+    ELSEIF(LIB)
+      STRING(REGEX REPLACE "^-l" "" LIB ${LIB})
+      LIST(APPEND LIBS ${LIB})
+    ELSE()
+      MESSAGE(FATAL_ERROR "Unrecognized token \"${LDFLAG}\" in the output of cppunit-config --libs")
+    ENDIF()
+  ENDFOREACH(LDFLAG ${LDFLAGS_LIST})
+  FOREACH(LIB ${LIBS})
+    FIND_LIBRARY(CPPUNIT_SUBLIB_${LIB} ${LIB})
+    IF(NOT CPPUNIT_SUBLIB_${LIB})
+      MESSAGE(FATAL_ERROR "Error in CPPUNIT detection! Fail to locate the needed library ${LIB}!")
+    ENDIF(NOT CPPUNIT_SUBLIB_${LIB})
+    LIST(APPEND CPPUNIT_LIBRARIES ${CPPUNIT_SUBLIB_${LIB}})
+  ENDFOREACH(LIB ${LIBS})
 #  MESSAGE("**** ${CPPUNIT_LIBRARIES}")
 ENDIF(WIN32)