![Question :?:](./images/smilies/icon_question.gif)
![Exclamation :!:](./images/smilies/icon_exclaim.gif)
- Create DCMTK project files with CMake (for demonstration purposes switch all external libraries off).
- Open the main project file "dcmtk.dsw" or "dcmtk.sln" in Visual Studio.
- Select target ALL_BUILD and compile the complete DCMTK.
- Select target INSTALL in order to install the DCMTK files to the directory specified using CMake.
- Create a new directory "testapp" somewhere on your harddisk with the following files.
Code: Select all
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
int main()
{
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile("test.dcm");
if (status.good())
{
OFString patientName;
if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
{
cout << "Patient's Name: " << patientName << endl;
} else
cerr << "Error: cannot access Patient's Name!" << endl;
} else
cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
return 0;
}
Code: Select all
PROJECT(testapp)
# Minimum CMake version required
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
SET(DCMTK_DIR /Programme/DCMTK_20100916_PUBLIC_NOLIB_MTd)
# Declare project
PROJECT(testapp)
#-----------------------------------------------------------------------------
# Platform-specific settings
#-----------------------------------------------------------------------------
# set project wide flags for compiler and linker
# settings for Microsoft Visual C
IF(CMAKE_C_COMPILER MATCHES "CL|cl")
IF(NOT WITH_SHARED_LIBS)
IF(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_C_FLAGS_MINSIZEREL "/MT /O2")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
IF(CMAKE_GENERATOR STREQUAL "Visual Studio 7" OR CMAKE_GENERATOR STREQUAL "Visual Studio 7 .NET 2003")
SET(CMAKE_C_FLAGS "/nologo /W3 /Gy")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_C_FLAGS_MINSIZEREL "/MT /O2")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 7" OR CMAKE_GENERATOR STREQUAL "Visual Studio 7 .NET 2003")
IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10")
SET(CMAKE_C_FLAGS "/nologo /W3 /Gy /EHsc")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_C_FLAGS_MINSIZEREL "/MT /O2")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10")
ENDIF(NOT WITH_SHARED_LIBS)
ENDIF(CMAKE_C_COMPILER MATCHES "CL|cl")
# settings for Microsoft Visual C++
IF(CMAKE_CXX_COMPILER MATCHES "CL|cl")
IF(NOT WITH_SHARED_LIBS)
IF(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX /Zm500") # /Zm500 increments heap size which is needed on some system to compile templates in dcmimgle
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
IF(CMAKE_GENERATOR STREQUAL "Visual Studio 7" OR CMAKE_GENERATOR STREQUAL "Visual Studio 7 .NET 2003")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /Gy")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 7" OR CMAKE_GENERATOR STREQUAL "Visual Studio 7 .NET 2003")
IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /Gy /EHsc")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008" OR CMAKE_GENERATOR STREQUAL "Visual Studio 10")
ENDIF(NOT WITH_SHARED_LIBS)
ENDIF(CMAKE_CXX_COMPILER MATCHES "CL|cl")
ADD_DEFINITIONS(-D_REENTRANT)
# directories to search for libraries
LINK_DIRECTORIES(${DCMTK_DIR}/lib)
# Specify the executable to be built
ADD_EXECUTABLE(testapp testapp)
# define include directories to be searched
INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
# define libraries that must be linked to most windows applications
TARGET_LINK_LIBRARIES(testapp dcmdata oflog ofstd ws2_32 netapi32 wsock32)