Cannot build sub-directory library if top-level CMakeLists.txt call install(EXPORT ...)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Cannot build sub-directory library if top-level CMakeLists.txt call install(EXPORT ...)

Ziji Hu
Hi all,

I'm a newbie of CMake. I'm trying to add a feature as a sub-library to
an existing application. But I met troubles of install(EXPORT ...)

My project source code structure shows as below:
app (the existing application)
     |-- top-level CMakeLists.txt
     |
     |-- sublib (my new feature)
     |        |-- src
     |        |-- include
     |        |-- CMakeLists.txt
     |
     |-- other existing src ...

I build sublib in the CMakeLists.txt inside my own feature as:
     ...
     add_library(sublib ${LIB_SRC})
     ...

I modify the top-level CMakeLists.txt in the existing application to
link sublib:
     ...
     add_subdirectory(subdirectory of sublib)
     ...
     target_link_directories(app sublib)
     ...

I thought it is enough. But CMake threw out an error:
CMake Error: install(EXPORT "appTargets" ...) includes target "app"
which requires target "sublib" that is not in the export set.

I guess it is because "app" is exported by install(EXPORT .. ) in the
top-level CMakeLists.txt. Thus I also install and export sublib.
I add the install and export into sublib CMakeLists.txt:
    ...
    install(TARGETS sublib
        EXPORT  sublibTargets
        ARCHIVE DESTINATION ${BIN_INSTALL_DIR}
        LIBRARY DESTINATION ${LIB_INSTALL_DIR}
        RUNTIME DESTINATION ${LIB_INSTALL_DIR}
        )

    install(EXPORT sublibTargets
        FILE sublib-config.cmake
        DESTINATION ${LIB_INSTALL_DIR}/cmake/sublib
        )
    ...
I also add find_package() in top-level CMakeLists.txt:
    ...
    find_package(sublib REQUIRED)
    target_link_directories(app sublib)
    ...

However, it becomes worse. sublib is not built at all and
sublib-config.cmake is not found.

Could you please tell me how fix the EXPORT issue?

Thank you.

Best regards,
David Hu
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake