Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dcmtk] How to use CONAN_LIBS to link libraries #5638

Closed
akalali opened this issue May 26, 2021 · 4 comments
Closed

[dcmtk] How to use CONAN_LIBS to link libraries #5638

akalali opened this issue May 26, 2021 · 4 comments
Labels
question Further information is requested

Comments

@akalali
Copy link

akalali commented May 26, 2021

I have several ExternalProjects that I would like to use with the cci DCMTK recipe.
E.g. CTK requires DCMTK_LIBRARIES and DCMTK_INCLUDE_DIRS to be set and they are defined inside the DCMTKConfig.cmake-file of the classical built DCMTK, e.g.

set(DCMTK_LIBRARIES "ofstd;oflog;dcmdata;i2d;dcmimgle;dcmimage;dcmjpeg;ijg8;ijg12;ijg16;dcmjpls;charls;dcmtls;dcmnet;dcmsr;cmr;dcmdsig;dcmwlm;dcmqrdb;dcmpstat;dcmrt;dcmiod;dcmfg;dcmseg;dcmtract;dcmpmap")

or

list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/build/config/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/ofstd/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/oflog/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmdata/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmimgle/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmimage/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmjpeg/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmjpls/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmtls/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmnet/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmsr/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmsign/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmwlm/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmqrdb/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmpstat/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmrt/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmiod/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmfg/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmseg/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmtract/include")
list(APPEND DCMTK_INCLUDE_DIRS "C:/Development/3rdparty/DCMTK/src/dcmpmap/include")

So using the classic CMake build approach for DCMTK and using find_package to find DCMTK provides these variables.

However, with the DCMTK Conan recipe these variables are not defined inside the DCMTKConfig.cmake-file.
Generating the conanbuildinfo.cmake-, DCMTKConfig.cmake- and DCMTKTargets.cmake-files (and some more) by using the conan cmake wrapper gives me some variables that I can use for my ExternalProjects, e.g.

inside conanbuildinfo.cmake

set(CONAN_LIBS_DCMTK i2d dcmjpeg ijg8 ijg12 ijg16 dcmjpls charls cmr dcmwlm dcmpstat dcmtls dcmsr dcmimage dcmdsig dcmqrdb dcmnet dcmrt dcmimgle dcmseg dcmtract dcmpmap dcmfg dcmiod dcmdata oflog ofstd)

or

set(CONAN_INCLUDE_DIRS_DCMTK "C:/.conan/data/dcmtk/3.6.5/_/_/package/e7e107e6cd35509c9b558bc060f0b7e067b8e481/include"
			"C:/.conan/data/dcmtk/3.6.5/_/_/package/e7e107e6cd35509c9b558bc060f0b7e067b8e481/include/dcmtk")

But I can not use the CONAN_LIBS_DCMTK for DCMTK_LIBRARIES, I get the following error:
Line 'DCMTK_LIBRARIES:=' does not match regex. Ignoring when doing

ExternalProject_Add(CTK
  GIT_REPOSITORY https://github.com/commontk/CTK
  GIT_TAG 7210c5bcc37bf1140a04c97bfe1e27142735c6ab
  UPDATE_COMMAND ""
  INSTALL_COMMAND ""
  CMAKE_CACHE_ARGS
    -DCMAKE_MODULE_PATH:PATH=${CMAKE_MODULE_PATH}
    -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
    -DITK_DIR:PATH=${ITK_DIR}
    -DDCMTK_DIR:PATH=${DCMTK_DIR}
    -DDCMTK_INCLUDE_DIRS:PATH=${CONAN_INCLUDE_DIRS_DCMTK}
    -DDCMTK_LIBRARIES:=${CONAN_LIBS_DCMTK}

inside my custom CTK.cmake-file.

I wonder how to replicate the original behavior and how to correctly use the DCMTK Conan recipe for other third parties. I also did not succeed using the DCMTK (or cci ITK packag) for DCMQI, see here or here.

There still seem to be a general misunderstanding on my side on how to replace a transitive dependency of an ExternalProject with a Conan package, ignoring the external project's way to find the required dependency and set the paths. So what can I do if a third party (e.g. CTK or DCMQI) require specific variables to be set (which is done in the original project) but the variables are not defined by Conan?

@akalali akalali added the question Further information is requested label May 26, 2021
@jgsogo
Copy link
Contributor

jgsogo commented May 28, 2021

Hi, @akalali . The generators provided by Conan use a template that is common for all the references, so it is expected that custom variables are not available when using Conan, and they are when using the modules provided by the library itself.

Conan implemented a feature called build_modules which is being used exactly for your purpose and many recipes here use it to provide those extra variables that are expected by consumers that were using the original Find/Config files. Sometimes we use them not only to provide those extra variables, but also to create estra targets (usually alias) that are provided by the upstream project.

You can have a look at OpenSSL recipe, it is adding an extra .cmake file with some custom variables: https://github.com/conan-io/conan-center-index/blob/master/recipes/openssl/1.x.x/conanfile.py#L802

I encourage you to create a PR contributing to DCMTK with these extra variables that are expected by consumers.

@jgsogo jgsogo changed the title How to use CONAN_LIBS to link libraries [dcmtk] How to use CONAN_LIBS to link libraries May 28, 2021
@akalali
Copy link
Author

akalali commented Jun 2, 2021

Hi @jgsogo and thank you for you reply.
I looked into the mentioned OpenSSL recipe but it is way to complex to for me to understand. The linked function seems to define some variables based on the values of other variables.

I tried to test this with DCMTK and it gives me a conan-official-dcmtk-targets.cmake inside my package\7cfafe290988bc08ced572b947f8619a8d4bc824\lib\cmake-directory. Here it basically writes the CMake script I added to the DCMTK Conan recipe. How would that help me? How is this file included?

I'm not sure if this is what I need: I somehow need to transfer the two mentioned variables from my initial post to the conanbuildinfo.cmake or rather the DCMTKConfig.cmake. But I somehow need them to be filled automatically - it does not make sense to write set(DCMTK_LIBRARIES "ofstd;oflog;dcmdata;i2d;dcmimgle;dcmimage;dcmjpeg;ijg8;ijg12;ijg16;dcmjpls;charls;dcmtls;dcmnet;dcmsr;cmr;dcmdsig;dcmwlm;dcmqrdb;dcmpstat;dcmrt;dcmiod;dcmfg;dcmseg;dcmtract;dcmpmap") inside the recipe because this would not allow to dynamically change the required libraries.

@jgsogo
Copy link
Contributor

jgsogo commented Jun 7, 2021

Those build_modules are just a CMake script stored in a file that Conan will include from the files generated by Conan's generators.

Yours would look like something like this:

my_cmake_build_module = """\
   set(DCMTK_LIBRARIES ...)
   set(DCMTK_INCLUDE_DIRS ...)
   """

def package(self):
   # Copy your file inside the package
   ... 

def package_info(self):
   self.cpp_info.build_modules['cmake'] = ['relative/path/to/your/file/inside/the/package', ]
   self.cpp_info.build_modules['cmake_find_package'] = ['relative/path/to/your/file/inside/the/package', ]
   self.cpp_info.build_modules['cmake_find_package_multi'] = ['relative/path/to/your/file/inside/the/package', ]

With this scaffolding, you should be able to modify the DCMTK recipe, now when you run conan install dcmtk/<version> -g cmake -g cmake_find_package -g cmake_find_package_multi you should observe that inside the files generated by Conan there is an include(....) directive to your build_module.

Now the problem is to assign the proper values to DCMTK_LIBRARIES and DCMTK_INCLUDE_DIRS. As you can see, your build module is included after all the information defined by Conan, so you can use all the variables you have there. Depending on the generator, these variables will be different, but all the information related to the Conan package is there to be used.

@SpaceIm
Copy link
Contributor

SpaceIm commented Feb 6, 2022

@akalali Those variables are defined in cmake_find_package or CMakeDeps generators. I think that this issue can be closed.

@SSE4 SSE4 closed this as completed Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants