diff --git a/SuperBuild/External-CLOUDFLARE-ZLIB.cmake b/SuperBuild/External-CLOUDFLARE-ZLIB.cmake index 9bc4d691..4c6a6acb 100644 --- a/SuperBuild/External-CLOUDFLARE-ZLIB.cmake +++ b/SuperBuild/External-CLOUDFLARE-ZLIB.cmake @@ -7,8 +7,12 @@ ExternalProject_Add(zlib BINARY_DIR cloudflare-zlib-build CMAKE_ARGS -Wno-dev + ${EXTERNAL_PROJECT_BUILD_TYPE_CMAKE_ARGS} ${OSX_ARCHITECTURES} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + # Compiler settings + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} + # Install directories -DCMAKE_INSTALL_PREFIX:PATH=${DEP_INSTALL_DIR} ) diff --git a/SuperBuild/External-OPENJPEG.cmake b/SuperBuild/External-OPENJPEG.cmake index f1175884..1d99ac28 100644 --- a/SuperBuild/External-OPENJPEG.cmake +++ b/SuperBuild/External-OPENJPEG.cmake @@ -8,8 +8,12 @@ ExternalProject_Add(openjpeg CMAKE_ARGS -Wno-dev --no-warn-unused-cli + ${EXTERNAL_PROJECT_BUILD_TYPE_CMAKE_ARGS} ${OSX_ARCHITECTURES} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + # Compiler settings + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} + # Not used -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} + # Install directories -DCMAKE_INSTALL_PREFIX:PATH=${DEP_INSTALL_DIR} ) diff --git a/SuperBuild/External-YAML-CPP.cmake b/SuperBuild/External-YAML-CPP.cmake index 95d009f0..ed85ca76 100644 --- a/SuperBuild/External-YAML-CPP.cmake +++ b/SuperBuild/External-YAML-CPP.cmake @@ -8,8 +8,12 @@ ExternalProject_Add(yaml-cpp CMAKE_ARGS -Wno-dev --no-warn-unused-cli + ${EXTERNAL_PROJECT_BUILD_TYPE_CMAKE_ARGS} ${OSX_ARCHITECTURES} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + # Compiler settings + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} + # Install directories -DCMAKE_INSTALL_PREFIX:PATH=${DEP_INSTALL_DIR} ) diff --git a/SuperBuild/SuperBuild.cmake b/SuperBuild/SuperBuild.cmake index d0635308..98f20c6c 100644 --- a/SuperBuild/SuperBuild.cmake +++ b/SuperBuild/SuperBuild.cmake @@ -4,12 +4,8 @@ if(NOT GIT_FOUND) message(FATAL_ERROR "Cannot find Git. Git is required for Superbuild") endif() -# Basic CMake build settings -if(NOT CMAKE_BUILD_TYPE) - 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") -endif() +include(${CMAKE_SOURCE_DIR}/cmake/dcm2niixInitializeBuildType.cmake) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) option(USE_STATIC_RUNTIME "Use static runtime" ON) @@ -151,17 +147,23 @@ ExternalProject_Add(console CMAKE_ARGS -Wno-dev --no-warn-unused-cli + ${EXTERNAL_PROJECT_BUILD_TYPE_CMAKE_ARGS} ${OSX_ARCHITECTURES} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + # Install directories -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR} + # Compiler settings + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} + -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} + # Options -DCMAKE_VERBOSE_MAKEFILE:BOOL=${CMAKE_VERBOSE_MAKEFILE} -DUSE_STATIC_RUNTIME:BOOL=${USE_STATIC_RUNTIME} -DUSE_TURBOJPEG:BOOL=${USE_TURBOJPEG} -DUSE_JASPER:BOOL=${USE_JASPER} -DUSE_JPEGLS:BOOL=${USE_JPEGLS} -DUSE_JNIFTI:BOOL=${USE_JNIFTI} + # ZLIB -DZLIB_IMPLEMENTATION:STRING=${ZLIB_IMPLEMENTATION} -DZLIB_ROOT:PATH=${ZLIB_ROOT} # OpenJPEG diff --git a/cmake/dcm2niixInitializeBuildType.cmake b/cmake/dcm2niixInitializeBuildType.cmake new file mode 100644 index 00000000..b21ba4a8 --- /dev/null +++ b/cmake/dcm2niixInitializeBuildType.cmake @@ -0,0 +1,47 @@ +# This module allows to consistently manage the initialization and setting of build type +# CMake variables. +# +# It sets the variable EXTERNAL_PROJECT_BUILD_TYPE_CMAKE_ARGS based on the CMake generator +# being used: +# * If a multi-config generator (e.g Visual Studio) is used, it sets the variable with +# CMAKE_CONFIGURATION_TYPES. +# * If a single-config generator (e.g Unix Makefiles) is used, it sets the variable with +# CMAKE_BUILD_TYPE. +# +# Adapted from https://github.com/Slicer/Slicer/blob/5.2/CMake/SlicerInitializeBuildType.cmake + +# Default build type to use if none was specified +if(NOT DEFINED dcm2niix_DEFAULT_BUILD_TYPE) + set(dcm2niix_DEFAULT_BUILD_TYPE "Release") +endif() + +# Set a default build type if none was specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + + message(STATUS "Setting build type to '${dcm2niix_DEFAULT_BUILD_TYPE}' as none was specified.") + + set(CMAKE_BUILD_TYPE ${dcm2niix_DEFAULT_BUILD_TYPE} CACHE STRING "Choose the type of build." FORCE) + mark_as_advanced(CMAKE_BUILD_TYPE) + + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" + "Release" + "MinSizeRel" + "RelWithDebInfo" + ) +endif() + +# Pass variables to dependent projects +if(COMMAND ExternalProject_Add) + if(NOT CMAKE_CONFIGURATION_TYPES) + set(EXTERNAL_PROJECT_BUILD_TYPE_CMAKE_ARGS + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + ) + else() + set(EXTERNAL_PROJECT_BUILD_TYPE_CMAKE_ARGS + -DCMAKE_CONFIGURATION_TYPES:STRING=${CMAKE_CONFIGURATION_TYPES} + ) + endif() +endif() +