]> SALOME platform Git repositories - tools/configuration.git/blobdiff - cmake/FindCppUnit.cmake
Salome HOME
Merge branch 'po/fix-hdf5'
[tools/configuration.git] / cmake / FindCppUnit.cmake
index d5796b936df774d0621f37220ae85fde28c44e6d..cea819273ad8c847186b70e6a77e31921145eccd 100644 (file)
 #
 
 #########################################################################
-# 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
+# Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -55,11 +52,27 @@ IF(WIN32)
     FIND_LIBRARY(CPPUNIT_LIBRARIES cppunit_dll)
   ENDIF(CMAKE_BUILD_TYPE STREQUAL Debug)
 ELSE(WIN32)
-  FIND_PROGRAM(CPPUNIT_CONFIG_BIN cppunit-config)
-  IF(NOT CPPUNIT_CONFIG_BIN)
-    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)
+
+  # RNV: Some new Linux distributions don't contain cppunit-config executable,
+  #      so use pkg-config to detect cppunit first.
+  FIND_PACKAGE(PkgConfig QUIET)
+
+  IF(PKG_CONFIG_FOUND)
+    PKG_SEARCH_MODULE(CPPUNIT_TOOL cppunit)  
+    IF(CPPUNIT_TOOL_FOUND)
+      SET(CPPUNIT_LDFLAGS ${CPPUNIT_TOOL_LIBRARIES})
+    ENDIF()
+  ENDIF()
+  
+  IF(NOT CPPUNIT_TOOL_FOUND)
+    MESSAGE("CPPUNIT is not found via pgk-config, try to find cppunit-config executable ...")
+    FIND_PROGRAM(CPPUNIT_CONFIG_BIN cppunit-config)
+    IF(NOT CPPUNIT_CONFIG_BIN)
+      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)
+  ENDIF()
+  
   STRING(STRIP ${CPPUNIT_LDFLAGS} CPPUNIT_LDFLAGS)
   STRING(REPLACE " " ";" LDFLAGS_LIST ${CPPUNIT_LDFLAGS})
   FOREACH(LDFLAG ${LDFLAGS_LIST})
@@ -72,7 +85,11 @@ ELSE(WIN32)
       STRING(REGEX REPLACE "^-l" "" LIB ${LIB})
       LIST(APPEND LIBS ${LIB})
     ELSE()
-      MESSAGE(FATAL_ERROR "Unrecognized token \"${LDFLAG}\" in the output of cppunit-config --libs")
+      IF(CPPUNIT_CONFIG_BIN)
+        MESSAGE(FATAL_ERROR "Unrecognized token \"${LDFLAG}\" in the output of cppunit-config --libs")
+      ELSE()
+        LIST(APPEND LIBS ${LDFLAG})
+      ENDIF()
     ENDIF()
   ENDFOREACH(LDFLAG ${LDFLAGS_LIST})
   FOREACH(LIB ${LIBS})
@@ -93,5 +110,3 @@ ENDIF(WIN32)
 
 INCLUDE(FindPackageHandleStandardArgs)
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CppUnit REQUIRED_VARS CPPUNIT_INCLUDE_DIRS CPPUNIT_LIBRARIES)
-
-