mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 02:17:16 +02:00
build: mp-units-contracts
CMakeTarget added to reuse contract definition in different separate targets
Refers to #581
This commit is contained in:
@ -28,32 +28,12 @@ if(${projectPrefix}BUILD_CXX_MODULES)
|
||||
target_compile_features(example_utils INTERFACE cxx_std_20)
|
||||
target_compile_definitions(example_utils INTERFACE ${projectPrefix}MODULES)
|
||||
target_include_directories(example_utils INTERFACE include)
|
||||
target_link_libraries(example_utils INTERFACE mp-units-contracts)
|
||||
endif()
|
||||
|
||||
add_library(example_utils-headers INTERFACE)
|
||||
target_include_directories(example_utils-headers INTERFACE include)
|
||||
|
||||
if(${projectPrefix}API_CONTRACTS STREQUAL "NONE")
|
||||
target_compile_definitions(mp-units-core INTERFACE ${projectPrefix}API_CONTRACTS=0)
|
||||
elseif(${projectPrefix}API_CONTRACTS STREQUAL "GSL-LITE")
|
||||
if(NOT TARGET gsl::gsl-lite)
|
||||
find_package(gsl-lite REQUIRED)
|
||||
endif()
|
||||
if(${projectPrefix}BUILD_CXX_MODULES)
|
||||
target_link_libraries(example_utils INTERFACE gsl::gsl-lite)
|
||||
endif()
|
||||
target_link_libraries(example_utils-headers INTERFACE gsl::gsl-lite)
|
||||
target_compile_definitions(mp-units-core INTERFACE ${projectPrefix}API_CONTRACTS=2)
|
||||
elseif(${projectPrefix}API_CONTRACTS STREQUAL "MS-GSL")
|
||||
if(NOT TARGET Microsoft.GSL::GSL)
|
||||
find_package(Microsoft.GSL REQUIRED)
|
||||
endif()
|
||||
if(${projectPrefix}BUILD_CXX_MODULES)
|
||||
target_link_libraries(example_utils INTERFACE Microsoft.GSL::GSL)
|
||||
endif()
|
||||
target_link_libraries(example_utils-headers INTERFACE Microsoft.GSL::GSL)
|
||||
target_compile_definitions(mp-units-core INTERFACE ${projectPrefix}API_CONTRACTS=3)
|
||||
endif()
|
||||
target_link_libraries(example_utils-headers INTERFACE mp-units-contracts)
|
||||
|
||||
#
|
||||
# add_example(target <depependencies>...)
|
||||
|
@ -114,6 +114,7 @@ else()
|
||||
endif()
|
||||
|
||||
# components/modules
|
||||
include(MPUnitsContracts)
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(systems)
|
||||
|
||||
|
41
src/cmake/MPUnitsContracts.cmake
Normal file
41
src/cmake/MPUnitsContracts.cmake
Normal file
@ -0,0 +1,41 @@
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2018 Mateusz Pusz
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
add_library(mp-units-contracts INTERFACE)
|
||||
|
||||
if(${projectPrefix}API_CONTRACTS STREQUAL "NONE")
|
||||
target_compile_definitions(mp-units-contracts INTERFACE ${projectPrefix}API_CONTRACTS=0)
|
||||
elseif(${projectPrefix}API_CONTRACTS STREQUAL "GSL-LITE")
|
||||
if(NOT TARGET gsl::gsl-lite)
|
||||
find_package(gsl-lite REQUIRED)
|
||||
endif()
|
||||
target_link_libraries(mp-units-contracts INTERFACE gsl::gsl-lite)
|
||||
target_compile_definitions(mp-units-contracts INTERFACE ${projectPrefix}API_CONTRACTS=2)
|
||||
elseif(${projectPrefix}API_CONTRACTS STREQUAL "MS-GSL")
|
||||
if(NOT TARGET Microsoft.GSL::GSL)
|
||||
find_package(Microsoft.GSL REQUIRED)
|
||||
endif()
|
||||
target_link_libraries(mp-units-contracts INTERFACE Microsoft.GSL::GSL)
|
||||
target_compile_definitions(mp-units-contracts INTERFACE ${projectPrefix}API_CONTRACTS=3)
|
||||
endif()
|
||||
|
||||
install(TARGETS mp-units-contracts EXPORT mp-unitsTargets)
|
@ -108,21 +108,7 @@ if(NOT ${projectPrefix}API_FREESTANDING
|
||||
endif()
|
||||
|
||||
# Contracts checking
|
||||
if(${projectPrefix}API_CONTRACTS STREQUAL "NONE")
|
||||
target_compile_definitions(mp-units-core ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}API_CONTRACTS=0)
|
||||
elseif(${projectPrefix}API_CONTRACTS STREQUAL "GSL-LITE")
|
||||
if(NOT TARGET gsl::gsl-lite)
|
||||
find_package(gsl-lite REQUIRED)
|
||||
endif()
|
||||
target_link_libraries(mp-units-core ${${projectPrefix}TARGET_SCOPE} gsl::gsl-lite)
|
||||
target_compile_definitions(mp-units-core ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}API_CONTRACTS=2)
|
||||
elseif(${projectPrefix}API_CONTRACTS STREQUAL "MS-GSL")
|
||||
if(NOT TARGET Microsoft.GSL::GSL)
|
||||
find_package(Microsoft.GSL REQUIRED)
|
||||
endif()
|
||||
target_link_libraries(mp-units-core ${${projectPrefix}TARGET_SCOPE} Microsoft.GSL::GSL)
|
||||
target_compile_definitions(mp-units-core ${${projectPrefix}TARGET_SCOPE} ${projectPrefix}API_CONTRACTS=3)
|
||||
endif()
|
||||
target_link_libraries(mp-units-core ${${projectPrefix}TARGET_SCOPE} mp-units-contracts)
|
||||
|
||||
# C++20 modules
|
||||
if(${projectPrefix}BUILD_CXX_MODULES)
|
||||
|
Reference in New Issue
Block a user