1

I am trying a very simple ExternalProject usage against ITK. This will allow my automated jenkins slave to retrieve ITK directly instead of using a system installed library (thus I leave it as an option to use ExternalProject or not).

So I wrote the following piece of code:

set(ITK_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/ITK")
set(ITK_INSTALL_PREFIX "${ITK_PREFIX}/install-$<CONFIG>")
ExternalProject_Add(ITK
URL http://sourceforge.net/projects/itk/files/itk/4.6/InsightToolkit-4.6.1.tar.xz
URL_MD5 d8dcab9193b55d4505afa94ab46de699
PREFIX ${ITK_PREFIX}
CMAKE_ARGS -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -DModule_ITKReview:BOOL=ON -DITK_USE_SYSTEM_GDCM:BOOL=ON -DCMAKE_INSTALL_PREFIX=${ITK_INSTALL_PREFIX} -DGDCM_DIR:PATH=${GDCM_INSTALL_PREFIX}
BUILD_COMMAND "${CMAKE_COMMAND}" --build . --target install --config $<CONFIG>
)
# include directory:
include_directories(${ITK_INSTALL_PREFIX}/include/ITK-4.6)
# link directory:
#link_directories(${ITK_INSTALL_PREFIX}/lib/) # $ sign is escaped
link_directories(${ITK_PREFIX}/install-/lib)

But then I fail to understand how I can possibly populate the following variable: ITK_LIBRARIES which I had been using throughout my codebase.

How should I write:

set(ITK_LIBRARIES
  itksys-4.6
  ITKCommon-4.6
  ITKIOImageBase-4.6
  ITKIOMeta-4.6
  ITKIOGDCM-4.6
  pthread
  ...? possibly others ? possibly different order ? ...
)

This feels like a hack, extremely hard to maintain, esp. considering that I need to link to static libraries (requirements for me).


Obviously the magical solution would be for me to run find_package(ITK) and be done. But since ExternalProject are done at build time and not configure time, I cannot make use of this (ref).


Because people feel it is duplicate, let me insist, on: "Yes I do understand that I cannot use find_package". My question is totally different, and is rather about the complex case of static linking.

Community
  • 1
  • 1
malat
  • 12,152
  • 13
  • 89
  • 158
  • Possible duplicate of [CMake ExternalProject\_Add() and FindPackage()](http://stackoverflow.com/questions/17446981/cmake-externalproject-add-and-findpackage) – Tsyvarev May 04 '17 at 12:59
  • Clarified why my question is specifically different. Wonder how people think this is a duplicate since I even explain and reference it... – malat May 04 '17 at 13:05
  • 1
    Referenced question explains how to **make** `ExternalProject_Add` **usable** with `find_package`. In other words, you are right that these two commands don't cooperate in a *direct way*. But there are ways for make them cooperative. Exactly that is asked in the referenced question. (And answers actually provides such ways). – Tsyvarev May 04 '17 at 13:14
  • Actually, `find_package` is the most simple way for filling `ITK_LIBRARIES` variables if you build ITK with `ExternalProject` means (not with `add_subdirectory`). In this case there is no specific of **static libraries**: if ITK builds static libraries, then `find_package()` should find them. Other "automatic" ways are .. just reinventing the wheel (implementing logic of `ITKConfig.cmake` script, used by `find_package`). – Tsyvarev May 04 '17 at 13:31
  • Ordering of static libraries is a nightmare. So you are right, I *need* to use `find_package` at all cost. – malat May 04 '17 at 13:34

1 Answers1

0

So I should not be building the ordered list of static libraries in ITK_LIBRARIES, this is too complex. Instead I should be using the logic from a call to find_package(ITK).

I need to change the way I build my project and switch to a SuperBuild type solution.

malat
  • 12,152
  • 13
  • 89
  • 158