如何在Mac OS上链接CLion中的Folly

时间:2018-02-23 21:51:31

标签: macos cmake clion folly

我通过尝试两种安装方式安装了folly

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

我已验证它已在/usr/local/Cellar/folly/2017.10.23.00位置正确安装。

现在我试图在CLion的HelloWorld项目中使用它。这是我的CMakeLists.txt文件。

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()

我得到的错误是:

  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.

我将folly_DIR设置在顶部,但仍然无法找到。我做错了什么?

2 个答案:

答案 0 :(得分:1)

短语

  

或设置" * _ DIR"到包含上述文件之一的目录。

应将CMake错误消息中的

视为将缓存变量设置为适当的值。

通常,执行-D时,通过命令行选项cmake设置变量。如果要在CMakeLists.txt中设置变量,请在set命令中添加 CACHE 选项:

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

确保给定路径包含错误消息中记录的配置文件之一。

答案 1 :(得分:0)

创建您自己的FindFolly.cmake文件,如下所示(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
)

然后,您需要将此文件放入CMake模块路径(more detailes here),这意味着:

  1. 创建一个名为" cmake / Modules /"的文件夹。在您的项目根目录
  2. 将FindFolly.cmake文件放入创建的文件夹
  3. 将以下行添加到您的cmake文件中:
  4. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")