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

How to link different IlmBase library names according to Debug/Release configuration, when building OpenEXR with CMake + VS2015? #301

Closed
ghost opened this issue Jul 6, 2018 · 7 comments
Labels
Needs Discussion To be discussed in the technical steering committee

Comments

@ghost
Copy link

ghost commented Jul 6, 2018

My environment:

  • Windows 10 version 1803
  • Visual Studio 2015 Update 3
  • CMake 3.11.4
  • dev branch downloaded here.

I want to use different output names of IlmBase libraries for better management according to Debug/Release configuration in VS. Specifically, if built under Debug mode, the output name will be suffixed with "_d", say, Half-2_2_d.lib, Iex-2_2_d.dll. Otherwise, the names are left unchanged. For IlmBase, this is done by the following CMake command line:
cmake -DCMAKE_DEBUG_POSTFIX=_d -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=C:\...\openexr-develop\IlmBase\install_ -G"Visual Studio 14 2015 Win64" ..

Then I proceed to building OpenEXR and problem arises here. What I want is to set the IlmBase library names to be linked to OpenEXR project on the CMake command line only, instead of modifying existing CMakeLists.txt scripts, or changing names manually inside VS afterwards. I searched google for hours but the answers are all using target_link_libraries or add_library with IMPORTED flag, which requires modification of CMakeLists.txt. So my question is, does CMake have a general mechanism to set the suffix of linked library names, like the CMAKE_INSTALL_PREFIX I used above? Is there any flags I can use on CMake command line to specify the suffix of linked libraries for OpenEXR based on Debug/Release configuration, or, aiming at the final goal, how to link different IlmBase library names according to Debug/Release configuration? As a side note, the CMake command line I used to build OpenEXR is as follows:
cmake -DBUILD_SHARED_LIBS=ON -DILMBASE_PACKAGE_PREFIX=C:\...\openexr-develop\IlmBase\install_ -DCMAKE_INSTALL_PREFIX=C:\...\openexr-develop\OpenEXR\install_ -DZLIB_LIBRARY=C:\...\zlib-1.2.11\install\lib\zlib.lib -DZLIB_INCLUDE_DIR=C:\...\zlib-1.2.11\install\include -G"Visual Studio 14 2015 Win64" ..

I tried something like IMPORTED_LOCATION_DEBUG but of no avail.

Thank you for help.

@ghost ghost changed the title How link different IlmBase library names according to Debug/Release configuration, when building OpenEXR with CMake + VS2015 How to link different IlmBase library names according to Debug/Release configuration, when building OpenEXR with CMake + VS2015? Jul 6, 2018
@meshula
Copy link
Contributor

meshula commented Jul 6, 2018

Hi Zhou, if you try the develop branch, there is work in progress to generate debug libraries for windows with a different name than release, and for the debug and release OpenEXR libraries to appropriately link the IlmBase libraries.

There is a bit more work to do to clean it up, In particular, there should probably be ALIAS libraries to simplify linking, but perhaps you can start with what is on the develop branch already.

@ghost
Copy link
Author

ghost commented Jul 6, 2018

So, generally speaking, we need to add this feature by manually writing scripts in CMakeLists.txt? I had thought there is some existing option/flag provided by CMake that can do the work automatically on command line.

Thank you for your reply and the excellent work on the development of OpenEXT&IlmBase.

@meshula
Copy link
Contributor

meshula commented Jul 7, 2018

You can do it from the command line. After you have gone through the configuration steps, to build Release from the command line -

cmake --build . --target install --config Release -- /maxcpucount:16

Debug -

cmake --build . --target install --config Debug -- /maxcpucount:16

(set cpucount to a realistic number)

@ghost
Copy link
Author

ghost commented Jul 13, 2018

Sorry I just noticed the reply made 6 days ago. I didn't quite understand the reply however, perhaps because we are not on the same page. I read some more CMake documentations these days and confirmed my hypothesis that CMake does provide a mechanism for linking different filenames based on Debug/Release configuration. This is written in the doc of target_link_libraries function. As I mentioned in the original post, we can use CMAKE_DEBUG_POSTFIX to differentiate output library filename, but I was stuck by how to differentiate the input library filename. Now I know that this is done by specifying debug or optimized keyword when calling target_link_libraries() function; we can specify different library filenames after these keywords respectively. For example, Field3D are using this mechanism to link different versions of Boost libraries. Of course we need to modify CMakeLists.txt to make use of this mechanism. Is the ongoing work of OpenEXR using this way to link to different library filenames according to Debug/Release configuration?

@meshula
Copy link
Contributor

meshula commented Jul 13, 2018

I thought the following is true, please correct me if I am wrong. I have read the documentation page, and it seems that this is true:

  • create a cmake file to build library Foo
  • specify debug postfix _d to differentiate name
  • create a cmake file to build library Bar
  • specify target_link_library of Foo on Bar NOT using debug or optimized keyword
  • build Bar debug. Foo_d.lib will be linked
  • build Foo release. Foo.lib will be linked

@meshula
Copy link
Contributor

meshula commented Aug 3, 2018

Current top of tree on develop differentiates static libraries with _s, debug with _d, static debug with _s_d.

Import libraries have also been introduced (IlmBase::Half, IlmBase::Iex, etc). These libraries have debug and release variants with them.

So I think the things you need are now all in place.

@cary-ilm cary-ilm added the Needs Discussion To be discussed in the technical steering committee label Jun 26, 2019
@kdt3rd
Copy link
Contributor

kdt3rd commented Jul 22, 2019

As commented above, we believe there are all the controls necessary for setting suffixes on the generated libraries. In addition, the cmake system has been overhauled to use the "modern" cmake which should be a bit more robust. Create a new issue if there are any new issues. thank you for the report!

@kdt3rd kdt3rd closed this as completed Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Discussion To be discussed in the technical steering committee
Projects
None yet
Development

No branches or pull requests

3 participants