[CMake] Best practice for static libraries and include files

Matthew Woehlke matthew.woehlke at kitware.com
Fri Mar 8 16:59:27 EST 2013


On 2013-03-08 15:55, Alessandro Saccoia wrote:
>> (I've seen legitimate uses of defining variables for libraries'
>> interface properties, e.g. include directories, but all of this is
>> about to become properly supported :-), and anyway isn't something
>> I would recommend trying to emulate in a young project.)
>
> Where can I find more about it?

Hmm... I'm not sure how much the documentation has been updated for the 
new stuff yet. Stephen Kelly (who did much of the work) would be able to 
answer better.

You can dredge up at least some information searching the recent 
cmake-devel acrhives for 'target_link_libraries', but I couldn't tell 
you offhand how much of that will reflect the actual current state of 
things.

> OT: Since we're already here, do you know why CTest seems to be
> broken, as I need to create a new custom target that depends on the
> tests in order to run them, i.e. "make check" doesnt do anything and
> "ctest -N" always shows "Total Tests: 0"?

CMake has never created a 'check' target by default. This (as you 
probably know) is a GNU-ism/autotools-ism that CMake has never felt 
necessary to copy; for CMake projects, just think 'ctest' instead of 
'make check'.

That said, if you really want a 'check' target, you can do something like:

add_custom_target(check
   COMMAND ${CMAKE_CTEST_COMMAND}
   WORKING_DIRECTORY ${<root-project-name>_BINARY_DIR}
)

(Personally, I find having a target can be useful, because you can run a 
target from your IDE as a build target, which may be more convenient or 
to your preference. Of course, my 'check' target is just a root target 
for several check_<stuff> sub-targets, only one of which runs CTest :-).)

As for ctest reporting no tests, per Alexander's reply, I would first 
make sure you have called enable_testing().

> Also, I want my tests to be verbose and both cout and cerr seem to be
> redirected to /dev/null so I can read nothing

This is the default behavior (although the output does not go to 
/dev/null :-); log files are written to ctest's output directory). 
Please refer to ctest's documentation for how to run tests verbosely 
(hint: '-V').

-- 
Matthew



More information about the CMake mailing list