Tuesday, February 24, 2015

CMake unable to read Boost's version.hpp

Ever wonder how Boost works together with CMake? I have no knowledge prior to this setup, thus this is my initial code in CMakeLists.txt.
cmake_minimum_required(VERSION 2.8.4)
project("Project A")

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_ALL_DYN_LINK ON)

find_package(Boost 1.54.0 COMPONENTS filesystem system REQUIRED)

if(Boost_FOUND)
 message(STATUS "Boost library were found")
 
 include_directories(${Boost_INCLUDE_DIRS})
 add_executable(Project_A source/main.cpp)
 target_link_libraries(syncFile ${Boost_LIBRARIES})
else()
 message(STATUS "No Boost library were found")
endif()
As of this writing, I'm using Boost 1.54 and CMake 3.1.2. Anyhow, there is an error when generating the Makefile. Here is the error:
CMake Error at /usr/share/cmake-3.1.2/Modules/FindBoost.cmake:685 (file):
  file STRINGS file "/cygdrive/d/visual studio
  2012/projectA/C:/boost/include/boost-1_54/boost/version.hpp" cannot be
  read.
Call Stack (most recent call first):
  CMakeLists.txt:19 (find_package)


-- Could NOT find Boost
-- No Boost library were found
-- Configuring incomplete, errors occurred!
I have been trying on cygwin, and DOS prompt, it is somewhat weird that the error was happening in FindBoost.cmake. This is the code snippet on the piece that throw an error:
# Set Boost_FOUND based only on header location and version.
# It will be updated below for component libraries.
if(Boost_INCLUDE_DIR)
  if(Boost_DEBUG)
    message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
                   "location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp")
  endif()

  # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
  set(Boost_VERSION 0)
  set(Boost_LIB_VERSION "")
  file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS REGEX "#define BOOST_(LIB_)?VERSION ")
A quick check on ${Boost_INCLUDE_DIR}, it shows C:/boost/include/boost-1_54, but I don't know why there is a default path and why ${Boost_INCLUDE_DIR} appended to that default path. I have tried the workaround on BOOST_ROOT as described here, and here, and also try the workaround on CMAKE_PREFIX_PATH as describe here but none of them work. I also found this link were quite useful, but it doesn't work on find_package command.

I'm running out of clues on this problem. Since the default path was bundled together with CMake as one package, I choose to override Boost_INCLUDE_DIR instead of shake him off away.
  ...

  set(Boost_INCLUDE_DIR /cygdrive/c/boost/include/boost-1_54)
But this isn't a perfect solution as it wouldn't work on Linux since the Boost path is referring to Windows. I'm still searching a solution for this.

No comments: