Hello,

Do find_package( Qt4 COMPONENTS ... ) from each subdir and use only
the components you need for each library.

Do not INCLUDE( ${QT_USE_FILE} ) in any case, just do an include_directories.

When linking, do not use the contain-all QT_LIBRARIES variable but the
individual library variables.

Assuming lib1 uses QtCore and QtNetwork:

find_package( Qt4 COMPONENTS QtCore QtNetwork REQUIRED )
include_directories( ${QT_QTCORE_INCLUDE_DIR} ${QT_QTNETWORK_INCLUDE_DIR} )
add_library( lib1 SHARED lib1_source1.cpp lib1_source2.cpp ... )
target_link_libraries( lib1 ${QT_QTCORE_LIBRARIES} ${QT_QTNETWORK_LIBRARIES} )

You'd do similar for lib2 and lib3 and the main CMakeLists.txt would
only contain something like:

project( blah )

add_directory( lib1 )
add_directory( lib2 )
add_directory( lib3 )

i. e. no find_package( Qt4 ...) in the main CMakeLists.txt [*]

[*] Actually you can do the find_package( Qt4 COMPONENTES
yourcomponents ) in the main CMakeLists.txt but then you need to
specify all the components required by all the directories below that
one in the hierarchy, which is more difficult to track.


On Thu, Dec 31, 2009 at 2:45 PM, Hicham Mouline <hic...@mouline.org> wrote:
> Hello,
>
> My toplevel CMakeLists.txt looks like:
>
> ----------------------------------------------------------------------------
> --------
> PROJECT(...)
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
>
> # Openmp
> FIND_PACKAGE(OpenMP)
> IF(OPENMP_FOUND)
>  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
> ENDIF()
>
> # Boost
> FIND_PACKAGE(Boost)
> IF(Boost_FOUND)
>    INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
> ENDIF()
>
> # Qt
> FIND_PACKAGE(Qt4 4.6.0 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
> INCLUDE(${QT_USE_FILE})
>
> INCLUDE_DIRECTORIES(AFTER ${CMAKE_CURRENT_SOURCE_DIR})
>
> ADD_SUBDIRECTORY(common)
> ADD_SUBDIRECTORY(lib1)
> ADD_SUBDIRECTORY(lib2)
> ADD_SUBDIRECTORY(lib3)
> ADD_SUBDIRECTORY(main)
> ----------------------------------------------------------------------------
> --------
>
>
> Using QT_USE_FILE includes Qt headers for all of common, lib1, lib2, lib3.
> How can I include and link Qt only for lib3?
>
> Lib3's CMakeLists.txt looks like:
>
> ADD_LIBRARY(lib3 STATIC #cpps hpps ipps)
>
> ADD_DEPENDENCIES(lib3 common)
>
> TARGET_LINK_LIBRARIES(lib3 ${QT_LIBRARIES})
>
> Rds,
>
> _______________________________________________
> 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
>



-- 
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
_______________________________________________
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

Reply via email to