mirror of
https://github.com/fraillt/bitsery.git
synced 2026-06-08 08:13:56 +00:00
63 lines
2.8 KiB
CMake
63 lines
2.8 KiB
CMake
#MIT License
|
|
#
|
|
#Copyright (c) 2017 Mindaugas Vinkelis
|
|
#
|
|
#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.
|
|
|
|
cmake_minimum_required(VERSION 3.10)
|
|
project(bitsery_tests CXX)
|
|
|
|
find_package(GTest 1.8 REQUIRED)
|
|
|
|
if (NOT TARGET Bitsery::bitsery)
|
|
message(FATAL_ERROR "Bitsery::bitsery alias not set. Please generate CMake from bitsery root directory.")
|
|
endif()
|
|
|
|
file(GLOB TestSourceFiles ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
|
|
|
enable_testing()
|
|
|
|
foreach (TestFile ${TestSourceFiles})
|
|
get_filename_component(TestName ${TestFile} NAME_WE)
|
|
set(TestName bitsery.test.${TestName})
|
|
add_executable(${TestName} ${TestFile})
|
|
target_link_libraries(${TestName} PRIVATE GTest::Main Bitsery::bitsery)
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|
target_compile_options(${TestName} PRIVATE -Wextra -Wno-missing-braces -Wpedantic -Weffc++ -Wno-c++14-extensions)
|
|
endif()
|
|
gtest_discover_tests(${TestName})
|
|
|
|
# add_test(NAME ${TestName} COMMAND $<TARGET_FILE:${TestName}>)
|
|
endforeach()
|
|
|
|
#======================= setup development environment ====================
|
|
|
|
# get all header files for IDE (in my case Clion) and create dummy project that consumes theses files
|
|
get_directory_property(ParentDir PARENT_DIRECTORY)
|
|
if (ParentDir)
|
|
# only include when working from root project (Bitsery)
|
|
file(GLOB_RECURSE HeadersForIDE ${ParentDir}/include/bitsery/*.h)
|
|
# create dummy target IDE
|
|
file(WRITE ${CMAKE_BINARY_DIR}/dummy_for_ide.cpp "//generated by CMake to create dummy target with all includes for IDE.")
|
|
add_library(bitsery.dummy_for_ide ${CMAKE_BINARY_DIR}/dummy_for_ide.cpp)
|
|
# add headers so IDE correctly show them
|
|
target_sources(bitsery.dummy_for_ide PRIVATE ${HeadersForIDE} serialization_test_utils.h)
|
|
target_link_libraries(bitsery.dummy_for_ide PRIVATE GTest::Main Bitsery::bitsery)
|
|
endif()
|