Cannot link against brew-installde cppunit in OSX travis image

92 views Asked by At

I have a cmake-based C++ project on github that builds with Travis CI. The .travis.yml file has the following for building on OSX with clang:

language: cpp

jobs:
  include:
    - os: osx
      compiler: gcc
      osx_image: xcode11.2
      env:
        - GCC_VER="9"
        - MATRIX_EVAL="CC=gcc-${GCC_VER} && CXX=g++-${GCC_VER}"
      addons:
        homebrew:
          packages:
          - cppunit
          - mruby

... (other OS) ...

before_script:
  - eval "${MATRIX_EVAL}"

script:
  - cmake -D ENABLE_TESTS:BOOL=TRUE .
  - cmake --build . -- -j2
  - ctest -j2

CppUnit is installed by brew.

The cmake command runs fine and finds CppUnit in /usr/local (i.e. CPPUNIT_INDLUE_DIR is correctly set to /usr/local/include and CPPUNIT_LIBRARIES is correctly set to /usr/local/lib/libcppunit.dylib. However when building the tests, I get link errors about undefined symbols related to cppunit, indicating that it is not correctly linking against cppunit.

The same project builds fine on my MacBook (also with a brew-installed cppunit), and it correctly builds on Linux with both gcc-9 and with clang, with cppunit installed via apt.

I thought I needed to set DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/lib somewhere, but when I do that I get new errors:

$ cmake -D ENABLE_TESTS:BOOL=TRUE .

dyld: Symbol not found: __cg_jpeg_resync_to_restart

  Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO

  Expected in: /usr/local/lib/libJPEG.dylib

 in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO

/Users/travis/.travis/functions: line 109:  3565 Abort trap: 6           cmake -D ENABLE_TESTS:BOOL=TRUE .

The command "cmake -D ENABLE_TESTS:BOOL=TRUE ." exited with 134.

Here is the CMakeLists.txt file at the root of the source:

cmake_minimum_required (VERSION 3.1)
project (mrbind17 CXX)

set (CMAKE_CXX_STANDARD 17)

set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
     "${CMAKE_CURRENT_SOURCE_DIR}/cmake")


add_definitions(-g)
option(ENABLE_TESTS "Build tests. May require CppUnit_ROOT" OFF)

include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)

find_package (Mruby REQUIRED)
include_directories (${Mruby_INCLUDE_DIR})

find_package (CppUnit)
if (CPPUNIT_FOUND)
    message(STATUS "CppUnit found, unit tests will be compiled")
    message(STATUS "CPPUNIT_INCLUDE_DIR : ${CPPUNIT_INCLUDE_DIR}")
    message(STATUS "CPPUNIT_LIBRARIES : ${CPPUNIT_LIBRARIES}")
    include_directories(${CPPUNIT_INCLUDE_DIR})
    enable_testing()
    if(${ENABLE_TESTS})
        add_subdirectory (test)
    endif(${ENABLE_TESTS})
else (CPPUNIT_FOUND)
    message(STATUS "CppUnit not found, unit tests will not be compiled")
endif (CPPUNIT_FOUND)

and the CMakeLists.txt in the test directory:

add_executable(interpreter_test main.cpp interpreter_test.cpp)
target_link_libraries(interpreter_test ${Mruby_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_test(NAME interpreter_test COMMAND ./interpreter_test interpreter_test.xml)

add_executable(function_test main.cpp function_test.cpp)
target_link_libraries(function_test ${Mruby_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_test(NAME function_test COMMAND ./function_test function_test.xml)

add_executable(module_test main.cpp module_test.cpp)
target_link_libraries(module_test ${Mruby_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_test(NAME module_test COMMAND ./module_test module_test.xml)

What can I do to have cmake link correctly against cppunit?

0

There are 0 answers