Linking imported library to ExternalProject

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

Linking imported library to ExternalProject

Laurent Chauvin-2
Hello,

I'm trying to create a superbuild for my project, which require nifticlib library. I am able to automatically download and compile it, as well as import created libraries, however, I'm not sure how can I link it with another external project?

Here is my CMake (the relevant part):

message(STATUS "Installing Nifti library.")

ExternalProject_Add(Nifticlib
  SOURCE_DIR "${PROJECT_BINARY_DIR}/deps/nifticlib"
  BINARY_DIR "${PROJECT_BINARY_DIR}/deps/nifticlib-build"
  INSTALL_DIR "${PROJECT_BINARY_DIR}/deps/nifticlib-install"
  GIT_REPOSITORY "${git_protocol}://gitlab.com/slckr/nifticlib.git"
  GIT_TAG "e26a94e947c210104223f9f49737392c742c1c5b"
  CMAKE_ARGS
  -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
  -DZLIB_INCLUDE_DIR:PATH=${ZLIB_INC_DIR}
  -DZLIB_LIBRARY_DEBUG:PATH=${ZLIB_LIB_DIR}/${ZLIB_LIB_NAME_DEBUG}
  -DZLIB_LIBRARY_RELEASE:PATH=${ZLIB_LIB_DIR}/${ZLIB_LIB_NAME_RELEASE}
  DEPENDS Zlib)

set(NIFTIIO_LIB_BASE_NAME "niftiio")
set(NIFTIIO_LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${NIFTIIO_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")

set(NIFTICDF_LIB_BASE_NAME "nifticdf")
set(NIFTICDF_LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${NIFTICDF_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")

set(ZNZ_LIB_BASE_NAME "znz")
set(ZNZ_LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${ZNZ_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")

ExternalProject_Get_Property(Nifticlib install_dir)
set(NIFTI_LIB_DIR ${install_dir}/lib)
set(NIFTI_INC_DIR ${install_dir}/include/nifti)
set(NIFTI_BIN_DIR ${install_dir}/bin)

add_library(niftiio STATIC IMPORTED)
set_target_properties(niftiio PROPERTIES IMPORTED_LOCATION "${NIFTI_LIB_DIR}/${NIFTIIO_LIB_NAME}")

add_library(nifticdf STATIC IMPORTED)
set_target_properties(nifticdf PROPERTIES IMPORTED_LOCATION "${NIFTI_LIB_DIR}/${NIFTICDF_LIB_NAME}")

add_library(znz STATIC IMPORTED)
set_target_properties(znz PROPERTIES IMPORTED_LOCATION "${NIFTI_LIB_DIR}/${ZNZ_LIB_NAME}")


## My project
ExternalProject_Add(MyProject
  SOURCE_DIR "${PROJECT_BINARY_DIR}/deps/myproject"
  BINARY_DIR "${PROJECT_BINARY_DIR}/deps/myproject-build"
  INSTALL_DIR "${PROJECT_BINARY_DIR}/deps/myproject-install"
  GIT_REPOSITORY "${git_protocol}://gitlab.com/slckr/myproject.git"
  CMAKE_ARGS
      -DNIFTI_INC_DIR:PATH=${NIFTI_INC_DIR}
-DNIFTI_LIB_DIR:PATH=${NIFTI_LIB_DIR}
  DEPENDS Nifticlib)



However, I imported my nifticlib as niftiio,nifticdf, and znz. How can I pass them to be linked with my ExternalProject MyProject?
Given that I pass the NIFTI_LIBRARY_DIR, do I just need to do a target_link_libraries(MyProject niftiio nifticdf znz) in my CMakeLists.txt of MyProject? Is it gonna find the proper library (as the name of the library is platform dependent)?

Thank you.
-Laurent



--

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:
http://public.kitware.com/mailman/listinfo/cmake