0

I installed folly by attempting both ways of installation.

brew install folly
./build/bootstrap-osx-homebrew.sh

I have verified that it's installed correctly at the location /usr/local/Cellar/folly/2017.10.23.00.

Now I'm trying to use it in a HelloWorld project in CLion. Here is my CMakeLists.txt file.

cmake_minimum_required(VERSION 3.7)
project(HelloWorld)
message(STATUS "start running cmake....")
set(folly_DIR /usr/local/Cellar/folly/2017.10.23.00)
find_package(Boost 1.66)
find_package(folly 2017.10.23.00)
set(CMAKE_CXX_STANDARD 14)

if(Boost_FOUND)
    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
    message(STATUS "Boost_VERSION: ${Boost_VERSION}")

    include_directories(${Boost_INCLUDE_DIRS})
endif()

if(folly_FOUND)
    message(STATUS "folly_INCLUDE_DIRS: ${folly_INCLUDE_DIRS}")
    message(STATUS "folly_LIBRARIES: ${folly_LIBRARIES}")
    message(STATUS "folly_VERSION: ${folly_VERSION}")

    include_directories(${folly_INCLUDE_DIRS})
endif()

set(SOURCE_FILES main.cpp)
add_executable(HelloWorld ${SOURCE_FILES})

if(Boost_FOUND)
    target_link_libraries(HelloWorld ${Boost_LIBRARIES})
endif()
if(folly_FOUND)
    target_link_libraries(HelloWorld ${folly_LIBRARIES})
endif()

The error I get is:

  By not providing "Findfolly.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "folly", but
  CMake did not find one.

  Could not find a package configuration file provided by "folly" (requested
  version 2017.10.23.00) with any of the following names:

    follyConfig.cmake
    folly-config.cmake

  Add the installation prefix of "folly" to CMAKE_PREFIX_PATH or set
  "folly_DIR" to a directory containing one of the above files.  If "folly"
  provides a separate development package or SDK, be sure it has been
  installed.

I'm setting folly_DIR right at the top but it's still unable to find. What am I doing wrong?

RandomQuestion
  • 6,778
  • 17
  • 61
  • 97
  • Note that Boost 1.66 is currently not fully supported by CMake. A [fix is available in CMake master](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindBoost.cmake), but you will have to patch your local installation. – ComicSansMS Feb 26 '18 at 09:00

2 Answers2

1

The phrase

or set "*_DIR" to a directory containing one of the above files.

in the CMake error message should be treated as setting the cached variable to appropriate value.

Normally, the variable is set via command-line option -D when execute cmake. If you want to set the variable in CMakeLists.txt, add CACHE option to the set command:

set(folly_DIR /usr/local/Cellar/folly/2017.10.23.00 CACHE PATH "")

Make sure that given path contain one of the config files noted in the error message.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • I think that's the other issue. I can't seem to locate those files anywhere on my system. https://github.com/facebook/folly/tree/master/CMake includes `folly-config.h.cmake` but not `folly-config.cmake`. – RandomQuestion Feb 23 '18 at 23:01
  • According to fully's `CMakeLists.txt`, the config file is installed into `share/folly`. Probably, `dev` package should contain that file. – Tsyvarev Feb 23 '18 at 23:06
0

Create you own FindFolly.cmake file as following (reference here):

# Usage of this module as follows:
#
#     find_package(Folly)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
#  FOLLY_ROOT_DIR Set this variable to the root installation of
#                    folly if the module has problems finding
#                    the proper installation path.
#
# Variables defined by this module:
#
#  FOLLY_FOUND             System has folly libs/headers
#  FOLLY_LIBRARIES         The folly library/libraries
#  FOLLY_INCLUDE_DIR       The location of folly headers

find_path(FOLLY_ROOT_DIR
   NAMES include/folly/folly-config.h
)

find_library(FOLLY_LIBRARIES
   NAMES folly
   HINTS ${FOLLY_ROOT_DIR}/lib
)

find_library(FOLLY_BENCHMARK_LIBRARIES
   NAMES follybenchmark
   HINTS ${FOLLY_ROOT_DIR}/lib
)

find_path(FOLLY_INCLUDE_DIR
   NAMES folly/folly-config.h
   HINTS ${FOLLY_ROOT_DIR}/include
)

include(FindPackageHandleStandardArgs)
   find_package_handle_standard_args(Folly DEFAULT_MSG
   FOLLY_LIBRARIES
   FOLLY_INCLUDE_DIR
)

mark_as_advanced(
   FOLLY_ROOT_DIR
   FOLLY_LIBRARIES
   FOLLY_BENCHMARK_LIBRARIES
   FOLLY_INCLUDE_DIR
)

Then, you need to put this file into your CMake module path (more detailes here), that means:

  1. Create a folder named "cmake/Modules/" under your project root
  2. Put the FindFolly.cmake file in the created folder
  3. Add the following line to your cmake file:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

Ugo Giordano
  • 373
  • 3
  • 11