Skip to content

Commit 42d43a9

Browse files
committed
export
1 parent 1d74ef2 commit 42d43a9

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,28 @@ endif()
4747
# Internal name _eggs_assert; downstream CMake code uses the alias Eggs::Assert.
4848
#
4949
add_library(_eggs_assert src/assert.cpp)
50+
set_target_properties(_eggs_assert PROPERTIES EXPORT_NAME Assert)
51+
target_compile_features(_eggs_assert PUBLIC cxx_std_23)
52+
53+
include(GenerateExportHeader)
54+
generate_export_header(
55+
_eggs_assert
56+
BASE_NAME EGGS_ASSERT
57+
EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/eggs/assert-export.h"
58+
)
5059
target_sources(
5160
_eggs_assert
52-
PUBLIC FILE_SET HEADERS BASE_DIRS include FILES include/eggs/assert.h
61+
PUBLIC
62+
FILE_SET HEADERS
63+
BASE_DIRS include "${CMAKE_CURRENT_BINARY_DIR}/include"
64+
FILES
65+
include/eggs/assert.h
66+
"${CMAKE_CURRENT_BINARY_DIR}/include/eggs/assert-export.h"
5367
)
54-
set_target_properties(_eggs_assert PROPERTIES EXPORT_NAME Assert)
55-
target_compile_features(_eggs_assert PUBLIC cxx_std_23)
68+
get_target_property(_eggs_assert_type _eggs_assert TYPE)
69+
if(_eggs_assert_type STREQUAL "STATIC_LIBRARY")
70+
target_compile_definitions(_eggs_assert PUBLIC EGGS_ASSERT_STATIC_DEFINE)
71+
endif()
5672

5773
include(Cxx23Stacktrace)
5874
target_link_libraries(_eggs_assert PUBLIC ${EGGS_CXX23_STACKTRACE_LIB})

include/eggs/assert.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
#else
2020

21+
# include <eggs/assert-export.h>
22+
2123
# ifdef __cplusplus
22-
extern "C" [[noreturn]] void eggs_assert_failed(
24+
extern "C" [[noreturn]] EGGS_ASSERT_EXPORT void eggs_assert_failed(
2325
char const* message, char const* file, unsigned line, char const* function
2426
);
2527
# else
26-
_Noreturn void eggs_assert_failed(
28+
EGGS_ASSERT_EXPORT _Noreturn void eggs_assert_failed(
2729
char const* message, char const* file, unsigned line, char const* function
2830
);
2931
# endif

src/assert.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Distributed under the Boost Software License, Version 1.0. (See accompanying
66
// file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
77

8+
#include <eggs/assert-export.h>
89
#include <eggs/assert.h>
910

1011
#include <cstdio>
@@ -29,7 +30,7 @@ void println(std::format_string<Args...> fmt, Args&&... args)
2930

3031
} // namespace
3132

32-
extern "C" [[noreturn]] void eggs_assert_failed(
33+
extern "C" [[noreturn]] EGGS_ASSERT_EXPORT void eggs_assert_failed(
3334
char const* message, char const* file, unsigned line, char const* function
3435
)
3536
{

test/cmake-find_package/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ if(_assert_type STREQUAL "SHARED_LIBRARY")
2525
add_custom_command(
2626
TARGET consumer_verify
2727
POST_BUILD
28-
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Eggs::Assert>
29-
$<TARGET_FILE_DIR:consumer_verify>
28+
COMMAND
29+
${CMAKE_COMMAND} -E copy_if_different
30+
$<TARGET_FILE:Eggs::Assert> $<TARGET_FILE_DIR:consumer_verify>
3031
)
3132
else()
3233
set_target_properties(
33-
consumer_verify PROPERTIES BUILD_RPATH "$<TARGET_FILE_DIR:Eggs::Assert>"
34+
consumer_verify
35+
PROPERTIES BUILD_RPATH "$<TARGET_FILE_DIR:Eggs::Assert>"
3436
)
3537
endif()
3638
endif()

0 commit comments

Comments
 (0)