Skip to content

Commit

Permalink
Update CMake files.
Browse files Browse the repository at this point in the history
Fixes (TurboJPEG, Jasper) and tweaks (OpenJPEG, yaml-cpp).
  • Loading branch information
ningfei committed Jun 29, 2017
1 parent e326fa8 commit 4e01405
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 56 deletions.
8 changes: 4 additions & 4 deletions COMPILE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The text below generally describes how to build dcm2niix using the [GCC](https:/
You can also build the software without C-make. The easiest way to do this is to run the function "make" from the "console" folder. Note that this only creates the default version of dcm2niix, not the optional batch version described above. The make command simply calls the g++ compiler, and if you want you can tune this for your build. In essence, the make function simply calls

```
g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableOpenJPEG -DmyDisableJasper
g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableOpenJPEG
```

The following sub-sections list how you can modify this basic recipe for your needs.
Expand All @@ -37,15 +37,15 @@ g++ -O3 -s -DmyDisableOpenJPEG -DmyDisableZLib -I. main_console.cpp nii_dicom.cp
DICOM images can be stored as either raw data or compressed using one of many formats as described by the [transfer syntaxes](https://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage#Transfer_Syntaxes_and_Compressed_Images). One of the compressed formats is the lossy classic JPEG format (which is separate from and predates the lossy JPEG 2000 format). This software comes with the [NanoJPEG](http://keyj.emphy.de/nanojpeg/) library to handle these images. However, you can use the `myDisableClassicJPEG` compiler switch to remove this dependency. The resulting executable will be smaller but will not be able to convert images stored with this format.

```
g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableClassicJPEG -DmyDisableOpenJPEG -DmyDisableJasper
g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableClassicJPEG -DmyDisableOpenJPEG
```

##### USING LIBJPEG-TURBO TO DECODE CLASSIC JPEG

By default, classic JPEG images will be decoded using the [compact NanoJPEG decoder](http://keyj.emphy.de/nanojpeg/). However, the compiler directive `myTurboJPEG` will create an executable based on the [libjpeg-turbo](http://www.libjpeg-turbo.org) library. This library is a faster decoder and is the standard for many Linux distributions. On the other hand, the lossy classic JPEG is rarely used for DICOM images, so this compilation has extra dependencies and can result in a larger executable size (for static builds).

```
g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableOpenJPEG -DmyDisableJasper -DmyTurboJPEG -I/opt/libjpeg-turbo/include /opt/libjpeg-turbo/lib/libturbojpeg.a
g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableOpenJPEG -DmyTurboJPEG -I/opt/libjpeg-turbo/include /opt/libjpeg-turbo/lib/libturbojpeg.a
```

##### JPEG2000 BUILD
Expand Down Expand Up @@ -86,7 +86,7 @@ This software can be compiled with VisualStudio 2015. This example assumes the c

```
vcvarsall amd64
cl /EHsc main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -DmyDisableOpenJPEG -DmyDisableJasper /odcm2niix
cl /EHsc main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -DmyDisableOpenJPEG /o dcm2niix
```

##### OSX BUILD WITH BOTH 32 AND 64-BIT SUPPORT
Expand Down
2 changes: 1 addition & 1 deletion SuperBuild/External-OPENJPEG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ExternalProject_Add(openjpeg
-DCMAKE_INSTALL_PREFIX=${DEP_INSTALL_DIR}
)

set(OPENJPEG_DIR ${DEP_INSTALL_DIR}/lib/openjpeg-2.1)
set(OpenJPEG_DIR ${DEP_INSTALL_DIR}/lib/openjpeg-2.1)
70 changes: 40 additions & 30 deletions SuperBuild/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(USE_STATIC_RUNTIME "Use static runtime" ON)

option(USE_SYSTEM_ZLIB "Use the system zlib" OFF)
option(USE_SYSTEM_TURBOJPEG "Use the system TurboJPEG" OFF)
option(USE_JASPER "Compile with Jasper support" OFF)
option(USE_TURBOJPEG "Use TurboJPEG to decode classic JPEG" OFF)
option(USE_JASPER "Build with JPEG2000 support using Jasper" OFF)

option(USE_OPENJPEG "Build with OpenJPEG support" OFF)
option(USE_OPENJPEG "Build with JPEG2000 support using OpenJPEG" OFF)
option(BATCH_VERSION "Build dcm2niibatch for multiple conversions" OFF)

include(ExternalProject)
Expand All @@ -42,38 +42,48 @@ endif()
if(USE_OPENJPEG)
message("-- Build with OpenJPEG: ${USE_OPENJPEG}")

find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(OPENJPEG libopenjp2)
endif()

if(OPENJPEG_FOUND)
set(OPENJPEG_DIR ${OPENJPEG_LIBDIR}/openjepg-2.1)
message("-- Using the system OpenJPEG")
if(OpenJPEG_DIR OR OPENJPEG_DIR)
set(OpenJPEG_DIR "${OpenJPEG_DIR}${OPENJPEG_DIR}" CACHE PATH "Path to OpenJPEG configuration file" FORCE)
message("-- Using OpenJPEG library from ${OpenJPEG_DIR}")
else()
include(${CMAKE_SOURCE_DIR}/SuperBuild/External-OPENJPEG.cmake)
list(APPEND DEPENDENCIES openjpeg)
set(BUILD_OPENJPEG TRUE)
message("-- Will build OpenJPEG from github")
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(OPENJPEG libopenjp2)
endif()

if(OPENJPEG_FOUND)
set(OpenJPEG_DIR ${OPENJPEG_LIBDIR}/openjepg-2.1 CACHE PATH "Path to OpenJPEG configuration file" FORCE)
message("-- Using OpenJPEG library from ${OpenJPEG_DIR}")
else()
include(${CMAKE_SOURCE_DIR}/SuperBuild/External-OPENJPEG.cmake)
list(APPEND DEPENDENCIES openjpeg)
set(BUILD_OPENJPEG TRUE)
message("-- Will build OpenJPEG library from github")
endif()
endif()
endif()

if(BATCH_VERSION)
message("-- Build dcm2niibatch: ${BATCH_VERSION}")

find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(YAML-CPP yaml-cpp)
endif()

if(YAML-CPP_FOUND)
set(YAML-CPP_DIR ${YAML-CPP_LIBDIR}/cmake/yaml-cpp)
message("-- Using the system yaml-cpp")
if(YAML-CPP_DIR)
set(YAML-CPP_DIR ${YAML-CPP_DIR} CACHE PATH "Path to yaml-cpp configuration file" FORCE)
message("-- Using yaml-cpp library from ${YAML-CPP_DIR}")
else()
include(${CMAKE_SOURCE_DIR}/SuperBuild/External-YAML-CPP.cmake)
list(APPEND DEPENDENCIES yaml-cpp)
set(BUILD_YAML-CPP TRUE)
message("-- Will build yaml-cpp from github")
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(YAML-CPP yaml-cpp)
endif()

if(YAML-CPP_FOUND)
set(YAML-CPP_DIR ${YAML-CPP_LIBDIR}/cmake/yaml-cpp CACHE PATH "Path to yaml-cpp configuration file" FORCE)
message("-- Using yaml-cpp library from ${YAML-CPP_DIR}")
else()
include(${CMAKE_SOURCE_DIR}/SuperBuild/External-YAML-CPP.cmake)
list(APPEND DEPENDENCIES yaml-cpp)
set(BUILD_YAML-CPP TRUE)
message("-- Will build yaml-cpp library from github")
endif()
endif()
endif()

Expand All @@ -89,11 +99,11 @@ ExternalProject_Add(console
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
-DUSE_STATIC_RUNTIME:BOOL=${USE_STATIC_RUNTIME}
-DUSE_SYSTEM_ZLIB:BOOL=${USE_SYSTEM_ZLIB}
-DUSE_SYSTEM_TURBOJPEG:BOOL=${USE_SYSTEM_TURBOJPEG}
-DUSE_SYSTEM_JASPER:BOOL=${USE_SYSTEM_JASPER}
-DUSE_TURBOJPEG:BOOL=${USE_TURBOJPEG}
-DUSE_JASPER:BOOL=${USE_JASPER}
# OpenJPEG
-DUSE_OPENJPEG:BOOL=${USE_OPENJPEG}
-DOpenJPEG_DIR:PATH=${OPENJPEG_DIR}
-DOpenJPEG_DIR:PATH=${OpenJPEG_DIR}
# yaml-cpp
-DBATCH_VERSION:BOOL=${BATCH_VERSION}
-DYAML-CPP_DIR:PATH=${YAML-CPP_DIR}
Expand Down
43 changes: 24 additions & 19 deletions console/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ else()
ucm_set_runtime(DYNAMIC)
endif()

# Basic CMake build settings
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel")

set(PROGRAMS dcm2niix)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand Down Expand Up @@ -60,30 +65,28 @@ if(USE_SYSTEM_ZLIB)
target_link_libraries(dcm2niix ${ZLIB_LIBRARIES})
endif()

option(USE_SYSTEM_TURBOJPEG "Use the system TurboJPEG" OFF)
if(USE_SYSTEM_TURBOJPEG)
option(USE_TURBOJPEG "Use TurboJPEG to decode classic JPEG" OFF)
if(USE_TURBOJPEG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(TurboJPEG REQUIRED libturbojpeg)
pkg_check_modules(TURBOJPEG REQUIRED libturbojpeg)
add_definitions(-DmyTurboJPEG)
target_include_directories(dcm2niix PRIVATE ${TurboJPEG_INCLUDE_DIRS})
target_link_libraries(dcm2niix ${TurboJPEG_LIBRARIES})
target_include_directories(dcm2niix PRIVATE ${TURBOJPEG_INCLUDEDIR})
target_link_libraries(dcm2niix ${TURBOJPEG_LIBRARIES})
endif()

option(USE_JASPER "Compile with Jasper support" OFF)
option(USE_JASPER "Build with JPEG2000 support using Jasper" OFF)
if(USE_JASPER)
find_package(Jasper REQUIRED)
add_definitions(-DmyEnableJasper)
target_include_directories(dcm2niix PRIVATE ${JASPER_INCLUDE_DIR})
target_link_libraries(dcm2niix ${JASPER_LIBRARIES})
else ()
add_definitions(-DmyDisableJASPER)
endif()

option(USE_OPENJPEG "Build with OpenJPEG support" OFF)
option(USE_OPENJPEG "Build with JPEG2000 support using OpenJPEG" OFF)
if(USE_OPENJPEG)
option(OpenJPEG_DIR "Path to OpenJPEG configuration file" "")
set(OpenJPEG_DIR "${OpenJPEG_DIR}${OPENJPEG_DIR}" CACHE PATH "Path to yaml-cpp configuration file" FORCE)

find_package(OpenJPEG)
find_package(OpenJPEG REQUIRED)

if(WIN32)
if(BUILD_SHARED_LIBS)
Expand Down Expand Up @@ -113,29 +116,31 @@ if(BATCH_VERSION)
nii_ortho.cpp
nii_dicom_batch.cpp)

option(YAML-CPP_DIR "Path to yaml-cpp configuration file" "")
set(YAML-CPP_DIR ${YAML-CPP_DIR} CACHE PATH "Path to yaml-cpp configuration file" FORCE)

find_package(YAML-CPP)
find_package(YAML-CPP REQUIRED)
target_include_directories(dcm2niibatch PRIVATE ${YAML_CPP_INCLUDE_DIR})
target_link_libraries(dcm2niibatch ${YAML_CPP_LIBRARIES})

if(ZLIB_FOUND)
add_definitions(-DmyDisableMiniZ)
target_include_directories(dcm2niibatch PRIVATE ${ZLIB_INCLUDE_DIRS})
target_link_libraries(dcm2niibatch z)
endif()

if(TurboJPEG_FOUND)
target_include_directories(dcm2niibatch PRIVATE ${TurboJPEG_INCLUDE_DIRS})
target_link_libraries(dcm2niibatch ${TurboJPEG_LIBRARIES})
if(TURBOJPEG_FOUND)
add_definitions(-DmyTurboJPEG)
target_include_directories(dcm2niibatch PRIVATE ${TURBOJPEG_INCLUDEDIR})
target_link_libraries(dcm2niibatch ${TURBOJPEG_LIBRARIES})
endif()

if(JASPER_FOUND)
add_definitions(-DmyEnableJasper)
target_include_directories(dcm2niibatch PRIVATE ${JASPER_INCLUDE_DIR})
target_link_libraries(dcm2niibatch ${JASPER_LIBRARIES})
else()
add_definitions(-DmyDisableJASPER)
endif()

if(USE_OPENJPEG)
if(OPENJPEG_FOUND)
target_include_directories(dcm2niibatch PRIVATE ${OPENJPEG_INCLUDE_DIRS})
target_link_libraries(dcm2niibatch ${OPENJPEG_LIBRARIES})
else()
Expand Down
2 changes: 1 addition & 1 deletion console/main_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

//Alternatively, windows users with VisualStudio can compile this project
// vcvarsall amd64
// cl /EHsc main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp -DmyDisableOpenJPEG -DmyDisableJasper /odcm2niix
// cl /EHsc main_console.cpp nii_foreign.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp -DmyDisableOpenJPEG /o dcm2niix


//#define mydebugtest //automatically process directory specified in main, ignore input arguments
Expand Down
2 changes: 1 addition & 1 deletion console/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ ifneq ($(OS),Windows_NT)
endif
endif
all:
g++ $(CFLAGS) -O3 -I. main_console.cpp nii_foreign.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp -o dcm2niix -DmyDisableOpenJPEG -DmyDisableJasper
g++ $(CFLAGS) -O3 -I. main_console.cpp nii_foreign.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp -o dcm2niix -DmyDisableOpenJPEG

0 comments on commit 4e01405

Please sign in to comment.