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)