|
3 | 3 | # See accompanying file LICENSE_1_0.txt |
4 | 4 | # or copy at http://www.boost.org/LICENSE_1_0.txt) |
5 | 5 |
|
6 | | -# Illustrates the exe-exports-data / DLL-imports-data pattern on Windows: |
7 | | -# the exe defines and exports a variable; the DLL imports and reads it. |
8 | | -# |
9 | | -# On non-Windows both compilation units are linked into a single executable. |
| 6 | +# Illustrates the dllvar technique: the exe owns (exports) a variable; the |
| 7 | +# DLL imports it. Both see static_answer<answer_dllvar, void>::value as the |
| 8 | +# same linker symbol because the varying base class does not enter the mangled |
| 9 | +# name; SFINAE selects dllexport in the owner and dllimport in the client. |
10 | 10 |
|
11 | | -if (WIN32 OR CYGWIN) |
12 | | - # Exe exports the registry state and loads the plugin at runtime. |
13 | | - add_executable(windll_main main.cpp) |
14 | | - target_compile_definitions(windll_main PRIVATE WINDLL_OWNER) |
15 | | - set_target_properties(windll_main PROPERTIES ENABLE_EXPORTS ON) |
| 11 | +if (NOT (WIN32 OR CYGWIN)) |
| 12 | + return() |
| 13 | +endif() |
16 | 14 |
|
17 | | - # DLL imports the variable from the exe. |
18 | | - add_library(windll_plugin SHARED plugin.cpp) |
19 | | - target_link_libraries(windll_plugin PRIVATE windll_main) |
20 | | - set_target_properties(windll_plugin PROPERTIES ENABLE_EXPORTS ON) |
| 15 | +add_executable(windll_main main.cpp) |
| 16 | +target_compile_definitions(windll_main PRIVATE WINDLL_OWNER) |
| 17 | +set_target_properties(windll_main PROPERTIES ENABLE_EXPORTS ON) |
21 | 18 |
|
22 | | - # windll_main loads windll_plugin at runtime; build both before testing. |
23 | | - add_custom_target(windll_all ALL DEPENDS windll_main windll_plugin) |
| 19 | +add_library(windll_plugin SHARED plugin.cpp) |
| 20 | +target_link_libraries(windll_plugin PRIVATE windll_main) |
24 | 21 |
|
25 | | - add_test( |
26 | | - NAME windll |
27 | | - COMMAND windll_main |
28 | | - WORKING_DIRECTORY $<TARGET_FILE_DIR:windll_main>) |
29 | | -else() |
30 | | - # Non-Windows: single executable, no DLL decoration needed. |
31 | | - add_executable(windll_main main.cpp plugin.cpp) |
32 | | - target_compile_definitions(windll_main PRIVATE WINDLL_OWNER) |
| 22 | +add_custom_target(windll_all ALL DEPENDS windll_main windll_plugin) |
33 | 23 |
|
34 | | - add_test(NAME windll COMMAND windll_main) |
35 | | -endif() |
| 24 | +add_test( |
| 25 | + NAME windll |
| 26 | + COMMAND windll_main |
| 27 | + WORKING_DIRECTORY $<TARGET_FILE_DIR:windll_main>) |
0 commit comments