From 965d56553d000f94fdfea47f14a3cb71d5535b6f Mon Sep 17 00:00:00 2001 From: ihedvall <92839244+ihedvall@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:20:45 +0100 Subject: [PATCH] Prepare for report server build. Simplify boost version change. Always build google test. --- .github/workflows/cmake_linux.yml | 2 +- .github/workflows/cmake_macos.yml | 2 +- .github/workflows/cmake_windows.yml | 2 +- .idea/.gitignore | 8 ---- .idea/.idea.mdflib.dir/.idea/.gitignore | 13 ------ .idea/.idea.mdflib.dir/.idea/encodings.xml | 4 -- .idea/.idea.mdflib.dir/.idea/indexLayout.xml | 8 ---- .idea/.idea.mdflib.dir/.idea/vcs.xml | 6 --- .idea/.idea.mdflib/.idea/.gitignore | 13 ------ .idea/.idea.mdflib/.idea/encodings.xml | 4 -- .idea/.idea.mdflib/.idea/indexLayout.xml | 8 ---- .idea/.idea.mdflib/.idea/vcs.xml | 6 --- CMakeLists.txt | 10 ++-- include/mdf/mdfreader.h | 2 +- mdflib/CMakeLists.txt | 5 +- mdflib/src/mdfreader.cpp | 2 +- mdflib_test/CMakeLists.txt | 1 - script/boost.cmake | 2 +- script/googletest.cmake | 25 +++++----- vcpkg.json | 49 ++++++++++---------- 20 files changed, 54 insertions(+), 118 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/.idea.mdflib.dir/.idea/.gitignore delete mode 100644 .idea/.idea.mdflib.dir/.idea/encodings.xml delete mode 100644 .idea/.idea.mdflib.dir/.idea/indexLayout.xml delete mode 100644 .idea/.idea.mdflib.dir/.idea/vcs.xml delete mode 100644 .idea/.idea.mdflib/.idea/.gitignore delete mode 100644 .idea/.idea.mdflib/.idea/encodings.xml delete mode 100644 .idea/.idea.mdflib/.idea/indexLayout.xml delete mode 100644 .idea/.idea.mdflib/.idea/vcs.xml diff --git a/.github/workflows/cmake_linux.yml b/.github/workflows/cmake_linux.yml index 2a7c1ea2..fca4a389 100644 --- a/.github/workflows/cmake_linux.yml +++ b/.github/workflows/cmake_linux.yml @@ -21,7 +21,7 @@ jobs: - name: CMAKE Configure run: > cmake -B ${{github.workspace}}/build - -D MDF_BUILD_TOOL=OFF -D MDF_BUILD_TEST=ON -D MDF_BUILD_SHARED_LIB=OFF + -D MDF_BUILD_TOOL=OFF -D MDF_BUILD_TEST=ON -D MDF_BUILD_SHARED_LIB=ON -D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -D CMAKE_TOOLCHAIN_FILE=${{env.VCPKG_FILE}} diff --git a/.github/workflows/cmake_macos.yml b/.github/workflows/cmake_macos.yml index 368ce28d..0ed55952 100644 --- a/.github/workflows/cmake_macos.yml +++ b/.github/workflows/cmake_macos.yml @@ -21,7 +21,7 @@ jobs: - name: CMAKE Configure run: > cmake -B ${{github.workspace}}/build - -D MDF_BUILD_TOOL=OFF -D MDF_BUILD_TEST=OFF -D MDF_BUILD_SHARED_LIB=OFF + -D MDF_BUILD_TOOL=OFF -D MDF_BUILD_TEST=OFF -D MDF_BUILD_SHARED_LIB=ON -D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -D CMAKE_TOOLCHAIN_FILE=${{env.VCPKG_FILE}} diff --git a/.github/workflows/cmake_windows.yml b/.github/workflows/cmake_windows.yml index ed858ae5..c8f12f25 100644 --- a/.github/workflows/cmake_windows.yml +++ b/.github/workflows/cmake_windows.yml @@ -22,7 +22,7 @@ jobs: - name: CMAKE Configure run: > cmake -B ${{github.workspace}}/build - -D MDF_BUILD_TOOL=ON -D MDF_BUILD_TEST=ON -D MDF_BUILD_SHARED_LIB=OFF + -D MDF_BUILD_TOOL=ON -D MDF_BUILD_TEST=ON -D MDF_BUILD_SHARED_LIB=ON -D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -D CMAKE_TOOLCHAIN_FILE=${{env.VCPKG_FILE}} diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.idea.mdflib.dir/.idea/.gitignore b/.idea/.idea.mdflib.dir/.idea/.gitignore deleted file mode 100644 index c41c4f2d..00000000 --- a/.idea/.idea.mdflib.dir/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/projectSettingsUpdater.xml -/modules.xml -/.idea.mdflib.iml -/contentModel.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.idea.mdflib.dir/.idea/encodings.xml b/.idea/.idea.mdflib.dir/.idea/encodings.xml deleted file mode 100644 index df87cf95..00000000 --- a/.idea/.idea.mdflib.dir/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.mdflib.dir/.idea/indexLayout.xml b/.idea/.idea.mdflib.dir/.idea/indexLayout.xml deleted file mode 100644 index 7b08163c..00000000 --- a/.idea/.idea.mdflib.dir/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.mdflib.dir/.idea/vcs.xml b/.idea/.idea.mdflib.dir/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/.idea.mdflib.dir/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/.idea.mdflib/.idea/.gitignore b/.idea/.idea.mdflib/.idea/.gitignore deleted file mode 100644 index 2d312e30..00000000 --- a/.idea/.idea.mdflib/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/modules.xml -/projectSettingsUpdater.xml -/.idea.mdflib.iml -/contentModel.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.idea.mdflib/.idea/encodings.xml b/.idea/.idea.mdflib/.idea/encodings.xml deleted file mode 100644 index df87cf95..00000000 --- a/.idea/.idea.mdflib/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.mdflib/.idea/indexLayout.xml b/.idea/.idea.mdflib/.idea/indexLayout.xml deleted file mode 100644 index 7b08163c..00000000 --- a/.idea/.idea.mdflib/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.mdflib/.idea/vcs.xml b/.idea/.idea.mdflib/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/.idea.mdflib/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c15ec14..70b93de6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,17 +8,21 @@ else() set(VCPKG ON) endif() +option(BUILD_SHARED_LIBS "Build static library as default." OFF) option(MDF_BUILD_SHARED_LIB "Build shared library." ON) option(MDF_BUILD_SHARED_LIB_NET "Build shared library with .NET." OFF) # Only for MSVC 19.36+ -option(MDF_BUILD_SHARED_LIB_EXAMPLE "Build MdfLibrary Example." OFF) +option(MDF_BUILD_SHARED_LIB_NET "Build shared library with .NET." OFF) +option(MDF_BUILD_SHARED_LIB_EXAMPLE "Build shared library example." OFF) option(MDF_BUILD_DOC "Build documentation. Requires Doxygen and Release mode." OFF) option(MDF_BUILD_TOOL "Build tools like the MDF Viewer. Requires WxWidgets." OFF) +option(MDF_BUILD_TEST "Build Google Unit Tests. Requires Google Test." OFF) + if(MDF_BUILD_TOOL AND VCPKG) # Boost & wxWidgets need /MT for static linking # string(REPLACE "-static" "" VCPKG_TARGET_TRIPLET "${VCPKG_TARGET_TRIPLET}") list(APPEND VCPKG_MANIFEST_FEATURES "mdfviewer") endif() -option(MDF_BUILD_TEST "Build Google unit tests. Requires Google Test." OFF) + if(MDF_BUILD_TEST AND VCPKG) # GTest need /MT for static linking # string(REPLACE "-static" "" VCPKG_TARGET_TRIPLET "${VCPKG_TARGET_TRIPLET}") @@ -27,7 +31,7 @@ endif() project( mdflib - VERSION 2.0 + VERSION 2.1 DESCRIPTION "Interface against MDF 3/4 files" LANGUAGES CXX) diff --git a/include/mdf/mdfreader.h b/include/mdf/mdfreader.h index 41743274..b314d191 100644 --- a/include/mdf/mdfreader.h +++ b/include/mdf/mdfreader.h @@ -91,7 +91,7 @@ class MdfReader { /** \brief Returns the header (HD) block. */ [[nodiscard]] const IHeader* GetHeader() const; /** \brief Returns the data group (DG) block. */ - [[nodiscard]] const IDataGroup* GetDataGroup(size_t order) const; + [[nodiscard]] IDataGroup* GetDataGroup(size_t order) const; [[nodiscard]] std::string ShortName() const; ///< Returns the file name without paths. diff --git a/mdflib/CMakeLists.txt b/mdflib/CMakeLists.txt index 399826dc..52acac88 100644 --- a/mdflib/CMakeLists.txt +++ b/mdflib/CMakeLists.txt @@ -3,8 +3,9 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_DEBUG_POSTFIX d) +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -add_library(mdf STATIC +add_library(mdf src/mdfblock.cpp src/mdfblock.h src/mdffile.cpp ../include/mdf/mdffile.h src/idblock.cpp src/idblock.h @@ -148,6 +149,8 @@ set_target_properties(mdf PROPERTIES PUBLIC_HEADER "${MDF_PUBLIC_HEADERS}") get_target_property(PH1 mdf PUBLIC_HEADER) message(STATUS "MDF Target Includes: " "${PH1}") + + if(WIN32) install( TARGETS mdf diff --git a/mdflib/src/mdfreader.cpp b/mdflib/src/mdfreader.cpp index 48d45911..bc460c73 100644 --- a/mdflib/src/mdfreader.cpp +++ b/mdflib/src/mdfreader.cpp @@ -441,7 +441,7 @@ const IHeader *MdfReader::GetHeader() const { return file != nullptr ? file->Header() : nullptr; } -const IDataGroup *MdfReader::GetDataGroup(size_t order) const { +IDataGroup *MdfReader::GetDataGroup(size_t order) const { const auto *file = GetFile(); if (file != nullptr) { DataGroupList dg_list; diff --git a/mdflib_test/CMakeLists.txt b/mdflib_test/CMakeLists.txt index 2dab24a2..ffd193a1 100644 --- a/mdflib_test/CMakeLists.txt +++ b/mdflib_test/CMakeLists.txt @@ -45,7 +45,6 @@ else() target_link_libraries(test_mdf PRIVATE ${Boost_LIBRARIES}) include("../script/googletest.cmake") - target_include_directories(test_mdf PRIVATE ${GTEST_INCLUDE_DIRS}) target_link_libraries(test_mdf PRIVATE GTest::gtest GTest::gtest_main) endif() diff --git a/script/boost.cmake b/script/boost.cmake index cdc2dae9..29b2ca0f 100644 --- a/script/boost.cmake +++ b/script/boost.cmake @@ -9,7 +9,7 @@ if (NOT Boost_FOUND) set(Boost_DEBUG OFF) if (COMP_DIR) - set(Boost_ROOT ${COMP_DIR}/boost/boost_1_80_0) + set(Boost_ROOT ${COMP_DIR}/boost/latest) endif() find_package(Boost REQUIRED COMPONENTS filesystem system locale program_options) diff --git a/script/googletest.cmake b/script/googletest.cmake index a7ef322f..d1655def 100644 --- a/script/googletest.cmake +++ b/script/googletest.cmake @@ -1,17 +1,16 @@ # Copyright 2021 Ingemar Hedvall # SPDX-License-Identifier: MIT -if (NOT GTest_FOUND) - set(GTEST_MSVC_SEARCH MT) - if (COMP_DIR) - # Ignore the error message that GTest_ROOT should be used. It has to be capital letters - set(GTEST_ROOT ${COMP_DIR}/googletest/master) - endif() +include (FetchContent) - find_package(GTest) - message(STATUS "GTest Found: " ${GTest_FOUND}) - message(STATUS "GTest Include Dirs: " ${GTEST_INCLUDE_DIRS}) - message(STATUS "GTest Libraries: " ${GTEST_LIBRARIES}) - message(STATUS "GTest Main Libraries: " ${GTEST_MAIN_LIBRARIES}) - message(STATUS "GTest Both Libraries: " ${GTEST_BOTH_LIBRARIES}) -endif() +include(FetchContent) +FetchContent_Declare(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG HEAD +) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) +message(STATUS "googletest Populated: " ${googletest_POPULATED}) +message(STATUS "googletest Source: " ${googletest_SOURCE_DIR}) +message(STATUS "googletest Binary: " ${googletest_BINARY_DIR}) diff --git a/vcpkg.json b/vcpkg.json index 401c96ce..0a38cf65 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,26 +1,27 @@ { - "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", - "name": "mdflib", - "version": "2.1", - "dependencies": [ - "zlib", - "expat" - ], - "features": { - "mdfviewer": { - "description": "Build mdf viewer", - "dependencies": [ - "boost-process", - "boost-locale", - "wxwidgets" - ] - }, - "mdflibtest": { - "description": "Build mdf tests", - "dependencies": [ - "boost-endian", - "gtest" - ] - } + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "mdflib", + "version": "2.1", + "dependencies": [ + "zlib", + "expat" + ], + "features": { + "mdfviewer": { + "description": "Build mdf viewer", + "dependencies": [ + "boost-process", + "boost-locale", + "wxwidgets" + ] + }, + "mdflibtest": { + "description": "Build mdf tests", + "dependencies": [ + "boost-endian", + "gtest" + ] } -} \ No newline at end of file + }, + "builtin-baseline": "2b681d95e08447fde261b4404fbeab324f7d1e5b" +}