Salome HOME
30b9ca9a4b3d33a7354de736e23e4251b30add23
[modules/med.git] / adm_local_without_kernel / cmake_files / FindCppUnit.cmake
1 # - Find CppUnit
2 # Sets the following variables:
3 #   CPPUNIT_INCLUDE_DIRS - path to the CppUnit include directory
4 #   CPPUNIT_LIBRARIES    - path to the CppUnit libraries to be linked against
5 #   CPPUNIT_DEFINITIONS  - specific CppUnit definitions to be added
6 #
7 #  The header cppunit/extensions/HelperMacros.h is looked for.
8 #  The following libraries are searched  
9 #        cppunit_dll, or cppunitd_dll (Windows) 
10 #        cppunit (Linux)
11 #
12
13 #########################################################################
14 # Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
15 #
16 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
17 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
18 #
19 # This library is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU Lesser General Public
21 # License as published by the Free Software Foundation; either
22 # version 2.1 of the License, or (at your option) any later version.
23 #
24 # This library is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27 # Lesser General Public License for more details.
28 #
29 # You should have received a copy of the GNU Lesser General Public
30 # License along with this library; if not, write to the Free Software
31 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
32 #
33 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
34 #
35
36 IF(NOT CppUnit_FIND_QUIETLY)
37     MESSAGE(STATUS "Looking for CppUnit ...")
38 ENDIF()
39
40 # Headers
41 SET(CPPUNIT_ROOT_DIR $ENV{CPPUNIT_ROOT_DIR} CACHE PATH "Path to the CPPUNIT.")
42 IF(CPPUNIT_ROOT_DIR)
43   LIST(APPEND CMAKE_INCLUDE_PATH "${CPPUNIT_ROOT_DIR}/include")
44   LIST(APPEND CMAKE_PROGRAM_PATH "${CPPUNIT_ROOT_DIR}/bin")
45 ENDIF(CPPUNIT_ROOT_DIR)
46
47 SET(CPPUNIT_INCLUDE_TO_FIND cppunit/extensions/HelperMacros.h)
48 FIND_PATH(CPPUNIT_INCLUDE_DIRS ${CPPUNIT_INCLUDE_TO_FIND})
49
50 # Libraries
51 IF(WIN32)
52   IF(CMAKE_BUILD_TYPE STREQUAL Debug)
53     FIND_LIBRARY(CPPUNIT_LIBRARIES cppunitd_dll)
54   ELSE(CMAKE_BUILD_TYPE STREQUAL Debug)
55     FIND_LIBRARY(CPPUNIT_LIBRARIES cppunit_dll)
56   ENDIF(CMAKE_BUILD_TYPE STREQUAL Debug)
57 ELSE(WIN32)
58   FIND_PROGRAM(CPPUNIT_CONFIG_BIN cppunit-config)
59   IF(NOT CPPUNIT_CONFIG_BIN)
60     MESSAGE(FATAL_ERROR "Error in CPPUNIT detection ! cppunit-config executable not found !")
61   ENDIF(NOT CPPUNIT_CONFIG_BIN)
62   EXECUTE_PROCESS(COMMAND ${CPPUNIT_CONFIG_BIN} --libs OUTPUT_VARIABLE CPPUNIT_LDFLAGS)
63   STRING(STRIP ${CPPUNIT_LDFLAGS} CPPUNIT_LDFLAGS)
64   STRING(REPLACE " " ";" LDFLAGS_LIST ${CPPUNIT_LDFLAGS})
65   FOREACH(LDFLAG ${LDFLAGS_LIST})
66     STRING(REGEX MATCH "^-L.*" LIBDIR "${LDFLAG}")
67     STRING(REGEX MATCH "^-l.*" LIB "${LDFLAG}")
68     IF(LIBDIR)
69       STRING(REGEX REPLACE "^-L" "" LIBDIR ${LIBDIR})
70       LIST(APPEND CMAKE_LIBRARY_PATH ${LIBDIR})
71     ELSEIF(LIB)
72       STRING(REGEX REPLACE "^-l" "" LIB ${LIB})
73       LIST(APPEND LIBS ${LIB})
74     ELSE()
75       MESSAGE(FATAL_ERROR "Unrecognized token \"${LDFLAG}\" in the output of cppunit-config --libs")
76     ENDIF()
77   ENDFOREACH(LDFLAG ${LDFLAGS_LIST})
78   FOREACH(LIB ${LIBS})
79     FIND_LIBRARY(CPPUNIT_SUBLIB_${LIB} ${LIB})
80     IF(NOT CPPUNIT_SUBLIB_${LIB})
81       MESSAGE(FATAL_ERROR "Error in CPPUNIT detection! Fail to locate the needed library ${LIB}!")
82     ENDIF(NOT CPPUNIT_SUBLIB_${LIB})
83     LIST(APPEND CPPUNIT_LIBRARIES ${CPPUNIT_SUBLIB_${LIB}})
84   ENDFOREACH(LIB ${LIBS})
85 #  MESSAGE("**** ${CPPUNIT_LIBRARIES}")
86 ENDIF(WIN32)
87
88 # Global variables
89 SET(CPPUNIT_DEFINITIONS)
90 IF(WIN32)
91   SET(CPPUNIT_DEFINITIONS -DCPPUNIT_DLL)
92 ENDIF(WIN32)
93
94 INCLUDE(FindPackageHandleStandardArgs)
95 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CppUnit REQUIRED_VARS CPPUNIT_INCLUDE_DIRS CPPUNIT_LIBRARIES)
96
97