user2448431
user2448431

Reputation: 195

CMake is not including boost directories into it's generated projects

I have been trying to create a CMake project and then compiling it with Visual Studio 2015. When I Generate the Project Files, however, boost isn't included. Here is the relevant output from CMake upon generation:

Boost version: 1.62.0
Found the following Boost libraries:
system
thread
chrono
date_time
atomic
Configuring done
Generating done

And the paths are all correct. Where should CMake put the include directories, into VC++ Directories? Where could the build system be going wrong?

The actual CMakeLists.txt is as follows:

#MultiTracker Application
cmake_minimum_required (VERSION 3.1)
project(MultiTracker)

#Additional CMake search modules

#Require C++11
set (CMAKE_CXX_STANDARD 11)
message(STATUS "Generating Makefile for MultiTracker")

file(GLOB SRC_FILES *.cpp)
#Find and link boost
SET(Boost_USE_STATIC_LIBS   ON)
find_package(Boost REQUIRED system thread)

add_executable(MultiTracker ${SRC_FILES})
#Link internal libraries

#Link 3rd party libraries
target_link_libraries(MultiTracker ${Boost_LIBRARIES})

#The native OS thread library
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(MultiTracker Threads::Threads)

Main.cpp

//System Includes
#include <iostream>
#include <cstdlib>    

//Library Includes
#include <boost/program_options.hpp>
#include <boost/format.hpp>

//Local Includes    


int main(int iArgc, char *cpArgv[])
{
    std::string confName = "Conf.json", outFileName, inFileName;

    //setup the program options
    boost::program_options::options_description oPODescriptions("Available options");
    oPODescriptions.add_options()
        ("help", "help message")
        ("confFile", boost::program_options::value<std::string>(&confName)->default_value("pclConf.json"), "Name of the configuration file to use");

    boost::program_options::variables_map mapVars;
    try
    {
        boost::program_options::store(boost::program_options::parse_command_line(iArgc, cpArgv, oPODescriptions), mapVars);
        boost::program_options::notify(mapVars);
    }
    catch (std::exception &e)
    {
        std::cerr << e.what() << std::endl;
        return 2;
    }

    //print the help message
    if (mapVars.count("help"))
    {
        std::cout << "Stack Overflow Test: " << oPODescriptions << std::endl;
        return ~0;
    }

    std::cout << "Press enter to exit" << std::endl;
    std::cin.get();
}

Thanks!

Upvotes: 0

Views: 778

Answers (1)

roalz
roalz

Reputation: 2788

You should also include in your question HOW did you managed the Boost dependency in your CMakeLists.txt file.

If you used find_package(Boost) (see reference here),
you should add Boost_INCLUDE_DIRS to your target project include directories, and Boost_LIBRARIES to the libraries linked by your project.

See a very similar question and answer here: How do you add boost libraries in CMakeLists.txt

Added after question has been edited
you are missing:

target_include_directories(MultiTracker PRIVATE ${Boost_INCLUDE_DIRS})

(not sure about "PRIVATE" in your case)

Upvotes: 5

Related Questions