MantisBT - CMake
View Issue Details
0015364CMakeCMakepublic2015-01-22 07:552016-03-07 09:12
Gunther Laure 
Brad King 
normalmajoralways
closedfixed 
CMake 3.1 
CMake 3.3CMake 3.3 
0015364: FindBoost.cmake does not find debug libraries if they are located in a different directory than the release libraries
FindBoost.cmake does not find debug libraries if they are located in a different directory than the release libraries.

Assume following boost lib dir layout:

lib/shared/Debug
lib/shared/Release
lib/static/Debug
lib/static/Release
lib64/shared/Debug
lib64/shared/Release
lib64/static/Debug
lib64/static/Release

For previous cmake version we changed changed the CMAKE_LIBRARY_PATH (depending on x86,x64,Release,Debug) so that FindBoost did find the correct libraries.

The current version of FindBoost.cmake assumes that Debug and Release have to be in the same directoy.

This is done in the macro _Boost_FIND_LIBRARY (line 323-325):
  # If Boost_LIBRARY_DIR is known then search only there.
  if(Boost_LIBRARY_DIR)
    set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH)
  endif()


Commenting/Removing these lines restores the previous behaviour and Release and Debug libraries are found again.
create a directory structure like that:
lib/Debug
lib/Release

and put valid boost libs in there:
lib/Debug/boost_system-vc120-mt-gd-1_55.lib
lib/Release/boost_system-vc120-mt-1_55.lib

With CMAKE_LIBRARY_PATH set to both directories and the current version of cmake (3.1)
find_package(Boost REQUIRED COMPONENTS
  system
)
will result in:
Boost_SYSTEM_LIBRARY = lib/Release/boost_system-vc120-mt-1_55.lib


with the lines 323 to 325 commented in FindBoost.cmake it will find both libs:
Boost_SYSTEM_LIBRARY = optimized;lib/Release/boost_system-vc120-mt-1_55.lib;debug;lib/Debug/boost_system-vc120-mt-gd-1_55.lib
(absolute path removed manually)

If this is only an issue for us, we could workaround the problem with a customized FindBoost.cmake file in our environment.
No tags attached.
has duplicate 0015778closed  Support BOOST_LIBRARYDIR_DEBUG and BOOST_LIBRARYDIR_RELEASE 
? FindBoost.cmake (55,192) 2015-01-23 03:09
https://public.kitware.com/Bug/file/5357/FindBoost.cmake
patch 98bf613c+0001-FindBoost-Separate-search-for-debug-and-release-libraries.patch (7,729) 2015-01-23 08:43
https://public.kitware.com/Bug/file/5358/98bf613c%2B0001-FindBoost-Separate-search-for-debug-and-release-libraries.patch
patch 0001-FindBoost-Separate-search-for-debug-and-release-libr.patch (8,189) 2015-01-26 07:51
https://public.kitware.com/Bug/file/5364/0001-FindBoost-Separate-search-for-debug-and-release-libr.patch
patch 0002-FindBoost-Separate-search-for-debug-and-release-libr.patch (10,596) 2015-01-26 12:17
https://public.kitware.com/Bug/file/5365/0002-FindBoost-Separate-search-for-debug-and-release-libr.patch
patch v2-0001-FindBoost-Search-for-debug-and-release-libraries-sep.patch (11,618) 2015-02-03 14:17
https://public.kitware.com/Bug/file/5371/v2-0001-FindBoost-Search-for-debug-and-release-libraries-sep.patch
Issue History
2015-01-22 07:55Gunther LaureNew Issue
2015-01-22 09:11Brad KingNote Added: 0037770
2015-01-22 09:28Gunther LaureNote Added: 0037771
2015-01-22 09:28Gunther LaureNote Edited: 0037771bug_revision_view_page.php?bugnote_id=37771#r1684
2015-01-22 09:44Brad KingNote Added: 0037772
2015-01-22 10:04Ben BoeckelNote Added: 0037773
2015-01-22 10:15Gunther LaureNote Added: 0037774
2015-01-22 10:56Ben BoeckelNote Added: 0037775
2015-01-23 03:09Gunther LaureFile Added: FindBoost.cmake
2015-01-23 03:09Gunther LaureNote Added: 0037783
2015-01-23 08:43Brad KingFile Added: 98bf613c+0001-FindBoost-Separate-search-for-debug-and-release-libraries.patch
2015-01-23 08:45Brad KingNote Added: 0037785
2015-01-23 08:51Brad KingNote Added: 0037786
2015-01-26 07:51Gunther LaureFile Added: 0001-FindBoost-Separate-search-for-debug-and-release-libr.patch
2015-01-26 07:56Gunther LaureNote Added: 0037806
2015-01-26 11:04Brad KingNote Added: 0037814
2015-01-26 11:31Gunther LaureNote Added: 0037816
2015-01-26 12:17Gunther LaureFile Added: 0002-FindBoost-Separate-search-for-debug-and-release-libr.patch
2015-01-26 12:20Gunther LaureNote Added: 0037817
2015-02-03 14:17Brad KingFile Added: v2-0001-FindBoost-Search-for-debug-and-release-libraries-sep.patch
2015-02-03 14:19Brad KingNote Added: 0037894
2015-02-04 02:53Gunther LaureNote Added: 0037902
2015-02-05 10:55Brad KingNote Added: 0037924
2015-02-05 10:55Brad KingAssigned To => Brad King
2015-02-05 10:55Brad KingStatusnew => resolved
2015-02-05 10:55Brad KingResolutionopen => fixed
2015-02-05 10:55Brad KingFixed in Version => CMake 3.3
2015-02-05 10:55Brad KingTarget Version => CMake 3.3
2015-02-05 10:55Brad KingSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=1697#r1697
2015-10-08 13:06Brad KingRelationship addedhas duplicate 0015778
2016-03-07 09:12Robert MaynardNote Added: 0040607
2016-03-07 09:12Robert MaynardStatusresolved => closed

Notes
(0037770)
Brad King   
2015-01-22 09:11   
The purpose of the "# If Boost_LIBRARY_DIR is known then search only there." block is to make sure all boost libraries that are found belong together. Prior to that people had all kinds of problems with mixed libraries getting found scattered about. Boost mangles its library names with the configuration specifically so they can be put in the same directory. That is the simplest solution.

Since the _Boost_FIND_LIBRARY calls are already separate for release and debug configurations one could look at tracking the library directories separately.
(0037771)
Gunther Laure   
2015-01-22 09:28   
I understand and in fact I stumbled over this problem a lot. Specially on Linux when the system boost libraries mix up with the ones I build.

I will try to patch FindBoost.cmake so that the constraint hold that all release libraries have to be in the same directory and all debug libraries too.
There should be not restriction if its the same for release and debug or not.
(this is the change you proposed I think).

(0037772)
Brad King   
2015-01-22 09:44   
Re 0015364:0037771: Yes, that is what I proposed. Thanks!

Please try to make the change backward compatible for people that already set Boost_LIBRARY_DIR. It should be used to initialize the config-specific names if it is explicitly set. If not then it does not have to be added as a cache entry. Also once one config is found that should be the first directory considered for the other config so that if all libraries are together then they work.
(0037773)
Ben Boeckel   
2015-01-22 10:04   
Just for the record, does Boost create this directory structure on its own when installing it?
(0037774)
Gunther Laure   
2015-01-22 10:15   
Re 0015364:0037773: I am installing boost (and other 3rdparty libraries) that way using the standard --prefix and --libdir configure options.

So no, this is not a Boost default installation.
(0037775)
Ben Boeckel   
2015-01-22 10:56   
Maybe it would be better to have a flag to find_library ("CONFIGURATION_SUFFIX" or something?) which looks in a configuration-named subdirectory for libraries rather than doing this for every FindX module out there? Not that find_library isn't already a complicated beast... But FindBoost is also a very unique module due to the structure of Boost itself, so maybe it's easier to test run here and see if it's more widely useful later.
(0037783)
Gunther Laure   
2015-01-23 03:09   
Uploaded proposed changes to FindBoost.cmake
(0037785)
Brad King   
2015-01-23 08:45   
Re 0015364:0037783: Thanks for working on it. I applied it on top of v3.1.0 and then rebased on master as of commit 98bf613c. Then I used "git format-patch" to generate the attached "98bf613c+0001-FindBoost-Separate-search-for-debug-and-release-libraries.patch". For further updates please base work on the 'master' branch in Git and use "git format-patch" to construct patches. Otherwise we risk un-doing unrelated changes by copying the raw file.
(0037786)
Brad King   
2015-01-23 08:51   
Re 0015364:0037785: Some comments on the patch:

In the documentation, Boost_LIBRARY_DIR should no longer be listed as a cached value. Also, if the user does set Boost_LIBRARY_DIR then we should use that for both Boost_LIBRARY_DIR_RELEASE and Boost_LIBRARY_DIR_DEBUG without caching the latter. Only if Boost_LIBRARY_DIR is not set should we provide the per-config cache entries. We must preserve the behavior that if any of these values is already set then we don't cache them or force values.

Rather than duplicating _Boost_FIND_LIBRARY please add a parameter to it to specify the configuration.

When setting Boost_LIBRARY_DIRS at the end, use list(REMOVE_DUPLICATES) in case both directories are the same.

Once either Boost_LIBRARY_DIR_RELEASE or Boost_LIBRARY_DIR_DEBUG is determined, its value should be used at the front of the search path for the other configuration until that one is determined too. That way if all libraries for both configurations are together then they will still be found together.
(0037806)
Gunther Laure   
2015-01-26 07:56   
New patch:
* Boost_LIBRARY_DIR no longer cached, removed from doc
* Preserve behaviour of Boost_LIBRARY_DIR
* _Boost_FIND_LIBRARY got RELEASE,DEBUG argument
* list(REMOVE_DUPLICATES) on Boost_LIBRARY_DIRS
* use found Boost_LIBRARY_DIR_RELEASE as first search dir for Boost_LIBRARY_DIR_DEBUG (and vice verse)

Use git format-patch

Afaik I did it :).
(0037814)
Brad King   
2015-01-26 11:04   
Re 0015364:0037806: Thanks. Please use "git config --global user.name" and "git config --global user.email " to set your name and email address for the patch.

We can still document Boost_LIBRARY_DIR down in the "other variables" section:

# Boost_LIBRARY_DIR - Default value for Boost_LIBRARY_DIR_RELEASE and
# Boost_LIBRARY_DIR_DEBUG.

The logic to use it as a default should be the same for both configs:

# If the user sets BOOST_LIBRARY_DIR, use it as the default for both
# configurations.
if(NOT Boost_LIBRARY_DIR_RELEASE AND Boost_LIBRARY_DIR)
  set(Boost_LIBRARY_DIR_RELEASE "${Boost_LIBRARY_DIR}")
endif()
if(NOT Boost_LIBRARY_DIR_DEBUG AND Boost_LIBRARY_DIR)
  set(Boost_LIBRARY_DIR_DEBUG "${Boost_LIBRARY_DIR}")
endif()

The _Boost_CHANGE_DETECT call needs to be split to have one for each configuration.
(0037816)
Gunther Laure   
2015-01-26 11:31   
Agreed. I will add these changes.
The macro _Boost_CHANGE_DETECT is a complicated beast. Hopefully I will get that right.
(0037817)
Gunther Laure   
2015-01-26 12:20   
I did split the call to _Boost_CHANGE_DETECT. I think it is not necessary to check for changes in Boost_LIBRARY_DIR, so I replaced it with checks for Boost_LIBRARY_DIR_RELEASE and Boost_LIBRARY_DIR_DEBUG.
(0037894)
Brad King   
2015-02-03 14:19   
Re 0015364:0037817: I realized the logic could be simplified with a foreach() over DEBUG and RELEASE. Please try out

 v2-0001-FindBoost-Search-for-debug-and-release-libraries-sep.patch

After applying with Git locally, use

 git show -w --color-words=.

to see the changes more easily.
(0037902)
Gunther Laure   
2015-02-04 02:53   
The patch looks good! It's working in our environment.
(0037924)
Brad King   
2015-02-05 10:55   
I've applied the change:

 FindBoost: Search for debug and release libraries separately
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=892b854f [^]

It was too late in the 3.2 release preparation cycle to add such a change, but it is now in place in post-3.2 development targeting 3.3.
(0040607)
Robert Maynard   
2016-03-07 09:12   
Closing resolved issues that have not been updated in more than 4 months.