1- cmake_minimum_required (VERSION 3.8 )
1+ cmake_minimum_required (VERSION 3.26 )
2+ project (mio LANGUAGES CXX )
23
3- #
4- # Here we check whether mio is being configured in isolation or as a component
5- # of a larger project. To do so, we query whether the `PROJECT_NAME` CMake
6- # variable has been defined. In the case it has, we can conclude mio is a
7- # subproject.
8- #
9- # This convention has been borrowed from the Catch C++ unit testing library.
10- #
11- if (DEFINED PROJECT_NAME )
12- set (subproject ON )
13- if (NOT DEFINED INSTALL_SUBPROJECTS)
14- set (INSTALL_SUBPROJECTS ON CACHE BOOL "Install subproject dependencies" )
15- endif ()
16- else ()
17- set (subproject OFF )
18- set_property (GLOBAL PROPERTY USE_FOLDERS ON )
19- endif ()
20-
21- project (mio VERSION 1.1.0 LANGUAGES C CXX )
22- list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR} /cmake" )
23- include (CMakeDependentOption )
24- include (CMakePackageConfigHelpers )
25- include (CTest )
26- include (GNUInstallDirs )
27-
28- # Generate 'compile_commands.json' for clang_complete
29- set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
30-
31- #
32- # mio requires C++ 11 support, at a minimum. The `CMAKE_CXX_STANDARD` variable
33- # is referenced when a target is created to initialize the CXX_STANDARD target
34- # property.
35- #
36- # ** NOTE **
37- # This is a directory scope variable. This has several implicitations.
38- #
39- # 1. It DOES NOT propegate to parent scopes (such as parent projects)
40- # 2. It hides cache variables of the same name for this directory and below
41- #
42- set (CMAKE_CXX_STANDARD 11)
4+ # Set C++20 as the minimum required standard
5+ set (CMAKE_CXX_STANDARD 20)
436set (CMAKE_CXX_STANDARD_REQUIRED ON )
447
45- #
46- # The `mio.testing` options only appear as cmake-gui and ccmake options iff
47- # mio is the highest level project. In the case that mio is a subproject, these
48- # options are hidden from the user interface and set to `OFF`
49- #
50- # Iff mio is the highest level project, this option is defaulted to the value
51- # of the traditional course grain testing option `BUILD_TESTING` established by
52- # the CTest module
53- #
54- CMAKE_DEPENDENT_OPTION (mio.tests
55- "Build the mio tests and integrate with ctest"
56- ON "BUILD_TESTING; NOT subproject" OFF )
57-
58- #
59- # On Windows, so as to be a "good citizen", mio offers two mechanisms to control
60- # the imported surface area of the Windows API. The default `mio` target sets
61- # the necessary flags for a minimal Win API (`WIN32_LEAN_AND_MEAN`, etc.) on
62- # linking targets. This is, in our view, the conservative behavior.
63- #
64- # However, an option is published in the cache allowing client to opt out of
65- # these compiler definintions. This preference will persist in the installed
66- # cmake configuration file, but can be modified by downstream users by way of
67- # the same cmake cache variable. This allows intermediate consumers (e.g. other
68- # libraries) to defer this decision making to downstream clients.
69- #
70- # Beyond the option-based mechanism, two additional targets,
71- # mio::mio_min_winapi and mio::mio_full_winapi, are specified below for those
72- # that expressly requiring either the minimal or full windows API, respectively.
73- #
74- CMAKE_DEPENDENT_OPTION (mio.windows.full_api
75- "Configure mio without WIN32_LEAN_AND_MEAN and NOMINMAX definitions"
76- OFF "WIN32" ON )
77-
78- #
79- # When the end user is consuming mio as a nested subproject, an option
80- # is provided such that the user may exlude mio from the set of installed
81- # cmake projects. This accomodates end users building executables or
82- # compiled libraries which privately link to mio, but wish to only ship their
83- # artifacts in an installation
84- #
85- CMAKE_DEPENDENT_OPTION (mio.installation
86- "Include mio in the install set"
87- "${INSTALL_SUBPROJECTS} " "subproject" ON )
88- mark_as_advanced (mio.installation )
8+ # Enable CTest support if BUILD_TESTING is enabled
9+ include (CTest )
10+ if (BUILD_TESTING)
11+ enable_testing ()
12+ endif ()
8913
90- #
91- # mio has no compiled components. As such, we declare it as an `INTERFACE`
92- # library, which denotes a collection of target properties to be applied
93- # transitively to linking targets. In our case, this amounts to an include
94- # directory and (potentially) some preprocessor definitions.
95- #
14+ # Create an interface library "mio" to provide the include directory.
15+ # It is assumed that the headers are located in "single_include/mio".
9616add_library (mio INTERFACE )
97- add_library (mio::mio ALIAS mio )
98-
99- #
100- # The include directory for mio can be expected to vary between build
101- # and installaion. Here we use a CMake generator expression to dispatch
102- # on how the configuration under which this library is being consumed.
103- #
104- # We define the generator expression as a variable, such that the logic
105- # need not be repeated when populating source file paths.
106- #
107- string (CONCAT prefix
108- "$<BUILD_INTERFACE :${CMAKE_CURRENT_LIST_DIR} /include >"
109- "$<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >" )
110-
111- target_include_directories (mio INTERFACE ${prefix} )
112-
113- if (NOT mio.windows.full_api)
114- target_compile_definitions (mio INTERFACE
115- $<BUILD_INTERFACE :WIN32_LEAN_AND_MEAN >
116- $<BUILD_INTERFACE :NOMINMAX >)
17+ target_include_directories (mio INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} /single_include )
18+
19+ # Add a basic test executable that is built on all platforms.
20+ # Note that the test source file is assumed to be located at "test/test.cpp".
21+ add_executable (mio.test ${CMAKE_CURRENT_SOURCE_DIR} /test/test.cpp )
22+ target_link_libraries (mio.test PRIVATE mio )
23+ if (BUILD_TESTING)
24+ add_test (NAME mio.test COMMAND mio.test )
11725endif ()
11826
27+ # Windows-specific targets (only built on Windows)
11928if (WIN32 )
120- add_library (mio_full_winapi INTERFACE )
121- add_library (mio::mio_full_winapi ALIAS mio_full_winapi )
122- target_include_directories (mio_full_winapi INTERFACE ${prefix} )
123-
124- add_library (mio_min_winapi INTERFACE )
125- add_library (mio::mio_min_winapi ALIAS mio_full_winapi )
126- target_compile_definitions (mio INTERFACE WIN32_LEAN_AND_MEAN NOMINMAX )
127- target_include_directories (mio_min_winapi INTERFACE ${prefix} )
128- endif ()
129-
130- #
131- # In order to collect mio's header files in IDE tools such as XCode or Visual
132- # Studio, there must exist a target adding any such header files as source files.
133- #
134- # Given mio is an interface target, source files may only be added with the
135- # INTERFACE keyword, which consequently propegate to linking targets. This
136- # behavior isn't desirable to all clients.
137- #
138- # To accomodate, a second target is declared which collects the header files,
139- # which links to the primary mio target. As such, the header files are available
140- # in IDE tools.
141- #
142- add_library (mio-headers INTERFACE )
143- add_library (mio::mio-headers ALIAS mio-headers )
144- target_link_libraries (mio-headers INTERFACE mio )
145-
146- add_subdirectory (include /mio )
147-
148- if (mio.tests)
149- add_subdirectory (test )
150- endif ()
151-
152- if (mio.installation)
153- #
154- # Non-testing header files (preserving relative paths) are installed to the
155- # `include` subdirectory of the `$INSTALL_DIR/${CMAKE_INSTALL_PREFIX}`
156- # directory. Source file permissions preserved.
157- #
158- install (DIRECTORY include/
159- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
160- FILES_MATCHING PATTERN "*.*pp" )
161-
162- #
163- # As a header-only library, there are no target components to be installed
164- # directly (the PUBLIC_HEADER property is not white listed for INTERFACE
165- # targets for some reason).
166- #
167- # However, it is worthwhile export our target description in order to later
168- # generate a CMake configuration file for consumption by CMake's `find_package`
169- # intrinsic
170- #
171- install (TARGETS mio mio-headers EXPORT mioTargets)
172-
173- if (WIN32 )
174- install (TARGETS mio_full_winapi mio_min_winapi EXPORT mioTargets)
29+ # Unicode version: add the UNICODE compile definition.
30+ add_executable (mio.unicode.test ${CMAKE_CURRENT_SOURCE_DIR} /test/test.cpp )
31+ target_link_libraries (mio.unicode.test PRIVATE mio )
32+ target_compile_definitions (mio.unicode.test PRIVATE UNICODE )
33+ if (BUILD_TESTING)
34+ add_test (NAME mio.unicode.test COMMAND mio.unicode.test )
17535 endif ()
17636
177- install (EXPORT mioTargets
178- FILE mio-targets .cmake
179- NAMESPACE mio::
180- DESTINATION share/cmake/mio)
181-
182- write_basic_package_version_file ("mio-config-version.cmake"
183- VERSION ${PROJECT_VERSION}
184- COMPATIBILITY SameMajorVersion )
185-
186- configure_file (
187- "${PROJECT_SOURCE_DIR} /cmake/mio-config.cmake.in"
188- "${PROJECT_BINARY_DIR} /mio-config.cmake"
189- @ONLY )
37+ # Full WinAPI version (adjust additional settings as needed).
38+ add_executable (mio.fullwinapi.test ${CMAKE_CURRENT_SOURCE_DIR} /test/test.cpp )
39+ target_link_libraries (mio.fullwinapi.test PRIVATE mio )
40+ if (BUILD_TESTING)
41+ add_test (NAME mio.fullwinapi.test COMMAND mio.fullwinapi.test )
42+ endif ()
19043
191- install (FILES
192- "${PROJECT_BINARY_DIR} /mio-config-version.cmake"
193- "${PROJECT_BINARY_DIR} /mio-config.cmake"
194- DESTINATION share/cmake/mio)
44+ # Minimal WinAPI version: minimal Windows API configuration.
45+ add_executable (mio.minwinapi.test ${CMAKE_CURRENT_SOURCE_DIR} /test/test.cpp )
46+ target_link_libraries (mio.minwinapi.test PRIVATE mio )
47+ if (BUILD_TESTING)
48+ add_test (NAME mio.minwinapi.test COMMAND mio.minwinapi.test )
49+ endif ()
50+ endif ()
19551
19652 #
19753 # Rudimentary CPack support.
@@ -209,15 +65,14 @@ if(mio.installation)
20965 #
21066 # See `cpack --help` or the CPack documentation for more information.
21167 #
212- if (NOT subproject)
213- set (CPACK_PACKAGE_VENDOR "mandreyel" )
214- set (CPACK_PACKAGE_DESCRIPTION_SUMMARY
215- "Cross-platform C++11 header-only library for memory mapped file IO" )
216- set (CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/mandreyel/mio" )
217- set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR} /LICENSE" )
218- set (CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR} " )
219- set (CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR} " )
220- set (CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH} " )
221- include (CPack )
222- endif ()
68+ if (NOT subproject)
69+ set (CPACK_PACKAGE_VENDOR "mandreyel" )
70+ set (CPACK_PACKAGE_DESCRIPTION_SUMMARY
71+ "Cross-platform C++20 header-only library for memory mapped file IO" )
72+ set (CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/Twilight-Dream-Of-Magic/mio" )
73+ set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR} /LICENSE" )
74+ set (CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR} " )
75+ set (CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR} " )
76+ set (CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH} " )
77+ include (CPack )
22378endif ()
0 commit comments