diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bbdba7..339430f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ else() endif() project(mio VERSION 1.0.0 LANGUAGES C CXX) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") include (CTest) include (CMakeDependentOption) @@ -40,22 +41,41 @@ CMAKE_DEPENDENT_OPTION(mio.tests # transitively to linking targets. In our case, this amounts to an include # directory and project header files. # -add_library(mio INTERFACE) -add_library(mio::mio ALIAS mio) +add_library(mio_base INTERFACE) # # mio requires C++ 11 support, at a minimum. Setting the `cxx_std_11` compile # features ensures that the corresponding C++ standard flag is populated in # targets linking to mio # -target_compile_features(mio INTERFACE cxx_std_11) +target_compile_features(mio_base INTERFACE cxx_std_11) + +# +# On Windows, so as to be a "good citizen", mio offers two different +# targets that control the imported surface area of the Windows API. The +# default `mio` target sets the necessary flags for a minimal Win API +# (`WIN32_LEAN_AND_MEAN`, etc.), while the `mio_full_winapi` target sets +# none of these flags so will not disable any of the modules. +# +if(WIN32) + include(WinApiLevels) +else() + # On non-Windows systems, the `mio` and `mio_base` targets are + # effectively identical. + add_library(mio INTERFACE) + target_link_libraries(mio + INTERFACE mio_base + ) +endif() + +add_library(mio::mio ALIAS mio) # # The include directory for mio can be expected to vary between build # and installaion. Here we use a CMake generator expression to dispatch # on how the configuration under which this library is being consumed. # -target_include_directories(mio INTERFACE +target_include_directories(mio_base INTERFACE $ $) @@ -84,7 +104,7 @@ install(DIRECTORY include/ # generate a CMake configuration file for consumption by CMake's `find_package` # intrinsic # -install(TARGETS mio EXPORT mioConfig) +install(TARGETS mio_base mio EXPORT mioConfig) install(EXPORT mioConfig FILE mioConfig.cmake NAMESPACE mio:: diff --git a/README.md b/README.md index d09b2f8..3555ce6 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,8 @@ find_package( mio REQUIRED ) target_link_libraries( MyTarget PUBLIC mio::mio ) ``` +**WINDOWS USERS**: The `mio::mio` target `#define`s `WIN32_LEAN_AND_MEAN` and `NOMINMAX`. The former ensures the imported surface area of the Win API is minimal, and the latter disables Windows' `min` and `max` macros so they don't intefere with `std::min` and `std::max`. Because *mio* is a header only library, these defintions will leak into downstream CMake builds. If their presence is causing problems with your build then you can use the alternative `mio::mio_full_winapi` target, which adds none of these defintions. + If mio was installed to a non-conventional location, it may be necessary for downstream projects to specify the mio installation root directory via either + the `CMAKE_PREFIX_PATH` configuration option, diff --git a/cmake/WinApiLevels.cmake b/cmake/WinApiLevels.cmake new file mode 100644 index 0000000..5f3ebad --- /dev/null +++ b/cmake/WinApiLevels.cmake @@ -0,0 +1,14 @@ +add_library(mio_full_winapi INTERFACE) +target_link_libraries(mio_full_winapi + INTERFACE mio_base +) +add_library(mio::mio_full_winapi ALIAS mio_full_winapi) + +add_library(mio INTERFACE) +target_link_libraries(mio + INTERFACE mio_full_winapi +) +target_compile_definitions(mio + INTERFACE WIN32_LEAN_AND_MEAN NOMINMAX +) +install(TARGETS mio_full_winapi EXPORT mioConfig) diff --git a/include/mio/CMakeLists.txt b/include/mio/CMakeLists.txt index 57268b6..c2d495c 100644 --- a/include/mio/CMakeLists.txt +++ b/include/mio/CMakeLists.txt @@ -3,7 +3,7 @@ # doing so populates these files in the source listing when CMake is used # to generate XCode and Visual Studios projects # -target_sources(mio INTERFACE +target_sources(mio_base INTERFACE $) diff --git a/include/mio/page.hpp b/include/mio/page.hpp index c2536a0..cae7377 100644 --- a/include/mio/page.hpp +++ b/include/mio/page.hpp @@ -22,9 +22,6 @@ #define MIO_PAGE_HEADER #ifdef _WIN32 -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif // WIN32_LEAN_AND_MEAN # include #else # include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 444d537..6bfc47e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,4 +7,9 @@ if(WIN32) target_link_libraries(mio.unicode.test PRIVATE mio::mio) target_compile_definitions(mio.unicode.test PRIVATE UNICODE) add_test(NAME mio.unicode.test COMMAND mio.test) + + add_executable(mio.fullwinapi.test test.cpp) + target_link_libraries(mio.fullwinapi.test + PRIVATE mio::mio_full_winapi) + add_test(NAME mio.fullwinapi.test COMMAND mio.test) endif()