libcheck / check

A unit testing framework for C
GNU Lesser General Public License v2.1
1.06k stars 208 forks source link

cmake: `make check` in project that uses tests has conflict with library name #76

Open 9fcc opened 7 years ago

9fcc commented 7 years ago

Default solution for make check in cmake is:

add_custom_target(check
COMMAND
    ${CMAKE_CTEST_COMMAND}
DEPENDS
    build-tests
)

But using compiled from source library produces errors:

CMake Error at *:* (target_link_libraries):
  Target "check" of type UTILITY may not be linked into another target.  One
  may link only to STATIC or SHARED libraries, or to executables with the
  ENABLE_EXPORTS property set.

So had to rename check target to tests-check.

Check was configured by cmake using pkg-config:

pkg_check_modules(CHECK REQUIRED check)

include_directories(
    ${CHECK_INCLUDE_DIRS}
)

link_directories(
    ${CHECK_LIBRARY_DIRS}
)

Default check library name in Ubuntu distribution is check_pic, so there was no problem before.

By the way "check" is too common word and associated to make check command so I've spent some time searching for that library in the past. It used only in C, so may be it would be better to rename library to "ccheck"? Or something like that.

brarcher commented 7 years ago

It used only in C, so may be it would be better to rename library to "ccheck"? Or something like that.

I hear you. Sorry that it is tricky to find information on it. The library's first release was in 2001 (on Sourceforge). I think that changing the name of the project now may only add further confusion.

Although Check does provide both autoconf and CMake build systems, Check officially supports autoconf for Linux/OSX/BSD/Solaris/Hurd and officially support CMake for Windows. I am not enough of a CMake expert to say definitively that it is fool-proof on anything but Windows. If my understanding is correct, the issue is a naming conflict between "check" the library and "check" the testing target in CMake, right? Is there a way to prevent the issue normally by modifying how Check using CMake?

I never really knew why Ubuntu renamed the Check library to check_pic. I wonder if it was in part to avoid the naming conflicts, or if that was accidental.

9fcc commented 7 years ago

The only solution is to change library name (maybe not the whole project but at least so-name). It is very rare case because cmake doesn't have default check target. But some people may added it like me through it was used often in past. Renaming the project could make problems but only for some time. This even library won't get popular even through google tests are easy to find and this library is hard to find example for.

9fcc commented 7 years ago

By the way I know CMake well but I don't know autoconf so I'll try to get cmake files to usable state. For now check's cmake files work on linux but do minimal things. First I tried to make deb package using CMake but didn't found pkg-config info in resulting package.

Corristo commented 5 years ago

There is another solution: Instead of renaming the library itself it suffices to rename the target (e.g. to libcheck) and instead set the target property OUTPUT_NAME to check in order for the filename of the generated library to stay the same.