Skip to content

Commit

Permalink
COMP: Fix initialization of build-type to support multi-config CMake …
Browse files Browse the repository at this point in the history
…generator

This commit introduces the module "dcm2niixInitializeBuildType"

It 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
  • Loading branch information
jcfr committed Apr 19, 2023
1 parent baf9c75 commit cdc755c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion SuperBuild/External-CLOUDFLARE-ZLIB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ 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}
Expand Down
2 changes: 1 addition & 1 deletion SuperBuild/External-OPENJPEG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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}
Expand Down
2 changes: 1 addition & 1 deletion SuperBuild/External-YAML-CPP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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}
Expand Down
10 changes: 3 additions & 7 deletions SuperBuild/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -151,8 +147,8 @@ 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
Expand Down
47 changes: 47 additions & 0 deletions cmake/dcm2niixInitializeBuildType.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit cdc755c

Please sign in to comment.