Skip to content

Commit

Permalink
cmake: fix check detection
Browse files Browse the repository at this point in the history
Building on Ubuntu 18.04 fails with missing symbols message
due to lack of proper libraries being automatically linked
against tests.

This patch uses pkgconfig to automatically detect system-installed
libcheck, and also gets rid of the unnecessery symbol requirement in
favor of a simple version check.
  • Loading branch information
pbalcer committed Feb 8, 2019
1 parent b88942a commit 6ba9ba0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
23 changes: 10 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,13 @@ add_subdirectory(${CCOMMON_SOURCE_DIR} ${PROJECT_BINARY_DIR}/ccommon)
include(FindPackageHandleStandardArgs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")

find_package(Check)
if(NOT CHECK_FOUND)
message(WARNING "Check is required to build and run tests")
endif(NOT CHECK_FOUND)
if(CHECK_FOUND)
check_symbol_exists(ck_assert_int_eq check.h CHECK_WORKING)
if(NOT CHECK_WORKING)
message(WARNING "Check version too old to build tests")
endif(NOT CHECK_WORKING)
endif(CHECK_FOUND)
find_package(PkgConfig QUIET)

if(PKG_CONFIG_FOUND)
pkg_check_modules(CHECK REQUIRED check>=0.10)
else()
find_package(Check REQUIRED 0.10)
endif()

find_package(Threads)

Expand All @@ -155,10 +152,10 @@ include_directories(${include_directories}
add_subdirectory(src)

# tests: always build last
if(CHECK_WORKING)
include_directories(${include_directories} "${CHECK_INCLUDES}")
if(CHECK_FOUND)
include_directories(${include_directories} ${CHECK_INCLUDES})
add_subdirectory(test)
endif(CHECK_WORKING)
endif(CHECK_FOUND)

# print a summary
message(STATUS "PLATFORM: " ${OS_PLATFORM})
Expand Down
25 changes: 11 additions & 14 deletions deps/ccommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,13 @@ endif(COVERAGE)
include(FindPackageHandleStandardArgs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")

find_package(Check)
if(NOT CHECK_FOUND)
message(WARNING "Check is required to build and run tests")
endif(NOT CHECK_FOUND)
if(CHECK_FOUND)
check_symbol_exists(ck_assert_int_eq check.h CHECK_WORKING)
if(NOT CHECK_WORKING)
message(WARNING "Check version too old to build tests")
endif(NOT CHECK_WORKING)
endif(CHECK_FOUND)
find_package(PkgConfig QUIET)

if(PKG_CONFIG_FOUND)
pkg_check_modules(CHECK REQUIRED check>=0.10)
else()
find_package(Check REQUIRED 0.10)
endif()

find_package(Threads)

Expand All @@ -166,10 +163,10 @@ include_directories(

add_subdirectory(src)

if(CHECK_WORKING)
include_directories(${include_directories} "${CHECK_INCLUDES}")
if(CHECK_FOUND)
include_directories(${include_directories} ${CHECK_INCLUDES})
add_subdirectory(test)
endif(CHECK_WORKING)
endif(CHECK_FOUND)


if(HAVE_RUST)
Expand All @@ -193,4 +190,4 @@ message(STATUS "HAVE_SIGNAME: " ${HAVE_SIGNAME})

message(STATUS "HAVE_BACKTRACE: " ${HAVE_BACKTRACE})

message(STATUS "CHECK_WORKING: " ${CHECK_WORKING})
message(STATUS "CHECK_FOUND: " ${CHECK_FOUND})

0 comments on commit 6ba9ba0

Please sign in to comment.