mirror of
https://github.com/boostorg/boost-ci.git
synced 2026-01-19 04:02:12 +00:00
Make the test library a compiled library
Convert the header-only library to a compiled library which additionally depends (privately) on another compiled library (Boost.Atomic chosen as it has few other dependencies). This reproduces the runtime link failure of #155 when compiling shared libraries.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Copyright 2018-2021 Peter Dimov
|
||||
# Copyright 2021 Alexander Grund
|
||||
# Copyright 2021-2025 Alexander Grund
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
@@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.5...3.16)
|
||||
|
||||
project(boost_ci VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
||||
|
||||
add_library(boost_boost_ci INTERFACE)
|
||||
add_library(boost_boost_ci src/boost_ci.cpp)
|
||||
add_library(Boost::boost_ci ALIAS boost_boost_ci)
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS "3.19")
|
||||
@@ -15,13 +15,17 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.19")
|
||||
target_sources(boost_boost_ci PRIVATE ${headers})
|
||||
endif()
|
||||
|
||||
target_include_directories(boost_boost_ci INTERFACE include)
|
||||
target_include_directories(boost_boost_ci PUBLIC include)
|
||||
|
||||
target_link_libraries(boost_boost_ci
|
||||
INTERFACE
|
||||
Boost::config
|
||||
PUBLIC Boost::config
|
||||
PRIVATE Boost::atomic
|
||||
)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(boost_boost_ci PUBLIC BOOST_BOOST_CI_DYN_LINK)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
25
build/Jamfile.v2
Normal file
25
build/Jamfile.v2
Normal file
@@ -0,0 +1,25 @@
|
||||
# Boost CI Test Build Jamfile
|
||||
|
||||
# Copyright (c) 2022 Alexander Grund
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE or www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import configure ;
|
||||
|
||||
local requirements =
|
||||
<link>shared:<define>BOOST_BOOST_CI_DYN_LINK=1
|
||||
<library>/boost/atomic//boost_atomic
|
||||
;
|
||||
|
||||
project boost/ci
|
||||
: source-location ../src
|
||||
: requirements $(requirements)
|
||||
: usage-requirements $(requirements)
|
||||
;
|
||||
|
||||
lib boost_ci
|
||||
: boost_ci.cpp
|
||||
;
|
||||
|
||||
boost-install boost_ci ;
|
||||
@@ -18,6 +18,17 @@
|
||||
#define MSVC_VALUE 0
|
||||
#endif
|
||||
|
||||
// This define is usually set in boost/<libname>/config.hpp
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_BOOST_CI_DYN_LINK)
|
||||
#ifdef BOOST_BOOST_CI_SOURCE
|
||||
#define BOOST_BOOST_CI_DECL BOOST_SYMBOL_EXPORT
|
||||
#else
|
||||
#define BOOST_BOOST_CI_DECL BOOST_SYMBOL_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define BOOST_BOOST_CI_DECL
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace boost_ci
|
||||
@@ -27,25 +38,7 @@ namespace boost
|
||||
example_error() : std::runtime_error("Example error for demonstration") {}
|
||||
};
|
||||
|
||||
// Some function to test
|
||||
BOOST_NOINLINE int get_answer(const int isMsvc = MSVC_VALUE)
|
||||
{
|
||||
int answer;
|
||||
// Specifically crafted condition to check for coverage from MSVC and non MSVC builds
|
||||
if(isMsvc == 0)
|
||||
answer = 42;
|
||||
else if(isMsvc == 1)
|
||||
answer = 21;
|
||||
else
|
||||
throw example_error();
|
||||
|
||||
#ifdef BOOST_NO_CXX11_SMART_PTR
|
||||
return answer;
|
||||
#else
|
||||
// Just use some stdlib feature combined with a Boost.Config feature as demonstration
|
||||
auto ptr = std::unique_ptr<int>(new int(answer));
|
||||
return *ptr;
|
||||
#endif
|
||||
}
|
||||
// Some function to test. Returns 41 for 0, 42 for 1 and throws for other values
|
||||
BOOST_BOOST_CI_DECL int get_answer(int isMsvc = MSVC_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
46
src/boost_ci.cpp
Normal file
46
src/boost_ci.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright (c) 2022 Alexander Grund
|
||||
//
|
||||
// Use, modification and distribution is subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_BOOST_CI_SOURCE
|
||||
|
||||
#include <boost/boost-ci/boost_ci.hpp>
|
||||
// Just some dependency on another Boost library
|
||||
#include <boost/atomic/atomic.hpp>
|
||||
|
||||
// Some simple struct big enough so that the atomic is forced to use a lock
|
||||
// forcing it to call into the library
|
||||
struct X
|
||||
{
|
||||
double x, y, z;
|
||||
explicit X(int value = 0): x(value), y(value), z(value) {}
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace boost_ci
|
||||
{
|
||||
// Some function to test
|
||||
int get_answer(const int isMsvc)
|
||||
{
|
||||
boost::atomic<X> answer;
|
||||
// Specifically crafted condition to check for coverage from MSVC and non MSVC builds
|
||||
if(isMsvc == 1)
|
||||
answer = X(21);
|
||||
else if(isMsvc == 0)
|
||||
answer = X(42);
|
||||
else
|
||||
throw example_error();
|
||||
#ifdef BOOST_NO_CXX11_SMART_PTR
|
||||
return answer.load().x;
|
||||
#else
|
||||
// Just use some stdlib feature combined with a Boost.Config feature as demonstration
|
||||
auto ptr = std::unique_ptr<int>(new int(answer.load().x));
|
||||
return *ptr;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,8 @@
|
||||
import os ;
|
||||
import testing ;
|
||||
|
||||
project boost/ci/test
|
||||
: requirements
|
||||
<include>.
|
||||
project : requirements
|
||||
<library>/boost/ci//boost_ci
|
||||
;
|
||||
|
||||
local B2_ADDRESS_MODEL = [ os.environ B2_ADDRESS_MODEL ] ;
|
||||
|
||||
@@ -11,8 +11,27 @@ project(cmake_subdir_test LANGUAGES CXX)
|
||||
if(BOOST_CI_INSTALL_TEST)
|
||||
find_package(boost_boost_ci REQUIRED)
|
||||
else()
|
||||
add_subdirectory(../.. boostorg/ci)
|
||||
add_subdirectory(../../../config boostorg/config)
|
||||
add_subdirectory(../.. boostorg/boost-ci)
|
||||
|
||||
set(deps
|
||||
# Primary dependencies
|
||||
atomic
|
||||
config
|
||||
core
|
||||
# Secondary dependencies
|
||||
align
|
||||
assert
|
||||
predef
|
||||
preprocessor
|
||||
static_assert
|
||||
throw_exception
|
||||
type_traits
|
||||
winapi
|
||||
)
|
||||
|
||||
foreach(dep IN LISTS deps)
|
||||
add_subdirectory(../../../${dep} boostorg/${dep})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
add_executable(main main.cpp)
|
||||
|
||||
Reference in New Issue
Block a user