2021年3月13日星期六

FB/folly and CMake's FetchContent

I am building a project in an environment where I cannot control the packages installed. Therefore, I would like them to be downloaded from a git-repo and built during the project compilation. Then, ideally I would simply do target_link_libraries(${MY_TARGET} PUBLIC folly).

So, I decided to give CMake's FetchContent a go, for FB/folly library. However, simply adding to my CMakeLists.txt

FetchContent_Declare(    folly    GIT_REPOSITORY https://github.com/facebook/folly.git  )  

with the subsequent FetchContent_MakeAvailable(folly) gives an error that it also depends on double-conversion. Doing the same for the latter library yields further complications of the same kind. Did anybody have success using FB/folly via FetchContent?

EDIT: After the comment below, I have improved my question considerably. Now, I first make sure I fetch and install the dependencies. For example, double-conversion is handled like this:

FetchContent_Declare(    DoubleConversion      GIT_REPOSITORY https://github.com/google/double-conversion.git  )  FetchContent_GetProperties(DoubleConversion)  string(TOLOWER "DoubleConversion" lcName)  if(NOT ${lcName}_POPULATED)    # Fetch the content using previously declared details    FetchContent_Populate(DoubleConversion)    # Set custom variables, policies, etc.    # Bring the populated content into the build    add_subdirectory(${${lcName}_SOURCE_DIR} ${${lcName}_BINARY_DIR})    find_package(double-conversion CONFIG REQUIRED)    message("DoubleConversion Library = " ${DOUBLE_CONVERSION_LIBRARY})    message("DoubleConversion Include Directory = " ${DOUBLE_CONVERSION_INCLUDE_DIR})  endif()  

Now, Folly uses DOUBLE_CONVERSION_LIBRARY variable. That is the reason in the above snippet I am message-ing this value to the console. However, that one is NOT_FOUND: DoubleConversion Library = DOUBLE_CONVERSION_LIBRARY-NOTFOUND

The question is, how, after find_package(double-conversion), find out the values of the DOUBLE_CONVERSION_LIBRARY and DOUBLE_CONVERSION_INCLUDE_DIR as required by FB/folly? How does FB/folly know that these variables will be named exactly as such, esp. given that in the double-conversion I could not find any obvious indication nor references to such variables?

EDIT': Based on the comment below, I have come this far:

include(ExternalProject)    FetchContent_Declare(      double-conversion      GIT_REPOSITORY https://github.com/google/double-conversion.git      CMAKE_ARGS -DBUILD_TESTING=OFF   )  FetchContent_MakeAvailable(double-conversion)  set(DOUBLE_CONVERSION_LIBRARY /usr/lib64/libdouble-conversion.a)  set(DOUBLE_CONVERSION_INCLUDE_DIR /usr/include/double-conversion)  FetchContent_Declare(      Glog      GIT_REPOSITORY https://github.com/google/glog.git      CMAKE_ARGS -DBUILD_TESTING=OFF   )  FetchContent_MakeAvailable(Glog)  set(GLOG_LIBRARY /usr/lib64/libglog.a)  set(GLOG_INCLUDE_DIR /usr/include/glog)  FetchContent_Declare(    folly      GIT_REPOSITORY https://github.com/facebook/folly.git    CMAKE_ARGS -DBUILD_TESTS=OFF  )  FetchContent_MakeAvailable(folly)  

This works, but I do not like the solution. Here, I first observed where the library and header files are installed in the dependencies for folly, and then hardcode these values via the set() instruction. However, ideally I would want to have them somewhere "safe" (i.e. not to assume anything about the system, nor mess with it) and "predictable". How to specify these inside the FetchContent? Should I do something like -DCMAKE_INSTALL_PREIX=${CURRENT_BINARY_DIR}? But then CMake complains that the installation path is in current binary directory. What is the best approach here?

https://stackoverflow.com/questions/66612731/fb-folly-and-cmakes-fetchcontent March 13, 2021 at 07:08PM

没有评论:

发表评论