Hi, The documentation says
> A package-specific list of components may be listed after the REQUIRED > option or after the COMPONENTS option if no REQUIRED option is given. http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:find_package But it doesn't say why you would want to do that. At first I thought it was to specify that only the components specified would be used to fill cmake variables. However, find_package(Qt COMPONENTS QtCore) also results in ${QT_QTGUI_LIBRARY} being defined for example. So then I thought maybe the semantic is that if one of the components can not be found, the find_package fails. So I tried find_package(Qt REQUIRED QtCore QtDoesNotExist) which works without error. What am I missing? The reason I ask is that I finally figured out why the tests in my library needed to be linked to QtGui, even though it only uses QtCore. The reason is that find_package(Qt) causes QT_GUI_LIB to be defined. Which in turn causes QTEST_MAIN to be defined to expand to use QApplication instead of QCoreApplication as it is if QT_GUI_LIB is not defined. http://qt.gitorious.org/qt/qt/blobs/4.7/src/testlib/qtest.h find_package(Qt REQUIRED QtCore QtScript) does not cause QT_GUI_LIB to be defined. However, some of my targets do need QtGui, so I should specify it, right? So if I do specify it I'll end up having QT_GUI_LIB defined when building my unit tests. I could remove_definitions(-DQT_GUI_LIB), but apart from being a BadHack(tm), it causes my unit tests which *do* require QtGui to fail at runtime because they create QWidgets and by undeffing QT_GUI_LIB I build them to use QCoreApplication instead of QApplication (Not allowed in Qt), so the tests fail at runtime. http://gitorious.org/grantlee/grantlee/blobs/0.1/tests/CMakeLists.txt Is there a solution to all this? What is the point of COMPONENTS if it has no effect on what I can include or link to? Is it possible to link some of my tests to QtGui but not all of them and still have them all pass? Do I need to just link my core tests to QtGui and use QApplication and quit my complaining? The only way I can see to satisfy all requirements is attached. Is that acceptable or is there a better way? All the best, Steve.
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aef989e..8709213 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,6 +17,8 @@ configure_file(grantlee_paths.h.cmake ${PROJECT_BINARY_DIR}/grantlee_paths.h) set (_rcc_file "scriptedtags.qrc") qt4_add_resources(_scripted_rcc_src ${_rcc_file} OPTIONS -root "/plugins/grantlee/${Grantlee_MAJOR_MINOR_VERSION_STRING}" ) +remove_definitions(-DQT_GUI_LIB) + macro(GRANTLEE_CORE_UNIT_TESTS) foreach(_testname ${ARGN}) set(_testSrcs ${_testname}.cpp) @@ -24,13 +26,14 @@ macro(GRANTLEE_CORE_UNIT_TESTS) qt4_generate_moc(${_testname}.cpp ${moc_output_file}) add_executable(${_testname}_exec ${_testSrcs} ${moc_output_file} ${_scripted_rcc_src} ${CMAKE_SOURCE_DIR}/corelib/lexer.cpp) add_test(${_testname} ${_testname}_exec ) - target_link_libraries(${_testname}_exec ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY} ${Grantlee_CORE_LIBRARIES} ) + target_link_libraries(${_testname}_exec ${QT_QTTEST_LIBRARY} ${Grantlee_CORE_LIBRARIES} ) endforeach(_testname) endmacro(GRANTLEE_CORE_UNIT_TESTS) macro(GRANTLEE_GUI_UNIT_TESTS) foreach(_testname ${ARGN}) set(_testSrcs ${_testname}.cpp) + set_source_files_properties(${_testSrcs} PROPERTIES COMPILE_FLAGS "-DQT_GUI_LIB" ) set(moc_output_file "${CMAKE_CURRENT_BINARY_DIR}/${_testname}.moc") qt4_generate_moc(${_testname}.cpp ${moc_output_file}) add_executable(${_testname}_exec ${_testSrcs} ${moc_output_file} )
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake