@@ -25,28 +25,54 @@ if(PROJECT_IS_TOP_LEVEL)
2525 set (CMAKE_VISIBILITY_INLINES_HIDDEN ON )
2626
2727 option (BUILD_EXAMPLE "Build the example" ON )
28+ option (BUILD_SHARED_LIBS "Build as a shared library" OFF )
2829 option (ENABLE_INSTALL "Generate install rules" ON )
2930else ()
3031 option (EGGS_ASSERT_BUILD_EXAMPLE "Build the example" OFF )
32+ option (
33+ EGGS_ASSERT_BUILD_SHARED_LIBS
34+ "Build as a shared library"
35+ ${BUILD_SHARED_LIBS }
36+ )
3137 option (EGGS_ASSERT_ENABLE_INSTALL "Generate install rules" OFF )
3238
3339 # Map prefixed options back to the canonical names used below
3440 set (BUILD_EXAMPLE ${EGGS_ASSERT_BUILD_EXAMPLE} )
41+ set (BUILD_SHARED_LIBS ${EGGS_ASSERT_BUILD_SHARED_LIBS} )
3542 set (ENABLE_INSTALL ${EGGS_ASSERT_ENABLE_INSTALL} )
3643endif ()
3744
3845#
39- # Library target — static library .
46+ # Library target — static or shared depending on BUILD_SHARED_LIBS .
4047# Internal name _eggs_assert; downstream CMake code uses the alias Eggs::Assert.
4148#
42- add_library (_eggs_assert STATIC src/assert.cpp )
43- target_sources (
49+ add_library (_eggs_assert src/assert.cpp )
50+ set_target_properties (
4451 _eggs_assert
45- PUBLIC FILE_SET HEADERS BASE_DIRS include FILES include /eggs/assert.h
52+ PROPERTIES EXPORT_NAME Assert OUTPUT_NAME eggs_assert
4653)
47- set_target_properties (_eggs_assert PROPERTIES EXPORT_NAME Assert)
4854target_compile_features (_eggs_assert PUBLIC cxx_std_23 )
4955
56+ include (GenerateExportHeader )
57+ generate_export_header (
58+ _eggs_assert
59+ BASE_NAME EGGS_ASSERT
60+ EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR } /include/eggs/assert-export.h"
61+ )
62+ if (NOT BUILD_SHARED_LIBS )
63+ target_compile_definitions (_eggs_assert PUBLIC EGGS_ASSERT_STATIC_DEFINE )
64+ endif ()
65+
66+ target_sources (
67+ _eggs_assert
68+ PUBLIC
69+ FILE_SET HEADERS
70+ BASE_DIRS include "${CMAKE_CURRENT_BINARY_DIR } /include"
71+ FILES
72+ include /eggs/assert.h
73+ "${CMAKE_CURRENT_BINARY_DIR } /include/eggs/assert-export.h"
74+ )
75+
5076include (Cxx23Stacktrace )
5177target_link_libraries (_eggs_assert PUBLIC ${EGGS_CXX23_STACKTRACE_LIB} )
5278
@@ -70,6 +96,8 @@ if(ENABLE_INSTALL)
7096 EXPORT EggsAssertTargets
7197 FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
7298 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
99+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
100+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
73101 )
74102
75103 install (
0 commit comments