|
| 1 | +# Copyright (c) 2018-2025 Jean-Louis Leroy |
| 2 | +# Distributed under the Boost Software License, Version 1.0. |
| 3 | +# See accompanying file LICENSE_1_0.txt |
| 4 | +# or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | + |
| 6 | +# Illustrates the dllvar mechanism: the exe owns (exports) the registry state; |
| 7 | +# the DLL imports it, contributing overriders that are consolidated by |
| 8 | +# initialize() before first use. |
| 9 | +# |
| 10 | +# On non-Windows both compilation units are linked into a single executable. |
| 11 | + |
| 12 | +if (WIN32 OR CYGWIN) |
| 13 | + # Exe exports the registry state and loads the plugin at runtime. |
| 14 | + add_executable(windll_main main.cpp) |
| 15 | + target_compile_definitions(windll_main PRIVATE WINDLL_OWNER) |
| 16 | + set_target_properties(windll_main PROPERTIES ENABLE_EXPORTS ON) |
| 17 | + target_link_libraries(windll_main PRIVATE Boost::openmethod) |
| 18 | + |
| 19 | + # DLL imports the registry state from the exe. |
| 20 | + add_library(windll_plugin SHARED plugin.cpp) |
| 21 | + target_link_libraries(windll_plugin PRIVATE Boost::openmethod windll_main) |
| 22 | + set_target_properties(windll_plugin PROPERTIES ENABLE_EXPORTS ON) |
| 23 | + |
| 24 | + # windll_main loads windll_plugin at runtime; build both before testing. |
| 25 | + add_custom_target(windll_all ALL DEPENDS windll_main windll_plugin) |
| 26 | + |
| 27 | + add_test( |
| 28 | + NAME windll |
| 29 | + COMMAND windll_main |
| 30 | + WORKING_DIRECTORY $<TARGET_FILE_DIR:windll_main>) |
| 31 | +else() |
| 32 | + # Non-Windows: single executable, no DLL decoration needed. |
| 33 | + add_executable(windll_main main.cpp plugin.cpp) |
| 34 | + target_compile_definitions(windll_main PRIVATE WINDLL_OWNER) |
| 35 | + target_link_libraries(windll_main PRIVATE Boost::openmethod) |
| 36 | + |
| 37 | + add_test(NAME windll COMMAND windll_main) |
| 38 | +endif() |
0 commit comments