mirror of
https://github.com/vimpunk/mio.git
synced 2025-12-06 16:57:01 +08:00
Merge pull request #32 from gmbeard/multi-target-windows-api
Multi target windows api
This commit is contained in:
commit
d77add92da
@ -15,6 +15,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(mio VERSION 1.0.0 LANGUAGES C CXX)
|
project(mio VERSION 1.0.0 LANGUAGES C CXX)
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||||
include (CTest)
|
include (CTest)
|
||||||
include (CMakeDependentOption)
|
include (CMakeDependentOption)
|
||||||
|
|
||||||
@ -40,22 +41,41 @@ CMAKE_DEPENDENT_OPTION(mio.tests
|
|||||||
# transitively to linking targets. In our case, this amounts to an include
|
# transitively to linking targets. In our case, this amounts to an include
|
||||||
# directory and project header files.
|
# directory and project header files.
|
||||||
#
|
#
|
||||||
add_library(mio INTERFACE)
|
add_library(mio_base INTERFACE)
|
||||||
add_library(mio::mio ALIAS mio)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# mio requires C++ 11 support, at a minimum. Setting the `cxx_std_11` compile
|
# 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
|
# features ensures that the corresponding C++ standard flag is populated in
|
||||||
# targets linking to mio
|
# 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
|
# The include directory for mio can be expected to vary between build
|
||||||
# and installaion. Here we use a CMake generator expression to dispatch
|
# and installaion. Here we use a CMake generator expression to dispatch
|
||||||
# on how the configuration under which this library is being consumed.
|
# on how the configuration under which this library is being consumed.
|
||||||
#
|
#
|
||||||
target_include_directories(mio INTERFACE
|
target_include_directories(mio_base INTERFACE
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>)
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
|
||||||
@ -84,7 +104,7 @@ install(DIRECTORY include/
|
|||||||
# generate a CMake configuration file for consumption by CMake's `find_package`
|
# generate a CMake configuration file for consumption by CMake's `find_package`
|
||||||
# intrinsic
|
# intrinsic
|
||||||
#
|
#
|
||||||
install(TARGETS mio EXPORT mioConfig)
|
install(TARGETS mio_base mio EXPORT mioConfig)
|
||||||
install(EXPORT mioConfig
|
install(EXPORT mioConfig
|
||||||
FILE mioConfig.cmake
|
FILE mioConfig.cmake
|
||||||
NAMESPACE mio::
|
NAMESPACE mio::
|
||||||
|
|||||||
@ -285,6 +285,8 @@ find_package( mio REQUIRED )
|
|||||||
target_link_libraries( MyTarget PUBLIC mio::mio )
|
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
|
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,
|
+ the `CMAKE_PREFIX_PATH` configuration option,
|
||||||
|
|||||||
14
cmake/WinApiLevels.cmake
Normal file
14
cmake/WinApiLevels.cmake
Normal file
@ -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)
|
||||||
@ -3,7 +3,7 @@
|
|||||||
# doing so populates these files in the source listing when CMake is used
|
# doing so populates these files in the source listing when CMake is used
|
||||||
# to generate XCode and Visual Studios projects
|
# to generate XCode and Visual Studios projects
|
||||||
#
|
#
|
||||||
target_sources(mio INTERFACE
|
target_sources(mio_base INTERFACE
|
||||||
$<BUILD_INTERFACE:
|
$<BUILD_INTERFACE:
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mmap.hpp
|
${CMAKE_CURRENT_LIST_DIR}/mmap.hpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/page.hpp
|
${CMAKE_CURRENT_LIST_DIR}/page.hpp
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
# detail files in the source listing for CMake-generated IDE projects
|
# detail files in the source listing for CMake-generated IDE projects
|
||||||
#
|
#
|
||||||
if(NOT subproject)
|
if(NOT subproject)
|
||||||
target_sources(mio INTERFACE
|
target_sources(mio_base INTERFACE
|
||||||
$<BUILD_INTERFACE:
|
$<BUILD_INTERFACE:
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mmap.ipp
|
${CMAKE_CURRENT_LIST_DIR}/mmap.ipp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/string_util.hpp>)
|
${CMAKE_CURRENT_LIST_DIR}/string_util.hpp>)
|
||||||
|
|||||||
@ -22,9 +22,6 @@
|
|||||||
#define MIO_PAGE_HEADER
|
#define MIO_PAGE_HEADER
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifndef WIN32_LEAN_AND_MEAN
|
|
||||||
# define WIN32_LEAN_AND_MEAN
|
|
||||||
# endif // WIN32_LEAN_AND_MEAN
|
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#else
|
#else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
|||||||
@ -7,4 +7,9 @@ if(WIN32)
|
|||||||
target_link_libraries(mio.unicode.test PRIVATE mio::mio)
|
target_link_libraries(mio.unicode.test PRIVATE mio::mio)
|
||||||
target_compile_definitions(mio.unicode.test PRIVATE UNICODE)
|
target_compile_definitions(mio.unicode.test PRIVATE UNICODE)
|
||||||
add_test(NAME mio.unicode.test COMMAND mio.test)
|
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()
|
endif()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user