Bug 176468 - RPATH isn't set for tests added with KDE4_ADD_UNIT_TEST
Summary: RPATH isn't set for tests added with KDE4_ADD_UNIT_TEST
Status: RESOLVED FIXED
Alias: None
Product: buildsystem
Classification: Developer tools
Component: KDE4 (cmake) (show other bugs)
Version: unspecified
Platform: Mandriva RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Alexander Neundorf
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-29 17:44 UTC by Daniel Calviño Sánchez
Modified: 2008-12-15 00:34 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Calviño Sánchez 2008-11-29 17:44:27 UTC
Version:            (using KDE 4.1.2)
OS:                Linux
Installed from:    Mandriva RPMs

Under GNU/Linux, when executing a unit test for a dynamic library not installed yet, the test executable fails as it can't found the dynamic library. RPATH wasn't properly set.

The test executable was created using kde4_add_unit_test macro. I have tried using no parameters, NOGUI parameter, TESTNAME parameter and both TESTNAME and NOGUI parameters:
kde4_add_unit_test(StepTest ${StepTest_SRCS})
kde4_add_unit_test(StepTest NOGUI ${StepTest_SRCS})
kde4_add_unit_test(StepTest TESTNAME ktutorial-StepTest ${StepTest_SRCS})
kde4_add_unit_test(StepTest TESTNAME ktutorial-StepTest NOGUI ${StepTest_SRCS})

All of them also with:
set(StepTest_SRCS StepTest.cpp)
target_link_libraries(StepTest ktutorial ${QT_QTTEST_LIBRARY})

I'm not a CMAKE expert and I may be wrong, but I think the problem is this:
KDE4_ADD_UNIT_TEST creates the executable calling kde4_add_executable( ${_test_NAME} TEST ${_srcList} ). KDE4_ADD_EXECUTABLE sets _type variable to GUI with set(_type "GUI") and, if NOGUI parameter is used, it changes it with set(_type "NOGUI"). That is, _type is always set to either "GUI" or "NOGUI".

Then, if RUN_UNINSTALLED or TEST parameters were used, _type value is changed with set(_type "RUN_UNINSTALLED ${_type}"). So, as KDE4_ADD_UNIT_TEST used TEST parameter when it called KDE4_ADD_EXECUTABLE, _type is set either to "RUN_UNINSTALLED GUI" or  "RUN_UNINSTALLED NOGUI". No further changes are applied to _type, and after some unrelated things, kde4_handle_rpath_for_executable(${_target_NAME} ${_type}) is called.

KDE4_HANDLE_RPATH_FOR_EXECUTABLE checks if we are in UNIX, and then if CMAKE_SKIP_RPATH isn't active. At this point is where RPATH properties are set depending on _type. The problem is that the conditions use STREQUAL. So as _type is "RUN_UNINSTALLED GUI"/"RUN_UNINSTALLED NOGUI" for unit tests, no condition is met.

In fact, I have checked that using (${_type} MATCHES "RUN_UNINSTALLED") instead of (${_type} STREQUAL "RUN_UNINSTALLED") (that is, checking for a regular expression instead of the exact string) mets the condition and RPATH is set as it should for unit tests. I don't know, however, if the behaviour caused by that change is the right one in other circumstances.

If I haven't failed in my reasoning, this also happens in current trunk (885852, http://websvn.kde.org/trunk/KDE/kdelibs/cmake/modules/KDE4Macros.cmake?revision=885852&view=markup)
Comment 1 Alexander Neundorf 2008-12-15 00:34:40 UTC
This should be fixed now in trunk, RPATH is now always set fully for all targets, revision 897003.
That's much easier now that we require cmake 2.6.

Alex