]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Improve CPPUNIT detection to avoid -ldl problem on link.
authorageay <ageay>
Mon, 8 Jul 2013 09:38:04 +0000 (09:38 +0000)
committerageay <ageay>
Mon, 8 Jul 2013 09:38:04 +0000 (09:38 +0000)
salome_adm/cmake_files/FindCppUnit.cmake

index 4460b9d0d42595c7cba918507c33cef55be7c568..b34e80a3598e088b8be02634830ba0c4ab2bfef2 100644 (file)
@@ -37,26 +37,51 @@ IF(NOT CppUnit_FIND_QUIETLY)
     MESSAGE(STATUS "Looking for CppUnit ...")
 ENDIF()
 
-# Headers  
+# Headers
+SET(CPPUNIT_ROOT_DIR $ENV{CPPUNIT_ROOT_DIR} CACHE PATH "Path to the CPPUNIT.")
+IF(CPPUNIT_ROOT_DIR)
+  LIST(APPEND CMAKE_INCLUDE_PATH "${CPPUNIT_ROOT_DIR}/include")
+  LIST(APPEND CMAKE_PROGRAM_PATH "${CPPUNIT_ROOT_DIR}/bin")
+ENDIF(CPPUNIT_ROOT_DIR)
+
 SET(CPPUNIT_INCLUDE_TO_FIND cppunit/extensions/HelperMacros.h)
 FIND_PATH(CPPUNIT_INCLUDE_DIRS ${CPPUNIT_INCLUDE_TO_FIND})
 
 # Libraries
-IF(WINDOWS)
+IF(WIN32)
   IF(CMAKE_BUILD_TYPE STREQUAL Debug)
     FIND_LIBRARY(CPPUNIT_LIBRARIES cppunitd_dll)
   ELSE(CMAKE_BUILD_TYPE STREQUAL Debug)
     FIND_LIBRARY(CPPUNIT_LIBRARIES cppunit_dll)
   ENDIF(CMAKE_BUILD_TYPE STREQUAL Debug)
-ELSE(WINDOWS)
-  FIND_LIBRARY(CPPUNIT_LIBRARIES cppunit)
-ENDIF(WINDOWS)
+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)
+  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})
+#  MESSAGE("**** ${CPPUNIT_LIBRARIES}")
+ENDIF(WIN32)
 
 # Global variables
 SET(CPPUNIT_DEFINITIONS)
-IF(WINDOWS)
+IF(WIN32)
   SET(CPPUNIT_DEFINITIONS -DCPPUNIT_DLL)
-ENDIF(WINDOWS)
+ENDIF(WIN32)
 
 INCLUDE(FindPackageHandleStandardArgs)
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CppUnit REQUIRED_VARS CPPUNIT_INCLUDE_DIRS CPPUNIT_LIBRARIES)