MantisBT - CMake
View Issue Details
0015301CMakeCMakepublic2014-12-12 12:032015-05-04 09:05
jackcmedia 
 
normalminoralways
closedno change required 
Windows7, 64 Bits
CMake 3.0.2 
 
0015301: FIND_LIBRARY_USE_LIB64_PATHS doesn't work on Windows OSes
Setting up a bi-arch cross-compiling script to generate 32 or 64 bit binaries on demand.

Found that FIND_LIBRARY_USE_LIB64_PATHS doesn't work on Windows, failing to locate the 64 bit libraries placed on a folder named "lib64". Renaming said folder to "lib" makes it work as intended.
1.- Install CMake 3.0.2 (TDM-GCC's MinGW-w64 4.9.2 and CLion are my compiler and IDE of choice, but are not required).

2.- Set up SFML 2.1 64 bits, a third party library, like this:

  include
  lib64 (x64 libs)

and set the CMake (or environmental variable) SFML_ROOT pointing to the root folder of the third party library.

3.- Create a minimal CMakeLists.txt, like the following:

cmake_minimum_required(VERSION 2.8)
project(CMakeTest LANGUAGES CXX)

if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  message(WARNING "Target is 64 bits")
else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  message(WARNING "Target is 32 bits")
endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")

set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2.1 REQUIRED graphics system window)

include_directories(${PROJECT_SOURCE_DIR}/)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})

if(SFML_FOUND)
  include_directories(${SFML_INCLUDE_DIR})
  target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})
endif()

4.- Create a minimal source file, like the following:

#include <SFML/Graphics/RenderWindow.hpp>

int main() {
  sf::RenderWindow window2;
  return 0;
}

5.- Download FindSFML.cmake from https://github.com/LaurentGomila/SFML/blob/2.1/cmake/Modules/FindSFML.cmake [^] and add it to the project inside ${PROJECT_SOURCE_DIR}/cmake/Modules.

6.- Try to compile and confirm it fails to locate the libraries.

7.- Rename "lib64" to "lib" and compile again. This time, it's a success.
c++, CMake, find_library, unix, Windows 7
Issue History
2014-12-12 12:03jackcmediaNew Issue
2014-12-12 13:22Brad KingNote Added: 0037448
2014-12-13 09:15jackcmediaNote Added: 0037449
2014-12-13 09:16jackcmediaTag Attached: c++
2014-12-13 09:16jackcmediaTag Attached: CMake
2014-12-13 09:16jackcmediaTag Attached: find_library
2014-12-13 09:16jackcmediaTag Attached: unix
2014-12-13 09:16jackcmediaTag Attached: Windows 7
2014-12-14 09:17jackcmediaNote Added: 0037455
2014-12-14 09:18jackcmediaNote Edited: 0037455bug_revision_view_page.php?bugnote_id=37455#r1642
2014-12-15 09:08Brad KingNote Added: 0037456
2014-12-15 09:08Brad KingStatusnew => resolved
2014-12-15 09:08Brad KingResolutionopen => no change required
2015-05-04 09:05Robert MaynardNote Added: 0038696
2015-05-04 09:05Robert MaynardStatusresolved => closed

Notes
(0037448)
Brad King   
2014-12-12 13:22   
One can see the use of FIND_LIBRARY_USE_LIB64_PATHS here:

 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmFindLibraryCommand.cxx;hb=v3.0.2#l58 [^]

and it depends on CMAKE_SIZEOF_VOID_P through cmMakefile::PlatformIs64Bit here:

 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmMakefile.cxx;hb=v3.0.2#l2367 [^]

Perhaps that will help start debugging it.
(0037449)
jackcmedia   
2014-12-13 09:15   
Detecting whether a platform is 32 or 64 bits seems to work fine.

Downloaded the CMake 3.0.2 source code and started tinkering with it on a XUbuntu 14.04 64 bit VM to see what is happening. Using the minimal reproducible example I provided (assuming I have the third party libraries at /home/jack/SFML-2.1/, the x64 libraries are inside the "lib64" subfolder and FIND_LIBRARY_USE_LIB64_PATHS is enabled), among the paths considered as possible places where the libraries might be are:

/home/jack/SFML-2.1/lib64/
/home/jack/SFML-2.1/lib64/64/
/home/jack/SFML-2.1/lib/
/home/jack/SFML-2.1/lib64/
/home/jack/SFML-2.1/lib64/64/
/home/jack/SFML-2.1/lib/64/
/home/jack/SFML-2.1/
/home/jack/SFML-2.1/64/

Notice the first and third items on that list. Yet, when using make to generate the binaries, it doesn't find the libraries on the first path and, instead, complains that they cannot be found on the third path.

Doesn't seem to be OS specific. Let me check if this is how it works on Windows...
(0037455)
jackcmedia   
2014-12-14 09:17   
(edited on: 2014-12-14 09:18)
All right, I feel like an idiot now.

FIND_LIBRARY_USE_LIB64_PATHS works on Windows. I've tested this both on Windows and Linux with the official precompiled binaries and binaries I modified to tell me, if the libraries have been found, where are them. Indeed, it finds the libraries located at the "lib64" subfolder.

The "bug" was a combination of CMake not updating the paths to the libraries and always pointing to the 32-bit libraries (I thought it would be updated), CLion not being able to delete the cache files.

So, closing this bug report. At least I learned a bit about the inner workings of CMake and found an unrelated bug in FindSFML.cmake...

(0037456)
Brad King   
2014-12-15 09:08   
Re 0015301:0037455: Okay, thanks for reporting back.
(0038696)
Robert Maynard   
2015-05-04 09:05   
Closing resolved issues that have not been updated in more than 4 months.