为什么CMake没有找到Boost?

时间:2016-09-29 17:32:43

标签: cmake boost-unit-test-framework

我尝试使用Boost单元测试框架来测试我的静态库,但是在调用BOOST_ROOT, CMAKE_INCLUDE_PATH, CMAKE_LIBRARY_PATH之前,尽管设置了find_package,但CMake无法找到Boost。实际上我已根据类似问题的答案尝试了很多选项,但仍未取得任何成功。

cmake版本:3.6.1

提升版本:1.60.0

Here is link to my project on GitHub

And here is log output from TravisCI

的CMakeLists.txt:

cmake_minimum_required(VERSION ${cmake_version})

project(${LibName}_test)

set(Boost_DEBUG ON)
set(Boost_DETAILED_FAILURE_MSG ON)

set(BOOST_ROOT $ENV{BOOST_ROOT})
message(STATUS "BOOST_ROOT >> ${BOOST_ROOT}")

set(BOOST_LIBRARYDIR $ENV{BOOST_ROOT}/lib)
set(BOOST_INCLUDEDIR $ENV{BOOST_ROOT}/include)

enable_testing()

set(Boost_USE_STATIC_LIBS       OFF)
set(Boost_USE_MULTITHREADED     ON)

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "$ENV{BOOST_ROOT}/include")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "$ENV{BOOST_ROOT}/lib")

find_package(Boost 1.60.0 EXACT REQUIRED COMPONENTS unit_test_framework)

#if(Boost_FOUND)
    include_directories("${LIB_HEADERS}")


    add_executable(test_executable
                                main.cpp
                                SomeClass_test.cpp
                                )

    target_include_directories(test_executable PRIVATE ${Boost_INCLUDE_DIRS})

    target_link_libraries(test_executable
                                        #${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
                                        Boost::unit_test_framework
                                        ${LibName}
                                        )

    add_test(NAME test1 COMMAND test_executable)
#else()
#   message(STATUS "No Boost library were found!")
#endif()

main.cpp中:

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include <iostream>

// initialization function:
bool init_unit_test()
{
    return true;
}

// entry point:
int main(int argc, char * argv[]) {
    // insert code here...

    std::cout << "Boost version: "
    << BOOST_VERSION / 100000     << "."  // major version
    << BOOST_VERSION / 100 % 1000 << "."  // minor version
    << BOOST_VERSION % 100                // patch level
    << std::endl;

    return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
}

SomeClass_test.cpp:

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include "config.h"
#include "Rectangle.h"
#include "SomeClass_test.hpp"

BOOST_AUTO_TEST_CASE(int_test)
{
    int i = 2;
    BOOST_TEST(i);
    BOOST_TEST(i == 2);

}

BOOST_AUTO_TEST_CASE(area_test)
{
    Rectangle rect;
    rect.set_values(2, 3);
    BOOST_TEST(6 == rect.area());
}

BOOST_AUTO_TEST_CASE(config_test)
{
    auto major = SimpleNet::Version::Major;
    BOOST_TEST(0 == major);
}

0 个答案:

没有答案