Skip to content

Commit

Permalink
Merge pull request #701 from jcfr/fix-build-ensuring-expected-compile…
Browse files Browse the repository at this point in the history
…r-is-used

Fix build ensuring expected compiler is used
  • Loading branch information
ningfei authored Apr 24, 2023
2 parents 1c6794d + cdc755c commit e25e75b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
6 changes: 5 additions & 1 deletion SuperBuild/External-CLOUDFLARE-ZLIB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand Down
6 changes: 5 additions & 1 deletion SuperBuild/External-OPENJPEG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand Down
6 changes: 5 additions & 1 deletion SuperBuild/External-YAML-CPP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand Down
16 changes: 9 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,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
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 e25e75b

Please sign in to comment.