Skip to content

Commit 033084a

Browse files
committed
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.
1 parent 5b22d1d commit 033084a

File tree

6 files changed

+109
-28
lines changed

6 files changed

+109
-28
lines changed

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ cmake_minimum_required(VERSION 3.5...3.16)
77

88
project(boost_ci VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
99

10-
add_library(boost_boost_ci INTERFACE)
10+
add_library(boost_boost_ci src/boost_ci.cpp)
1111
add_library(Boost::boost_ci ALIAS boost_boost_ci)
1212

13-
target_include_directories(boost_boost_ci INTERFACE include)
13+
target_include_directories(boost_boost_ci PUBLIC include)
1414

1515
target_link_libraries(boost_boost_ci
16-
INTERFACE
16+
PUBLIC
1717
Boost::config
18+
PRIVATE
19+
Boost::atomic
1820
)
1921

22+
if(BUILD_SHARED_LIBS)
23+
target_compile_definitions(boost_boost_ci PUBLIC BOOST_BOOST_CI_DYN_LINK)
24+
endif()
25+
2026
if(BUILD_TESTING)
2127
add_subdirectory(test)
2228
endif()

build/Jamfile.v2

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Boost CI Test Build Jamfile
2+
3+
# Copyright (c) 2022 Alexander Grund
4+
#
5+
# Distributed under the Boost Software License, Version 1.0.
6+
# (See accompanying file LICENSE or www.boost.org/LICENSE_1_0.txt)
7+
8+
import configure ;
9+
10+
local requirements =
11+
<link>shared:<define>BOOST_BOOST_CI_DYN_LINK=1
12+
<library>/boost/atomic//boost_atomic
13+
;
14+
15+
project boost/ci
16+
: source-location ../src
17+
: requirements $(requirements)
18+
: usage-requirements $(requirements)
19+
;
20+
21+
lib boost_ci
22+
: boost_ci.cpp
23+
;
24+
25+
boost-install boost_ci ;

include/boost/boost-ci/boost_ci.hpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
#include <memory>
1212
#endif
1313

14+
// This define is usually set in boost/<libname>/config.hpp
15+
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_BOOST_CI_DYN_LINK)
16+
#ifdef BOOST_BOOST_CI_SOURCE
17+
#define BOOST_BOOST_CI_DECL BOOST_SYMBOL_EXPORT
18+
#else
19+
#define BOOST_BOOST_CI_DECL BOOST_SYMBOL_IMPORT
20+
#endif
21+
#else
22+
#define BOOST_BOOST_CI_DECL
23+
#endif
24+
1425
namespace boost
1526
{
1627
namespace boost_ci
@@ -21,25 +32,7 @@ namespace boost
2132
#define MSVC_VALUE false
2233
#endif
2334

24-
// Some function to test
25-
BOOST_NOINLINE int get_answer(const bool isMsvc = MSVC_VALUE)
26-
{
27-
int answer;
28-
// Specifically crafted condition to check for coverage from MSVC and non MSVC builds
29-
if(isMsvc)
30-
{
31-
answer = 21;
32-
} else
33-
{
34-
answer = 42;
35-
}
36-
#ifdef BOOST_NO_CXX11_SMART_PTR
37-
return answer;
38-
#else
39-
// Just use some stdlib feature combined with a Boost.Config feature as demonstration
40-
auto ptr = std::unique_ptr<int>(new int(answer));
41-
return *ptr;
42-
#endif
43-
}
35+
// Some function to test. Returns 41 for true, 42 otherwise
36+
BOOST_BOOST_CI_DECL int get_answer(bool isMsvc = MSVC_VALUE);
4437
}
4538
}

src/boost_ci.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// Copyright (c) 2022 Alexander Grund
3+
//
4+
// Use, modification and distribution is subject to the Boost Software License,
5+
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt)
7+
8+
#define BOOST_BOOST_CI_SOURCE
9+
10+
#include <boost/boost-ci/boost_ci.hpp>
11+
// Just some dependency on another Boost library
12+
#include <boost/atomic/atomic.hpp>
13+
14+
namespace boost
15+
{
16+
namespace boost_ci
17+
{
18+
// Some function to test
19+
int get_answer(const bool isMsvc)
20+
{
21+
boost::atomic_int answer;
22+
// Specifically crafted condition to check for coverage from MSVC and non MSVC builds
23+
if(isMsvc)
24+
{
25+
answer = 21;
26+
} else
27+
{
28+
answer = 42;
29+
}
30+
#ifdef BOOST_NO_CXX11_SMART_PTR
31+
return answer;
32+
#else
33+
// Just use some stdlib feature combined with a Boost.Config feature as demonstration
34+
auto ptr = std::unique_ptr<int>(new int(answer));
35+
return *ptr;
36+
#endif
37+
}
38+
}
39+
}

test/Jamfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import os ;
99
import testing ;
1010

11-
project boost/ci/test
12-
: requirements
13-
<include>.
11+
project : requirements
12+
<library>/boost/ci//boost_ci
1413
;
1514

1615
local B2_ADDRESS_MODEL = [ os.environ B2_ADDRESS_MODEL ] ;

test/cmake_test/CMakeLists.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,27 @@ project(cmake_subdir_test LANGUAGES CXX)
1111
if(BOOST_CI_INSTALL_TEST)
1212
find_package(boost_boost_ci REQUIRED)
1313
else()
14-
add_subdirectory(../.. boostorg/ci)
15-
add_subdirectory(../../../config boostorg/config)
14+
add_subdirectory(../.. boostorg/boost-ci)
15+
16+
set(deps
17+
# Primary dependencies
18+
atomic
19+
config
20+
core
21+
# Secondary dependencies
22+
align
23+
assert
24+
predef
25+
preprocessor
26+
static_assert
27+
throw_exception
28+
type_traits
29+
winapi
30+
)
31+
32+
foreach(dep IN LISTS deps)
33+
add_subdirectory(../../../${dep} boostorg/${dep})
34+
endforeach()
1635
endif()
1736

1837
add_executable(main main.cpp)

0 commit comments

Comments
 (0)