0

I have tried following this solution this individual has from this question. I am trying to do this with boost with the following cmake file in a separate directory from my Source:

#---------------------------------------------------------------------------
# Get and build boost

SET_PROPERTY(DIRECTORY PROPERTY "EP_BASE" ${ep_base})
SET(boost_GIT_TAG "origin/master")
set( Boost_Bootstrap_Command )

if( UNIX )
  set( Boost_Bootstrap_Command ./bootstrap.sh )
  set( Boost_b2_Command ./b2 )
else()
  if( WIN32 )
    set( Boost_Bootstrap_Command bootstrap.bat )
    set( Boost_b2_Command b2.exe )
  endif()
endif()

ExternalProject_Add(Boost_external_Download
  GIT_REPOSITORY "https://github.com/boostorg/boost.git"
  GIT_TAG ${boost_GIT_TAG}
  BUILD_IN_SOURCE 1
  UPDATE_COMMAND ""
  PATCH_COMMAND ""
  CONFIGURE_COMMAND ${Boost_Bootstrap_Command}
  BUILD_COMMAND  ${Boost_b2_Command} install
    --without-python
    --without-mpi
    --disable-icu
    --prefix=${CMAKE_BINARY_DIR}/Boost
    --threading=single,multi
    --link=shared
    --variant=release
    -j8
  INSTALL_COMMAND ""
  INSTALL_DIR ""
)


if( NOT WIN32 )
  set(Boost_LIBRARY_DIR ${CMAKE_BINARY_DIR}/Boost/lib/ )
  set(Boost_INCLUDE_DIR ${CMAKE_BINARY_DIR}/Boost/include/boost/ )
else()
  set(Boost_LIBRARY_DIR ${CMAKE_BINARY_DIR}/Boost/lib/ )
  set(Boost_INCLUDE_DIR ${CMAKE_BINARY_DIR}/Boost/include/boost/ )
endif()

ExternalProject_Get_Property(Boost_external_Download BINARY_DIR)
SET(Boost_DIR ${BINARY_DIR} CACHE PATH "")

add_library(Boost_external SHARED IMPORTED)

The only thing that is different between one of the solutions and mine is that I don't have the set_target_properties right after I add the library. Since boost has a lot of libraries in there and I am not exactly sure what needs to be added.

In my Source Folder, my CMakeLists.txt does the following:

include_directories(${Boost_INCLUDE_DIR})

add_executable(Main main.cpp)
target_link_libraries(Main Boost_external)
add_dependencies(Main Boost_external_Download)

However, in main.cpp when I use #include <boost/process.hpp> just to see if it links, I get the error that #include <boost/process.hpp> no such file or directory. When I try to make the project. I am not really sure where I am going wrong with this so any helpful advice would be appreciated.

Edit: structure

Root Folder
|
- CmakeLists.txt
- Externals Directory
  |
  | - Externals.cmake
  | - boostExternal.cmake
  | - other external cmake files
- Source Directory
  |
  | - CmakeLists.txt
  | - main.cpp

The Root Cmake calls the Externals.cmake file. Which then includes all the other Cmake files within that directory. Once those are finished, the root Cmake file add the directory Source, and that Cmake file has the call to include_directories(${Boost_INCLUDE_DIR}).

Sailanarmo
  • 1,139
  • 15
  • 41
  • @Tsyvarev It is in my CMakeLists.txt file in my source folder. This boostExternal.cmake file is called from the root CMakeLists.txt file. I should have clarified my directory structure. – Sailanarmo Aug 02 '19 at 18:31
  • @Tsyvarev I am not sure I understand what you are asking. See my edit if you are confused. – Sailanarmo Aug 02 '19 at 18:42
  • My previous comments was wrong, sorry. So, you have `include_directories` command call, but it doesn't help in finding the headers. Have you checked the **actual** value of the `Boost_INCLUDE_DIR` when you use it in `include_directories` call? E.g. you may print value of the variable with `message()` command. Have you checked that directory, pointed by this variable, **actually** contains `boost/process.hpp` file? What **actual** content of this variable is and what **actual** location of the header file is? – Tsyvarev Aug 02 '19 at 21:17
  • @Tsyvarev I have done a message and that is what is confusing to me. If I call message within the `boostExternal.cmake` with the value of `Boost_INCLUDE_DIR`, I do get a message back showing me where the include directory is. However, if I call it anywhere else. It comes back blank. Curiously, if I do the same with `Boost_DIR`, that will print wherever I call it. – Sailanarmo Aug 02 '19 at 21:20
  • Well, so you include `boostExternal.cmake` in a way which adds the **scope**. So, setting `set(Boost_INCLUDE_DIR ${CMAKE_BINARY_DIR}/Boost/include/boost/ )` affects only on that scope, and in outer scope the variable remains unset (empty). Moreover, even `add_library(Boost_external SHARED IMPORTED)` affects only that scope, and `target_link_libraries(Main Boost_external)` call uses `Boost_external` as a *plain library name*, not a **target** (which would cause the error because `IMPORTED_LOCATION` property is not set). As for `Boost_DIR`, it is CACHED variable and exists in all scopes. – Tsyvarev Aug 02 '19 at 22:09
  • Would you include content of top-level `CMakeLists.txt` into the post, the problem would be easily detected. (This is why **showing the code** is usually much more helpful than *describing* that code. The same is true about the error messages.) – Tsyvarev Aug 02 '19 at 22:12

0 Answers0