From 693fb9f2dd7ac5b0a74492359e176f749a9d735b Mon Sep 17 00:00:00 2001 From: Lukas Senionis Date: Fri, 19 Jul 2024 00:58:17 +0300 Subject: [PATCH] Update CMake and CI configs (#66) --- .codeql-prebuild-cpp-Linux.sh | 3 ++- .codeql-prebuild-cpp-Windows.sh | 4 ++- .codeql-prebuild-cpp-macOS.sh | 4 ++- .github/workflows/ci.yml | 9 +++++-- .gitmodules | 4 --- README.rst | 4 ++- cmake/Boost_DD.cmake | 2 +- cmake/Json_DD.cmake | 12 +++++++-- src/CMakeLists.txt | 15 ++++++++--- src/common/CMakeLists.txt | 4 ++- src/display_device/CMakeLists.txt | 15 ----------- .../include/display_device/libddplaceholder.h | 0 src/display_device/libddplaceholder.cpp | 6 ----- src/platf/CMakeLists.txt | 26 ------------------- .../display_device/libplatfplaceholder.h | 0 src/platf/libplatfplaceholder.cpp | 6 ----- src/windows/CMakeLists.txt | 6 +++-- tests/CMakeLists.txt | 2 +- tests/fixtures/CMakeLists.txt | 2 +- tests/unit/windows/CMakeLists.txt | 1 - third-party/json | 1 - 21 files changed, 49 insertions(+), 77 deletions(-) delete mode 100644 src/display_device/CMakeLists.txt delete mode 100644 src/display_device/include/display_device/libddplaceholder.h delete mode 100644 src/display_device/libddplaceholder.cpp delete mode 100644 src/platf/CMakeLists.txt delete mode 100644 src/platf/include/display_device/libplatfplaceholder.h delete mode 100644 src/platf/libplatfplaceholder.cpp delete mode 160000 third-party/json diff --git a/.codeql-prebuild-cpp-Linux.sh b/.codeql-prebuild-cpp-Linux.sh index 56fb8f3..81c69e5 100644 --- a/.codeql-prebuild-cpp-Linux.sh +++ b/.codeql-prebuild-cpp-Linux.sh @@ -11,7 +11,8 @@ sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y sudo apt-get install -y \ build-essential \ cmake \ - ninja-build + ninja-build \ + nlohmann-json3-dev # clean apt cache sudo apt-get clean diff --git a/.codeql-prebuild-cpp-Windows.sh b/.codeql-prebuild-cpp-Windows.sh index d32da0b..7111efc 100644 --- a/.codeql-prebuild-cpp-Windows.sh +++ b/.codeql-prebuild-cpp-Windows.sh @@ -9,7 +9,9 @@ pacman --noconfirm -S \ mingw-w64-ucrt-x86_64-binutils \ mingw-w64-ucrt-x86_64-cmake \ mingw-w64-ucrt-x86_64-ninja \ - mingw-w64-ucrt-x86_64-toolchain + mingw-w64-ucrt-x86_64-toolchain \ + mingw-w64-ucrt-x86_64-boost \ + mingw-w64-ucrt-x86_64-nlohmann-json # build mkdir -p build diff --git a/.codeql-prebuild-cpp-macOS.sh b/.codeql-prebuild-cpp-macOS.sh index 0f1aeeb..4cee39a 100644 --- a/.codeql-prebuild-cpp-macOS.sh +++ b/.codeql-prebuild-cpp-macOS.sh @@ -4,7 +4,9 @@ set -e # install dependencies brew install \ cmake \ - ninja + ninja \ + boost \ + nlohmann-json # build mkdir -p build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ad45af..07bac8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,14 +42,17 @@ jobs: sudo apt-get install -y \ build-essential \ cmake \ - ninja-build + ninja-build \ + nlohmann-json3-dev - name: Setup Dependencies macOS if: runner.os == 'macOS' run: | brew install \ cmake \ - ninja + ninja \ + boost \ + nlohmann-json - name: Setup Dependencies Windows if: runner.os == 'Windows' @@ -62,6 +65,8 @@ jobs: mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-ninja mingw-w64-ucrt-x86_64-toolchain + mingw-w64-ucrt-x86_64-boost + mingw-w64-ucrt-x86_64-nlohmann-json - name: Prepare tests id: prepare-tests diff --git a/.gitmodules b/.gitmodules index 79ca3b6..6cbf29c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,7 +2,3 @@ path = third-party/googletest url = https://github.com/google/googletest.git branch = v1.14.x -[submodule "third-party/json"] - path = third-party/json - url = https://github.com/nlohmann/json.git - branch = master diff --git a/README.rst b/README.rst index 1ee209c..44461f9 100644 --- a/README.rst +++ b/README.rst @@ -55,7 +55,9 @@ Install dependencies: mingw-w64-ucrt-x86_64-binutils \ mingw-w64-ucrt-x86_64-cmake \ mingw-w64-ucrt-x86_64-ninja \ - mingw-w64-ucrt-x86_64-toolchain + mingw-w64-ucrt-x86_64-toolchain \ + mingw-w64-ucrt-x86_64-boost \ + mingw-w64-ucrt-x86_64-nlohmann-json Build ~~~~~ diff --git a/cmake/Boost_DD.cmake b/cmake/Boost_DD.cmake index 391cd30..b476665 100644 --- a/cmake/Boost_DD.cmake +++ b/cmake/Boost_DD.cmake @@ -12,7 +12,7 @@ set(REQUIRED_HEADER_LIBRARIES uuid ) -find_package(Boost 1.85 QUIET GLOBAL) +find_package(Boost 1.85 CONFIG QUIET GLOBAL) if(NOT Boost_FOUND) message(STATUS "Boost v1.85.x package not found in the system. Falling back to FetchContent.") include(FetchContent) diff --git a/cmake/Json_DD.cmake b/cmake/Json_DD.cmake index a916143..7f3a792 100644 --- a/cmake/Json_DD.cmake +++ b/cmake/Json_DD.cmake @@ -6,6 +6,14 @@ include_guard(GLOBAL) find_package(nlohmann_json 3.11 QUIET GLOBAL) if(NOT nlohmann_json_FOUND) - message(STATUS "nlohmann_json v3.11.x package not found in the system. Falling back to submodule.") - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third-party/json third-party/json) + message(STATUS "nlohmann_json v3.11.x package not found in the system. Falling back to FetchContent.") + include(FetchContent) + + FetchContent_Declare( + json + URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz + URL_HASH MD5=c23a33f04786d85c29fda8d16b5f0efd + DOWNLOAD_EXTRACT_TIMESTAMP + ) + FetchContent_MakeAvailable(json) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index af33d9a..d81ae71 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,15 +5,22 @@ add_subdirectory(common) if(WIN32) add_subdirectory(windows) elseif(APPLE) + add_library(libdisplaydevice_macos_dummy INTERFACE) + add_library(libdisplaydevice::platform ALIAS libdisplaydevice_macos_dummy) message(WARNING "MacOS is not supported yet.") elseif(UNIX) + add_library(libdisplaydevice_linux_dummy INTERFACE) + add_library(libdisplaydevice::platform ALIAS libdisplaydevice_linux_dummy) message(WARNING "Linux is not supported yet.") else() message(FATAL_ERROR "Unsupported platform") endif() -# This is a platform-specific library that loads the correct library for the OS -add_subdirectory(platf) +# Create a target that links to everything +add_library(libdisplaydevice_display_device INTERFACE) +target_link_libraries(libdisplaydevice_display_device INTERFACE + libdisplaydevice::common + libdisplaydevice::platform) -# This is the main library -add_subdirectory(display_device) +# Create an alias for the main target +add_library(libdisplaydevice::display_device ALIAS libdisplaydevice_display_device) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 9177bbb..c8aa9c7 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,5 +1,6 @@ # A global identifier for the library -set(MODULE libcommon) +set(MODULE libdisplaydevice_common) +set(MODULE_ALIAS libdisplaydevice::common) # Globing headers (so that they appear in some IDEs) and sources file(GLOB HEADER_LIST CONFIGURE_DEPENDS "include/display_device/*.h") @@ -8,6 +9,7 @@ file(GLOB SOURCE_LIST CONFIGURE_DEPENDS "*.cpp") # Automatic library - will be static or dynamic based on user setting add_library(${MODULE} ${HEADER_LIST} ${HEADER_DETAIL_LIST} ${SOURCE_LIST}) +add_library(${MODULE_ALIAS} ALIAS ${MODULE}) # Provide the includes together with this library target_include_directories(${MODULE} PUBLIC include) diff --git a/src/display_device/CMakeLists.txt b/src/display_device/CMakeLists.txt deleted file mode 100644 index 3ae6b4b..0000000 --- a/src/display_device/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# A global identifier for the library -set(MODULE libdisplaydevice) - -# Globing headers (so that they appear in some IDEs) and sources -file(GLOB HEADER_LIST CONFIGURE_DEPENDS "include/display_device/*.h") -file(GLOB SOURCE_LIST CONFIGURE_DEPENDS "*.cpp") - -# Automatic library - will be static or dynamic based on user setting -add_library(${MODULE} ${HEADER_LIST} ${SOURCE_LIST}) - -# Provide the includes together with this library -target_include_directories(${MODULE} PUBLIC include) - -# Required libraries -target_link_libraries(${MODULE} PUBLIC libcommon PRIVATE libplatf) diff --git a/src/display_device/include/display_device/libddplaceholder.h b/src/display_device/include/display_device/libddplaceholder.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/display_device/libddplaceholder.cpp b/src/display_device/libddplaceholder.cpp deleted file mode 100644 index b85491c..0000000 --- a/src/display_device/libddplaceholder.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "display_device/libddplaceholder.h" - -int -ddplaceholder() { - return 0; -} diff --git a/src/platf/CMakeLists.txt b/src/platf/CMakeLists.txt deleted file mode 100644 index 892064e..0000000 --- a/src/platf/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# A global identifier for the library -set(MODULE libplatf) - -# Globing headers (so that they appear in some IDEs) and sources -file(GLOB HEADER_LIST CONFIGURE_DEPENDS "include/display_device/*.h") -file(GLOB SOURCE_LIST CONFIGURE_DEPENDS "*.cpp") - -# Automatic library - will be static or dynamic based on user setting -add_library(${MODULE} ${HEADER_LIST} ${SOURCE_LIST}) - -# Provide the includes together with this library -target_include_directories(${MODULE} PUBLIC include) - -# Shared libraries between platforms -target_link_libraries(${MODULE} PRIVATE libcommon) - -# Link the platform specific library privately -if(WIN32) - target_link_libraries(${MODULE} PRIVATE libwindows) -elseif(APPLE) - message(WARNING "MacOS is not supported yet.") -elseif(UNIX) - message(WARNING "Linux is not supported yet.") -else() - message(FATAL_ERROR "Unsupported platform") -endif() diff --git a/src/platf/include/display_device/libplatfplaceholder.h b/src/platf/include/display_device/libplatfplaceholder.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/platf/libplatfplaceholder.cpp b/src/platf/libplatfplaceholder.cpp deleted file mode 100644 index 0e70e5d..0000000 --- a/src/platf/libplatfplaceholder.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "display_device/libplatfplaceholder.h" - -int -plaftplaceholder() { - return 0; -} diff --git a/src/windows/CMakeLists.txt b/src/windows/CMakeLists.txt index b483f6d..f6bca34 100644 --- a/src/windows/CMakeLists.txt +++ b/src/windows/CMakeLists.txt @@ -1,5 +1,6 @@ # A global identifier for the library -set(MODULE libwindows) +set(MODULE libdisplaydevice_windows) +set(MODULE_ALIAS libdisplaydevice::platform) # Globing headers (so that they appear in some IDEs) and sources file(GLOB HEADER_LIST CONFIGURE_DEPENDS "include/display_device/windows/*.h") @@ -8,6 +9,7 @@ file(GLOB SOURCE_LIST CONFIGURE_DEPENDS "*.cpp") # Automatic library - will be static or dynamic based on user setting add_library(${MODULE} ${HEADER_LIST} ${HEADER_DETAIL_LIST} ${SOURCE_LIST}) +add_library(${MODULE_ALIAS} ALIAS ${MODULE}) # Provide the includes together with this library target_include_directories(${MODULE} PUBLIC include) @@ -27,6 +29,6 @@ target_link_libraries(${MODULE} PRIVATE Boost::algorithm Boost::scope Boost::uuid - libcommon + libdisplaydevice::common nlohmann_json::nlohmann_json setupapi) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f6d631c..7d2f552 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -57,7 +57,7 @@ add_executable(${TEST_BINARY} ${sources}) target_link_libraries(${TEST_BINARY} PUBLIC gmock_main # if we use this we don't need our own main function - libdisplaydevice # we are always testing at least the public API so it's safe to always link this + libdisplaydevice::display_device # this target includes common + platform specific targets libfixtures # these are our fixtures/helpers for the tests ${libraries} # additional libraries if needed ) diff --git a/tests/fixtures/CMakeLists.txt b/tests/fixtures/CMakeLists.txt index 10df4dc..7ee2c99 100644 --- a/tests/fixtures/CMakeLists.txt +++ b/tests/fixtures/CMakeLists.txt @@ -21,5 +21,5 @@ target_link_libraries(${MODULE} PRIVATE gtest - libcommon + libdisplaydevice::common ) diff --git a/tests/unit/windows/CMakeLists.txt b/tests/unit/windows/CMakeLists.txt index 7bc84aa..c17447c 100644 --- a/tests/unit/windows/CMakeLists.txt +++ b/tests/unit/windows/CMakeLists.txt @@ -2,7 +2,6 @@ add_dd_test_dir( ADDITIONAL_LIBRARIES Boost::scope - libwindows ADDITIONAL_SOURCES utils/*.h diff --git a/third-party/json b/third-party/json deleted file mode 160000 index 9cca280..0000000 --- a/third-party/json +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03