dcmtk 3.6.7 + vcpkg + cmake

2023-12-30 11:26:36

main.cpp

#include <dcmtk/config/osconfig.h>   // make sure OS specific configuration is included first
#include <dcmtk/dcmdata/dctk.h>

int main() {
    OFString version = OFFIS_DCMTK_VERSION_STRING;
    std::cout << "Using DCMTK version " << version << std::endl;
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.25)

project(core)

set(CMAKE_CXX_STANDARD 23)

set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(Boost_NO_WARN_NEW_VERSIONS 1)
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")


find_package(spdlog REQUIRED)
find_package(asio CONFIG REQUIRED)
find_package(Crow CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(DCMTK CONFIG REQUIRED)
find_package(OpenCV REQUIRED)

find_package(VTK REQUIRED)
include("${VTK_USE_FILE}")
if (NOT VTK_FOUND)
  message(FATAL_ERROR "OffScreenRendering: Unable to find the VTK build folder.")
endif()


file(GLOB SRC_FILES core/src/*.cpp)
file(GLOB SRC_H_FILES core/src/*.h)

add_executable(core ${SRC_FILES} ${SRC_H_FILES})

if ("${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" STREQUAL "/")
    message(WARNING "No vcpkg install dir found, DCMTK definitions are not set")
else()
    target_compile_definitions(core
        PUBLIC
        "DCMTK_PREFIX=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}"
        "DCM_DICT_DEFAULT_PATH=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk/dicom.dic:${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk/private.dic"
        "DEFAULT_CONFIGURATION_DIR=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/etc/dcmtk/"
        "DEFAULT_SUPPORT_DATA_DIR=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk/"
    )
endif()

target_link_libraries(core PRIVATE spdlog::spdlog_header_only asio::asio Crow::Crow nlohmann_json::nlohmann_json DCMTK::DCMTK DCMTK::oflog ${VTK_LIBRARIES} ${OpenCV_LIBS})

vtk_module_autoinit(
  TARGETS core
  MODULES ${VTK_LIBRARIES}
)

vcpkg.json

{
  "dependencies": [
    {
      "name": "spdlog",
      "version>=": "1.12.0"
    },
    {
      "name": "asio",
      "version>=": "1.28.2"
    },
    {
      "name": "crow",
      "version>=": "1.0-5"
    },
    {
      "name": "nlohmann-json",
      "version>=": "3.11.3"
    },
    {
      "name": "dcmtk",
      "version>=": "3.6.7"
    },
    {
      "name": "vtk",
      "version>=": "9.2.0-pv5.11.0#10"
    },
    {
      "name": "opencv",
      "version>=": "4.8.0"
    }
  ],
  "builtin-baseline": "9fd83fa98b5f2ae6188a6ba59a49837061db0a3a"
}

单独的CMakeLists.txt (用vcpkg可以不用)

cmake_minimum_required(VERSION 3.5)
project(MyDCMTKProject)

# Setup the toolchain file from vcpkg

#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find package
find_package(DCMTK CONFIG REQUIRED)


add_executable(main main.cpp)

    if ("${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" STREQUAL "/")
        message(WARNING "No vcpkg install dir found, DCMTK definitions are not set")
    else()
        target_compile_definitions(main
            PUBLIC
                "DCMTK_PREFIX=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}"
                "DCM_DICT_DEFAULT_PATH=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk/dicom.dic:${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk/private.dic"
                "DEFAULT_CONFIGURATION_DIR=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/etc/dcmtk/"
                "DEFAULT_SUPPORT_DATA_DIR=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk/"
        )
    endif()

target_link_libraries(main PRIVATE DCMTK::DCMTK DCMTK::oflog)
target_include_directories(main PRIVATE ${DCMTK_INCLUDE_DIRS})

文章来源:https://blog.csdn.net/Ericohe/article/details/135303044
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。