From 47b08c22fc841af2abe01b33907d6989b85f2f77 Mon Sep 17 00:00:00 2001 From: Rinat Mukhometzianov Date: Fri, 21 Jun 2019 12:53:51 -0400 Subject: [PATCH 1/7] Fix of Boost and ITK for old versions of CentOS6 --- CMake/ITKSetStandardCompilerFlags.cmake | 204 +++++++++++++++++++++--- SuperBuild.cmake | 3 +- SuperBuild/External_Boost.cmake | 65 +++++--- SuperBuild/External_Eigen.cmake | 4 +- 4 files changed, 224 insertions(+), 52 deletions(-) diff --git a/CMake/ITKSetStandardCompilerFlags.cmake b/CMake/ITKSetStandardCompilerFlags.cmake index db4de2f..4042257 100644 --- a/CMake/ITKSetStandardCompilerFlags.cmake +++ b/CMake/ITKSetStandardCompilerFlags.cmake @@ -22,6 +22,38 @@ include(ITK_CheckCCompilerFlag) include(ITK_CheckCXXCompilerFlag) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14.0) + cmake_policy(SET CMP0083 NEW) + include(CheckPIESupported) + check_pie_supported() +endif() + +function(check_c_compiler_flags c_flag_var) + set(local_c_flags "") + set(flag_list "${ARGN}") + foreach(flag IN LISTS flag_list) + string(REPLACE "=" "_" flag_var ${flag} ) + ITK_CHECK_C_COMPILER_FLAG(${flag} C_HAS_WARNING${flag_var}) + if(${C_HAS_WARNING${flag_var}}) + set(local_c_flags "${local_c_flags} ${flag}") + endif() + endforeach() + set(${c_flag_var} "${local_c_flags}" PARENT_SCOPE) +endfunction() + +function(check_cxx_compiler_flags cxx_flag_var) + set(local_cxx_flags "") + set(flag_list "${ARGN}") + foreach(flag IN LISTS flag_list) + string(REPLACE "=" "_" flag_var ${flag} ) + ITK_CHECK_CXX_COMPILER_FLAG(${flag} CXX_HAS_WARNING${flag_var}) + if(${CXX_HAS_WARNING${flag_var}}) + set(local_cxx_flags "${local_cxx_flags} ${flag}") + endif() + endforeach() + set(${cxx_flag_var} "${local_cxx_flags}" PARENT_SCOPE) +endfunction() + function(check_c_compiler_warning_flags c_flag_var) set(local_c_flags "") set(flag_list "${ARGN}") @@ -34,7 +66,6 @@ function(check_c_compiler_warning_flags c_flag_var) set(${c_flag_var} "${local_c_flags}" PARENT_SCOPE) endfunction() - function(check_cxx_compiler_warning_flags cxx_flag_var) set(local_cxx_flags "") set(flag_list "${ARGN}") @@ -97,9 +128,7 @@ function(check_compiler_warning_flags c_warning_flags_var cxx_warning_flags_var) # Check this list on both C and C++ compilers set(c_and_cxx_flags ${VerboseWarningsFlag} -# -Wno-long-double is only applicable with gcc on apple, and is generating -# warnings now on all platforms. -# -Wno-long-double #Needed on APPLE + -Wno-long-double #Needed on APPLE -Wcast-align -Wdisabled-optimization -Wextra @@ -108,7 +137,6 @@ function(check_compiler_warning_flags c_warning_flags_var cxx_warning_flags_var) -Wno-format-nonliteral -Wpointer-arith -Wshadow - -Wunused -Wwrite-strings -funit-at-a-time @@ -119,9 +147,11 @@ function(check_compiler_warning_flags c_warning_flags_var cxx_warning_flags_var) set(cxx_flags -Wno-deprecated -Wno-invalid-offsetof + -Wno-undefined-var-template # suppress invalid warning when explicitly instantiated in another translation unit -Woverloaded-virtual -Wstrict-null-sentinel ) + ##-Wno-c++0x-static-nonintegral-init ## Clang compiler likes to warn about this feature that is technically only in ## c++0x, but works on many compilers, and if it fails, then alternate methods are used @@ -133,6 +163,49 @@ function(check_compiler_warning_flags c_warning_flags_var cxx_warning_flags_var) set(${cxx_warning_flags_var} "${CMAKE_CXX_WARNING_FLAGS}" PARENT_SCOPE) endfunction() +function(check_compiler_optimization_flags c_optimization_flags_var cxx_optimization_flags_var) + set(${c_optimization_flags_var} "" PARENT_SCOPE) + set(${cxx_optimization_flags_var} "" PARENT_SCOPE) + + if(MSVC) + set(InstructionSetOptimizationFlags + # https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64?view=vs-2015 + /arch:SSE /arch:SSE2 /arch:/AVX /arch:/AVX2 ) # /arch:/AVX2 AVX2 circa 2013 + else() + if (${CMAKE_C_COMPILER} MATCHES "icc.*$") + set(USING_INTEL_ICC_COMPILER TRUE) + endif() + if (${CMAKE_CXX_COMPILER} MATCHES "icpc.*$") + set(USING_INTEL_ICC_COMPILER TRUE) + endif() + if(USING_INTEL_ICC_COMPILER) + set(InstructionSetOptimizationFlags "" ) + else() + set(InstructionSetOptimizationFlags "") + endif () + + # Check this list on C compiler only + set(c_flags "") + + # Check this list on C++ compiler only + set(cxx_flags "") + + # Check this list on both C and C++ compilers + set(InstructionSetOptimizationFlags + # https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/i386-and-x86_002d64-Options.html + # NOTE the corei7 release date was 2008 + -mtune=native # Tune the code for the computer used to compile this package, but allow running on generic cpu archetectures defined by -march + -march=corei7-avx # Use ABI settings to support corei7 (circa 2008 ABI feature sets, corei7-avx circa 2013) + ) + endif() + set(c_and_cxx_flags ${InstructionSetOptimizationFlags}) + + check_c_compiler_flags( CMAKE_C_WARNING_FLAGS ${c_and_cxx_flags} ${c_flags}) + check_cxx_compiler_flags(CMAKE_CXX_WARNING_FLAGS ${c_and_cxx_flags} ${cxx_flags}) + + set(${c_optimization_flags_var} "${CMAKE_C_WARNING_FLAGS}" PARENT_SCOPE) + set(${cxx_optimization_flags_var} "${CMAKE_CXX_WARNING_FLAGS}" PARENT_SCOPE) +endfunction() macro(check_compiler_platform_flags) # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security @@ -166,9 +239,10 @@ macro(check_compiler_platform_flags) if(WIN32) # Some libraries (e.g. vxl libs) have no dllexport markup, so we can # build full shared libraries only with the GNU toolchain. For non - # gnu compilers on windows, only Common is shared. This allows for - # plugin type applications to use a dll for ITKCommon which will contain - # the static for Modified time. + # gnu compilers on windows, only a few libraries are built shared. + # This is controlled with ITK_LIBRARY_BUILD_TYPE used in the add_library + # call. This allows for plugin type applications to use a dll for + # ITKCommon which will contain the static for Modified time. if(CMAKE_COMPILER_IS_GNUCXX) # CMake adds --enable-all-exports on Cygwin (since Cygwin is # supposed to be UNIX-like), but we need to add it explicitly for @@ -181,18 +255,56 @@ macro(check_compiler_platform_flags) set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-auto-import") endif() else() + # if CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS is on, then + # BUILD_SHARED_LIBS works as it would on other systems + if(NOT CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS) if(BUILD_SHARED_LIBS) set(ITK_LIBRARY_BUILD_TYPE "SHARED") else() set(ITK_LIBRARY_BUILD_TYPE "STATIC") endif() + # turn off BUILD_SHARED_LIBS as ITK_LIBRARY_BUILD_TYPE + # is used on the libraries that have markup. set(BUILD_SHARED_LIBS OFF) endif() endif() + endif() + #----------------------------------------------------------------------------- #ITK requires special compiler flags on some platforms. if(CMAKE_COMPILER_IS_GNUCXX) - if(APPLE) + + # GCC's -Warray-bounds has been shown to throw false positives with -O3 on 4.8. + if(UNIX AND ( + ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_EQUAL "4.8") OR + ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER "4.8" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.9") )) + set(ITK_REQUIRED_CXX_FLAGS "${ITK_REQUIRED_CXX_FLAGS} -Wno-array-bounds") + endif() + + if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + set(_safe_cmake_required_flags "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fuse-ld=gold") + CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" have_gold) + set(CMAKE_REQUIRED_FLAGS "${_safe_cmake_required_flags}") + if(have_gold) + set(_use_gold_linker_default ON) + set(_gold_linker_failure_condition_0 "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.9.0") + set(_gold_linker_failure_condition_1 NOT BUILD_SHARED_LIBS AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_EQUAL "4.9.0") + if( (${_gold_linker_failure_condition_0}) OR (${_gold_linker_failure_condition_1}) ) + set(_use_gold_linker_default OFF) + endif() + option(ITK_USE_GOLD_LINKER "Use the gold linker instead of ld." ${_use_gold_linker_default}) + mark_as_advanced(ITK_USE_GOLD_LINKER) + # The gold linker is approximately 3X faster. + if(ITK_USE_GOLD_LINKER) + set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=gold ${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=gold ${CMAKE_MODULE_LINKER_FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=gold ${CMAKE_SHARED_LINKER_FLAGS}") + endif() + endif() + endif() + + if(APPLE) option(ITK_USE_64BITS_APPLE_TRUNCATION_WARNING "Turn on warnings on 64bits to 32bits truncations." OFF) mark_as_advanced(ITK_USE_64BITS_APPLE_TRUNCATION_WARNING) @@ -213,7 +325,6 @@ macro(check_compiler_platform_flags) message("-fopenmp causes incorrect compliation of HDF, removing from ${listname}") endif() endforeach() - endif() # gcc must have -msse2 option to enable sse2 support @@ -245,7 +356,8 @@ macro(check_compiler_platform_flags) endif() endif() endif() - + + # mingw thread support if(MINGW) set(ITK_REQUIRED_CXX_FLAGS "${ITK_REQUIRED_CXX_FLAGS} -mthreads") @@ -253,7 +365,6 @@ macro(check_compiler_platform_flags) set(ITK_REQUIRED_LINK_FLAGS "${ITK_REQUIRED_LINK_FLAGS} -mthreads") endif() - #----------------------------------------------------------------------------- # The frename-registers option does not work due to a bug in the gnu compiler. # It must be removed or data errors will be produced and incorrect results @@ -271,25 +382,70 @@ macro(check_compiler_platform_flags) #----------------------------------------------------------------------------- # Set the compiler-specific flag for disabling optimization. if(MSVC) - set(ITK_CXX_DISABLE_OPTIMIZATION_FLAG "/Od") - elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(GNU|Intel)$") - set(ITK_CXX_DISABLE_OPTIMIZATION_FLAG "-O0") + set(${PROJECT_NAME}_CXX_DISABLE_OPTIMIZATION_FLAG "/Od") + elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(GNU|Intel)$" AND NOT MINGW) + set(${PROJECT_NAME}_CXX_DISABLE_OPTIMIZATION_FLAG "-O0") endif() - if(DEFINED ITK_CXX_DISABLE_OPTIMIZATION_FLAG) - CHECK_CXX_SOURCE_COMPILES(${ITK_CXX_DISABLE_OPTIMIZATION_FLAG} CXX_HAS_DISABLE_OPTIMIZATION_FLAG) + if(DEFINED ${PROJECT_NAME}_CXX_DISABLE_OPTIMIZATION_FLAG) + CHECK_CXX_SOURCE_COMPILES(${${PROJECT_NAME}_CXX_DISABLE_OPTIMIZATION_FLAG} CXX_HAS_DISABLE_OPTIMIZATION_FLAG) endif() + endmacro()#End the platform check function +if(NOT ${PROJECT_NAME}_C_WARNING_FLAGS OR NOT ${PROJECT_NAME}_CXX_WARNING_FLAGS ) # Only check once if not explicitly set on command line + #----------------------------------------------------------------------------- + #Check the set of warning flags the compiler supports + check_compiler_warning_flags(C_WARNING_FLAGS CXX_WARNING_FLAGS) +endif() + +if(NOT ${PROJECT_NAME}_C_WARNING_FLAGS) #Not set on cmake command line option -D${PROJECT_NAME}_C_WARNING_FLAGS:STRING="" + set(${PROJECT_NAME}_C_WARNING_FLAGS ${C_WARNING_FLAGS}) +endif() +set(${PROJECT_NAME}_C_WARNING_FLAGS ${${PROJECT_NAME}_C_WARNING_FLAGS} CACHE STRING "ITK C compiler warning flags. Modify to suit your needs.") + +if(NOT ${PROJECT_NAME}_CXX_WARNING_FLAGS) #Not set on cmake command line option -D${PROJECT_NAME}_CXX_WARNING_FLAGS:STRING="" + set(${PROJECT_NAME}_CXX_WARNING_FLAGS ${CXX_WARNING_FLAGS}) +endif() +set(${PROJECT_NAME}_CXX_WARNING_FLAGS ${${PROJECT_NAME}_CXX_WARNING_FLAGS} CACHE STRING "ITK CXX compiler warning flags. Modify to suit your needs.") + +mark_as_advanced(${PROJECT_NAME}_CXX_WARNING_FLAGS) +mark_as_advanced(${PROJECT_NAME}_C_WARNING_FLAGS) +unset(C_WARNING_FLAGS) +unset(CXX_WARNING_FLAGS) + + +if(NOT ${PROJECT_NAME}_C_OPTIMIZATION_FLAGS OR NOT ${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS ) # Only check once if not explicitly set on command line + #----------------------------------------------------------------------------- + #Check the set of warning flags the compiler supports + check_compiler_optimization_flags(C_OPTIMIZATION_FLAGS CXX_OPTIMIZATION_FLAGS) +endif() +if(NOT ${PROJECT_NAME}_C_OPTIMIZATION_FLAGS) #Not set on cmake command line option -D${PROJECT_NAME}_C_OPTIMIZATION_FLAGS:STRING="" + set(${PROJECT_NAME}_C_OPTIMIZATION_FLAGS ${C_OPTIMIZATION_FLAGS} CACHE STRING "ITK C Compiler ABI/Optimization flags, Use '-march=native' to maximize performance, but break portabilitly.") +else() + set(${PROJECT_NAME}_C_OPTIMIZATION_FLAGS ${${PROJECT_NAME}_C_OPTIMIZATION_FLAGS} CACHE STRING "ITK C Compiler ABI/Optimization flags, Use '-march=native' to maximize performance, but break portabilitly.") +endif() +if(NOT ${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS) #Not set on cmake command line option -D${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS:STRING="" + set(${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS ${CXX_OPTIMIZATION_FLAGS} CACHE STRING "ITK CXX Compiler ABI/Optimization flags, Use '-march=native' to maximize performance, but break portabilitly.") +else() + set(${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS ${${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS} CACHE STRING "ITK CXX Compiler ABI/Optimization flags, Use '-march=native' to maximize performance, but break portabilitly.") +endif() +mark_as_advanced(${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS) +mark_as_advanced(${PROJECT_NAME}_C_OPTIMIZATION_FLAGS) +unset(C_OPTIMIZATION_FLAGS) +unset(CXX_OPTIMIZATION_FLAGS) #----------------------------------------------------------------------------- -#Check the set of warning flags the compiler supports -check_compiler_warning_flags(C_WARNING_FLAGS CXX_WARNING_FLAGS) +#Check the set of platform flags the compiler supports +check_compiler_platform_flags() # Append ITK warnings to the CMake flags. # We do not set them in ITK_REQUIRED FLAGS because all project which # use ITK don't require these flags . -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_WARNING_FLAGS}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARNING_FLAGS}") -#----------------------------------------------------------------------------- -#Check the set of platform flags the compiler supports -check_compiler_platform_flags() +string(REPLACE " " ";" CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${PROJECT_NAME}_C_OPTIMIZATION_FLAGS} ${${PROJECT_NAME}_C_WARNING_FLAGS}") +list(REMOVE_DUPLICATES CMAKE_C_FLAGS) +string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + +string(REPLACE " " ";" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS} ${${PROJECT_NAME}_CXX_WARNING_FLAGS}") +list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS) +string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + diff --git a/SuperBuild.cmake b/SuperBuild.cmake index 7dc3d10..46c598c 100644 --- a/SuperBuild.cmake +++ b/SuperBuild.cmake @@ -54,12 +54,12 @@ mark_as_superbuild( ## for i in SuperBuild/*; do echo $i |sed 's/.*External_\([a-zA-Z]*\).*/\1/g'|fgrep -v cmake|fgrep -v Template; done|sort -u set(${PRIMARY_PROJECT_NAME}_DEPENDENCIES + Boost SlicerExecutionModel ITK Eigen VTK teem - Boost ) #----------------------------------------------------------------------------- @@ -122,6 +122,7 @@ mark_as_superbuild( PYTHON_LIBRARY:FILEPATH BOOST_ROOT:PATH BOOST_INCLUDE_DIR:PATH + Boost_LIBRARY_DIR:PATH SlicerExecutionModel_DIR:PATH SlicerExecutionModel_DEFAULT_CLI_RUNTIME_OUTPUT_DIRECTORY:PATH SlicerExecutionModel_DEFAULT_CLI_LIBRARY_OUTPUT_DIRECTORY:PATH diff --git a/SuperBuild/External_Boost.cmake b/SuperBuild/External_Boost.cmake index 34ec12c..f1f03a1 100644 --- a/SuperBuild/External_Boost.cmake +++ b/SuperBuild/External_Boost.cmake @@ -34,36 +34,45 @@ if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" ### --- Project specific additions here set(Boost_Install_Dir ${CMAKE_CURRENT_BINARY_DIR}/${proj}-install) - set(Boost_Configure_Script ${CMAKE_CURRENT_LIST_DIR}/External_Boost_configureboost.cmake) - set(Boost_Build_Script ${CMAKE_CURRENT_LIST_DIR}/External_Boost_buildboost.cmake) + + if(CMAKE_COMPILER_IS_CLANGXX) + set(CLANG_ARG -DCMAKE_COMPILER_IS_CLANGXX:BOOL=ON) + endif() ### --- End Project specific additions -# SVN is too slow SVN_REPOSITORY http://svn.boost.org/svn/boost/trunk -# SVN is too slow SVN_REVISION -r "82586" - set(${proj}_URL http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz ) - set(${proj}_MD5 93780777cfbf999a600f62883bd54b17 ) if(CMAKE_COMPILER_IS_CLANGXX) set(CLANG_ARG -DCMAKE_COMPILER_IS_CLANGXX:BOOL=ON) endif() set(BOOST_SOURCE_DIR ${SOURCE_DOWNLOAD_CACHE}/${proj}) - ExternalProject_Add(${proj} - ${${proj}_EP_ARGS} - URL ${${proj}_URL} - URL_MD5 ${${proj}_MD5} - SOURCE_DIR ${BOOST_SOURCE_DIR} - CONFIGURE_COMMAND ${CMAKE_COMMAND} - ${CLANG_ARG} - -DBUILD_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/${proj} - -DBOOST_INSTALL_DIR:PATH=${Boost_Install_Dir} - -P ${Boost_Configure_Script} - INSTALL_COMMAND "" - BUILD_IN_SOURCE 1 - BUILD_COMMAND ${CMAKE_COMMAND} - -DBUILD_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/Boost - -DBOOST_INSTALL_DIR:PATH=${Boost_Install_Dir} -P ${Boost_Build_Script} - ) - set(BOOST_ROOT ${BOOST_SOURCE_DIR}) - set(BOOST_INCLUDE_DIR ${BOOST_SOURCE_DIR}) + + set( Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.tar.gz") + set( Boost_md5 fea771fe8176828fabf9c09242ee8c26 ) + set( Boost_Bootstrap_Command ./bootstrap.sh ) + set( Boost_b2_Command ./b2 ) + + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(Boost_address_model 64) +else() + set(Boost_address_model 32) +endif() + + ExternalProject_Add(${proj} + ${${proj}_EP_ARGS} + BUILD_IN_SOURCE 1 + URL ${Boost_url} + URL_MD5 ${Boost_md5} + UPDATE_COMMAND "" + CONFIGURE_COMMAND ${Boost_Bootstrap_Command} --prefix=${Boost_Install_Dir}/lib + BUILD_COMMAND ${Boost_b2_Command} install -j8 --prefix=${Boost_Install_Dir} --with-thread --with-filesystem --with-system --with-date_time --with-program_options --with-atomic address-model=${Boost_address_model} link=static,shared + INSTALL_COMMAND "" + ) + + set(BOOST_ROOT ${Boost_Install_Dir}) + set(BOOST_INCLUDE_DIR ${Boost_Install_Dir}/include) + set(Boost_LIBRARY_DIR ${Boost_Install_Dir}/lib) + message(STATUS "BOOST_ROOT is " ${BOOST_ROOT}) + message(STATUS "Boost_LIBRARY_DIR is " ${Boost_LIBRARY_DIR}) + else() if(${USE_SYSTEM_${extProjName}}) find_package(${proj} ${${extProjName}_REQUIRED_VERSION} REQUIRED) @@ -74,4 +83,10 @@ else() ExternalProject_Add_Empty(${proj} "${${proj}_DEPENDENCIES}") endif() -list(APPEND ${CMAKE_PROJECT_NAME}_SUPERBUILD_EP_VARS ${extProjName}_DIR:PATH) +mark_as_superbuild( + VARS + ${extProjName}_DIR:PATH + LABELS + "FIND_PACKAGE" +) + diff --git a/SuperBuild/External_Eigen.cmake b/SuperBuild/External_Eigen.cmake index 6e5c5a3..bb8ddae 100644 --- a/SuperBuild/External_Eigen.cmake +++ b/SuperBuild/External_Eigen.cmake @@ -10,7 +10,7 @@ if(DEFINED ${extProjName}_DIR AND NOT EXISTS ${${extProjName}_DIR}) endif() # Set dependency list -set(${proj}_DEPENDENCIES "") +set(${proj}_DEPENDENCIES Boost) # Include dependent projects if any ExternalProject_Include_Dependencies(${proj} PROJECT_VAR proj DEPENDS_VAR ${proj}_DEPENDENCIES) @@ -48,7 +48,7 @@ if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" LOG_INSTALL 0 # Wrap install in script to to ignore log output from dashboards INSTALL_DIR ${${proj}_INSTALL_DIR} CMAKE_GENERATOR ${gen} - CMAKE_ARGS -Wno-dev --no-warn-unused-cli + CMAKE_ARGS -Wno-dev --no-warn-unused-cli -DBOOST_ROOT:PATH=${BOOST_ROOT} -DBoost_NO_BOOST_CMAKE=TRUE -DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_LIBRARY_DIRS:FILEPATH=${BOOST_ROOT}/lib CMAKE_CACHE_ARGS ${CMAKE_OSX_EXTERNAL_PROJECT_ARGS} ${COMMON_EXTERNAL_PROJECT_ARGS} From a7c8777d6254d77fbdf55226237d44cad77fc2ce Mon Sep 17 00:00:00 2001 From: ML-Enthusiast Date: Fri, 21 Jun 2019 14:02:49 -0400 Subject: [PATCH 2/7] remove unnecessary files --- SuperBuild/External_Boost_buildboost.cmake | 20 ----------------- .../External_Boost_configureboost.cmake | 22 ------------------- 2 files changed, 42 deletions(-) delete mode 100644 SuperBuild/External_Boost_buildboost.cmake delete mode 100644 SuperBuild/External_Boost_configureboost.cmake diff --git a/SuperBuild/External_Boost_buildboost.cmake b/SuperBuild/External_Boost_buildboost.cmake deleted file mode 100644 index d08e793..0000000 --- a/SuperBuild/External_Boost_buildboost.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# -# Follow the boost suggestions -# - -if(WIN32) - - execute_process(COMMAND ./b2 install --prefix=${BOOST_INSTALL_DIR} - --without-atomic --without-chrono --without-context --without-date_time --without-exception --without-filesystem --without-graph --without-graph_parallel --without-iostreams --without-locale --without-log --without-math --without-mpi --without-program_options --without-python --without-random --without-regex --without-serialization --without-signals - --without-test --without-timer --without-wave -# Needed for UKF --without-system --without-thread - WORKING_DIRECTORY ${BUILD_DIR} RESULT_VARIABLE build_result) - -else() - - execute_process(COMMAND ./b2 install - WORKING_DIRECTORY ${BUILD_DIR} RESULT_VARIABLE build_result) - -endif() - -return(${build_result}) diff --git a/SuperBuild/External_Boost_configureboost.cmake b/SuperBuild/External_Boost_configureboost.cmake deleted file mode 100644 index bb81d6f..0000000 --- a/SuperBuild/External_Boost_configureboost.cmake +++ /dev/null @@ -1,22 +0,0 @@ -# -# Follow the boost suggestions -# - -if(WIN32) # bootstrap.bat has no options, the options are given to ./b2 when BUILDING: see buildboost.cmake - - execute_process(COMMAND bootstrap.bat - WORKING_DIRECTORY ${BUILD_DIR} RESULT_VARIABLE boostrap_result) - -else() - - execute_process(COMMAND ./bootstrap.sh --prefix=${BOOST_INSTALL_DIR} - --without-libraries=atomic,chrono,context,date_time,exception,filesystem,graph,graph_parallel,iostreams,locale,log,math,mpi,program_options,python,random,regex,serialization,signals,test,timer,wave -## Needed for UKF system,thread, - WORKING_DIRECTORY ${BUILD_DIR} RESULT_VARIABLE boostrap_result) -### NOTE: --with-libraries= is purposefull left blank to avoid building -### any of the unnecessary boost libraries. ANTS only needs -### the header-only components of boost! - -endif() - -return(${bootstrap_result}) From ad45169c31527ea2959a97934e6aaf7823e7ec24 Mon Sep 17 00:00:00 2001 From: ML-Enthusiast Date: Fri, 21 Jun 2019 17:14:57 -0400 Subject: [PATCH 3/7] additional win and mac support --- CMake/ITKSetStandardCompilerFlags.cmake | 31 ++---------- SuperBuild/External_Boost.cmake | 63 ++++++++++++++++++++----- 2 files changed, 53 insertions(+), 41 deletions(-) diff --git a/CMake/ITKSetStandardCompilerFlags.cmake b/CMake/ITKSetStandardCompilerFlags.cmake index 4042257..b4e00c1 100644 --- a/CMake/ITKSetStandardCompilerFlags.cmake +++ b/CMake/ITKSetStandardCompilerFlags.cmake @@ -54,31 +54,6 @@ function(check_cxx_compiler_flags cxx_flag_var) set(${cxx_flag_var} "${local_cxx_flags}" PARENT_SCOPE) endfunction() -function(check_c_compiler_warning_flags c_flag_var) - set(local_c_flags "") - set(flag_list "${ARGN}") - foreach(flag IN LISTS flag_list) - ITK_CHECK_C_COMPILER_FLAG(${flag} C_HAS_WARNING${flag}) - if(${C_HAS_WARNING${flag}}) - set(local_c_flags "${local_c_flags} ${flag}") - endif() - endforeach() - set(${c_flag_var} "${local_c_flags}" PARENT_SCOPE) -endfunction() - -function(check_cxx_compiler_warning_flags cxx_flag_var) - set(local_cxx_flags "") - set(flag_list "${ARGN}") - foreach(flag IN LISTS flag_list) - ITK_CHECK_CXX_COMPILER_FLAG(${flag} CXX_HAS_WARNING${flag}) - if(${CXX_HAS_WARNING${flag}}) - set(local_cxx_flags "${local_cxx_flags} ${flag}") - endif() - endforeach() - set(${cxx_flag_var} "${local_cxx_flags}" PARENT_SCOPE) -endfunction() - - function(check_compiler_warning_flags c_warning_flags_var cxx_warning_flags_var) set(${c_warning_flags_var} "" PARENT_SCOPE) set(${cxx_warning_flags_var} "" PARENT_SCOPE) @@ -156,8 +131,8 @@ function(check_compiler_warning_flags c_warning_flags_var cxx_warning_flags_var) ## Clang compiler likes to warn about this feature that is technically only in ## c++0x, but works on many compilers, and if it fails, then alternate methods are used - check_c_compiler_warning_flags(CMAKE_C_WARNING_FLAGS ${c_flags} ${c_and_cxx_flags}) - check_cxx_compiler_warning_flags(CMAKE_CXX_WARNING_FLAGS ${c_and_cxx_flags} ${cxx_flags}) + check_c_compiler_flags(CMAKE_C_WARNING_FLAGS ${c_flags} ${c_and_cxx_flags}) + check_cxx_compiler_flags(CMAKE_CXX_WARNING_FLAGS ${c_and_cxx_flags} ${cxx_flags}) set(${c_warning_flags_var} "${CMAKE_C_WARNING_FLAGS}" PARENT_SCOPE) set(${cxx_warning_flags_var} "${CMAKE_CXX_WARNING_FLAGS}" PARENT_SCOPE) @@ -200,7 +175,7 @@ function(check_compiler_optimization_flags c_optimization_flags_var cxx_optimiza endif() set(c_and_cxx_flags ${InstructionSetOptimizationFlags}) - check_c_compiler_flags( CMAKE_C_WARNING_FLAGS ${c_and_cxx_flags} ${c_flags}) + check_c_compiler_flags(CMAKE_C_WARNING_FLAGS ${c_and_cxx_flags} ${c_flags}) check_cxx_compiler_flags(CMAKE_CXX_WARNING_FLAGS ${c_and_cxx_flags} ${cxx_flags}) set(${c_optimization_flags_var} "${CMAKE_C_WARNING_FLAGS}" PARENT_SCOPE) diff --git a/SuperBuild/External_Boost.cmake b/SuperBuild/External_Boost.cmake index f1f03a1..f777622 100644 --- a/SuperBuild/External_Boost.cmake +++ b/SuperBuild/External_Boost.cmake @@ -45,16 +45,49 @@ if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" endif() set(BOOST_SOURCE_DIR ${SOURCE_DOWNLOAD_CACHE}/${proj}) - set( Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.tar.gz") - set( Boost_md5 fea771fe8176828fabf9c09242ee8c26 ) - set( Boost_Bootstrap_Command ./bootstrap.sh ) - set( Boost_b2_Command ./b2 ) + if(UNIX) + set(Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.tar.gz") + set(Boost_md5 fea771fe8176828fabf9c09242ee8c26) + set(Boost_Bootstrap_Command ./bootstrap.sh) + set(Boost_b2_Command ./b2) + else() + if(WIN32) + set(Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.zip") + set(Boost_md5 a110ebd91a3d2c34c72ace09c92ae50b) + set(Boost_Bootstrap_Command bootstrap.bat) + set(Boost_b2_Command b2.exe) + endif() + endif() + + if(MSVC10) + list(APPEND Boost_b2_Command toolset=msvc-10.0) + elseif(MSVC11) + list(APPEND Boost_b2_Command toolset=msvc-11.0) + elseif(MSVC12) + list(APPEND Boost_b2_Command toolset=msvc-12.0) + elseif(MSVC14) + list(APPEND Boost_b2_Command toolset=msvc-14.0) + elseif(XCODE_VERSION) + list(APPEND Boost_b2_Command toolset=clang) + elseif(ENV{CC}) + # CMake apprarently puts the full path of the compiler into CC + # The user might specify a non-default gcc compiler through ENV + message(STATUS "ENV{CC}=$ENV{CC}") + get_filename_component( gccToolset "$ENV{CC}" NAME ) + + # see: https://svn.boost.org/trac/boost/ticket/5917 + string(TOLOWER ${gccToolset} gccToolset) + if(gccToolset STREQUAL "cc") + set(gccToolset "gcc") + endif() + list(APPEND Boost_b2_Command toolset=${gccToolset}) + endif() if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(Boost_address_model 64) -else() - set(Boost_address_model 32) -endif() + set(Boost_address_model 64) + else() + set(Boost_address_model 32) + endif() ExternalProject_Add(${proj} ${${proj}_EP_ARGS} @@ -63,15 +96,19 @@ endif() URL_MD5 ${Boost_md5} UPDATE_COMMAND "" CONFIGURE_COMMAND ${Boost_Bootstrap_Command} --prefix=${Boost_Install_Dir}/lib - BUILD_COMMAND ${Boost_b2_Command} install -j8 --prefix=${Boost_Install_Dir} --with-thread --with-filesystem --with-system --with-date_time --with-program_options --with-atomic address-model=${Boost_address_model} link=static,shared + BUILD_COMMAND ${Boost_b2_Command} install -j8 --prefix=${Boost_Install_Dir} --with-thread --with-filesystem --with-system --with-date_time --with-program_options --with-atomic address-model=${Boost_address_model} link=static,shared INSTALL_COMMAND "" ) - set(BOOST_ROOT ${Boost_Install_Dir}) - set(BOOST_INCLUDE_DIR ${Boost_Install_Dir}/include) + if(NOT WIN32) + set(BOOST_ROOT ${Boost_Install_Dir}) + set(BOOST_INCLUDE_DIR ${Boost_Install_Dir}/include) + else() + set(BOOST_ROOT ${Boost_Install_Dir}) + set(Boost_INCLUDE_DIR ${Boost_Install_Dir}/include/boost-1_70) + endif() + set(Boost_LIBRARY_DIR ${Boost_Install_Dir}/lib) - message(STATUS "BOOST_ROOT is " ${BOOST_ROOT}) - message(STATUS "Boost_LIBRARY_DIR is " ${Boost_LIBRARY_DIR}) else() if(${USE_SYSTEM_${extProjName}}) From e96788d5172158dd32b10f39f565d86cc60b62cb Mon Sep 17 00:00:00 2001 From: Rinat M Date: Tue, 25 Jun 2019 15:19:10 -0400 Subject: [PATCH 4/7] update MSVC cmake variables --- SuperBuild/External_Boost.cmake | 45 ++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/SuperBuild/External_Boost.cmake b/SuperBuild/External_Boost.cmake index f777622..6fe9c33 100644 --- a/SuperBuild/External_Boost.cmake +++ b/SuperBuild/External_Boost.cmake @@ -59,28 +59,34 @@ if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" endif() endif() - if(MSVC10) - list(APPEND Boost_b2_Command toolset=msvc-10.0) - elseif(MSVC11) - list(APPEND Boost_b2_Command toolset=msvc-11.0) - elseif(MSVC12) - list(APPEND Boost_b2_Command toolset=msvc-12.0) - elseif(MSVC14) - list(APPEND Boost_b2_Command toolset=msvc-14.0) - elseif(XCODE_VERSION) - list(APPEND Boost_b2_Command toolset=clang) + if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) + list(APPEND Boost_b2_Command toolset=msvc-8.0) + elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) + list(APPEND Boost_b2_Command toolset=msvc-9.0) + elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) + list(APPEND Boost_b2_Command toolset=msvc-10.0) + elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) + list(APPEND Boost_b2_Command toolset=msvc-11.0) + elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) + list(APPEND Boost_b2_Command toolset=msvc-12.0) + elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) + list(APPEND Boost_b2_Command toolset=msvc-14.0) + elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) + list(APPEND Boost_b2_Command toolset=msvc-14.1) elseif(ENV{CC}) # CMake apprarently puts the full path of the compiler into CC # The user might specify a non-default gcc compiler through ENV - message(STATUS "ENV{CC}=$ENV{CC}") - get_filename_component( gccToolset "$ENV{CC}" NAME ) - - # see: https://svn.boost.org/trac/boost/ticket/5917 - string(TOLOWER ${gccToolset} gccToolset) - if(gccToolset STREQUAL "cc") - set(gccToolset "gcc") - endif() - list(APPEND Boost_b2_Command toolset=${gccToolset}) + message(STATUS "ENV{CC}=$ENV{CC}") + get_filename_component( gccToolset "$ENV{CC}" NAME ) + + # see: https://svn.boost.org/trac/boost/ticket/5917 + string(TOLOWER ${gccToolset} gccToolset) + if(gccToolset STREQUAL "cc") + set(gccToolset "gcc") + endif() + list(APPEND Boost_b2_Command toolset=${gccToolset}) + else() + message(FATAL_ERROR "Unknown MSVC compiler version [${MSVC_VERSION}]") endif() if(CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -126,4 +132,3 @@ mark_as_superbuild( LABELS "FIND_PACKAGE" ) - From 4c1d6d84e2d09021a3872b932da35851c0e7da63 Mon Sep 17 00:00:00 2001 From: Rinat M Date: Tue, 25 Jun 2019 16:19:56 -0400 Subject: [PATCH 5/7] boost bug fix --- SuperBuild/External_Boost.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/SuperBuild/External_Boost.cmake b/SuperBuild/External_Boost.cmake index 6fe9c33..3554776 100644 --- a/SuperBuild/External_Boost.cmake +++ b/SuperBuild/External_Boost.cmake @@ -85,8 +85,6 @@ if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" set(gccToolset "gcc") endif() list(APPEND Boost_b2_Command toolset=${gccToolset}) - else() - message(FATAL_ERROR "Unknown MSVC compiler version [${MSVC_VERSION}]") endif() if(CMAKE_SIZEOF_VOID_P EQUAL 8) From d0fbb1428f5fe21a14446a98cf34e070a8c5f255 Mon Sep 17 00:00:00 2001 From: Rinat M Date: Tue, 25 Jun 2019 22:17:30 -0400 Subject: [PATCH 6/7] fix windows script filename --- SuperBuild/External_Boost.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SuperBuild/External_Boost.cmake b/SuperBuild/External_Boost.cmake index 3554776..f3b4fc4 100644 --- a/SuperBuild/External_Boost.cmake +++ b/SuperBuild/External_Boost.cmake @@ -54,8 +54,8 @@ if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" if(WIN32) set(Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.zip") set(Boost_md5 a110ebd91a3d2c34c72ace09c92ae50b) - set(Boost_Bootstrap_Command bootstrap.bat) - set(Boost_b2_Command b2.exe) + set(Boost_Bootstrap_Command ./bootstrap.bat) + set(Boost_b2_Command ./b2.exe) endif() endif() From 5769afeb988970ea10eccde5df041e8555243fac Mon Sep 17 00:00:00 2001 From: Rinat Mukhometzianov Date: Fri, 28 Jun 2019 04:09:41 -0400 Subject: [PATCH 7/7] Fix for MS Win build --- CMake/ITKSetStandardCompilerFlags.cmake | 21 +- CMakeLists.txt | 10 +- Common.cmake | 3 + SuperBuild.cmake | 1 + SuperBuild/External_Boost.cmake | 278 +++++++++--------- SuperBuild/External_Eigen.cmake | 2 +- SuperBuild/External_ITK.cmake | 5 +- .../External_SlicerExecutionModel.cmake | 1 + SuperBuild/External_VTK.cmake | 18 +- SuperBuild/External_zlib.cmake | 6 +- UKFTractography.cmake | 7 + UKFTractography/CMakeLists.txt | 1 - fibertractdispersion/computedispersion.cxx | 6 +- fibertractdispersion/fiberbundle.cxx | 2 +- ukf/NrrdData.cc | 20 +- ukf/QuadProg++_Eigen.cc | 26 +- ukf/cli.cc | 2 +- ukf/unscented_kalman_filter.cc | 2 +- ukf/utilities.cc | 6 +- ukf/vtk_writer.cc | 54 ++-- vtk2mask/Converter.cc | 6 +- vtkFilter/vtkWriter.cc | 16 +- vtkFilter/vtkWriter.h | 8 +- 23 files changed, 282 insertions(+), 219 deletions(-) diff --git a/CMake/ITKSetStandardCompilerFlags.cmake b/CMake/ITKSetStandardCompilerFlags.cmake index b4e00c1..6cc23e4 100644 --- a/CMake/ITKSetStandardCompilerFlags.cmake +++ b/CMake/ITKSetStandardCompilerFlags.cmake @@ -21,6 +21,8 @@ include(ITK_CheckCCompilerFlag) include(ITK_CheckCXXCompilerFlag) +include(CheckCXXCompilerFlag) +include(CheckCCompilerFlag) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14.0) cmake_policy(SET CMP0083 NEW) @@ -33,7 +35,11 @@ function(check_c_compiler_flags c_flag_var) set(flag_list "${ARGN}") foreach(flag IN LISTS flag_list) string(REPLACE "=" "_" flag_var ${flag} ) - ITK_CHECK_C_COMPILER_FLAG(${flag} C_HAS_WARNING${flag_var}) + if(CMAKE_VERSION VERSION_LESS 2.8.9) + ITK_CHECK_C_COMPILER_FLAG(${flag} C_HAS_WARNING${flag_var}) + else() + check_c_compiler_flag(${flag} C_HAS_WARNING${flag_var}) + endif() if(${C_HAS_WARNING${flag_var}}) set(local_c_flags "${local_c_flags} ${flag}") endif() @@ -46,7 +52,11 @@ function(check_cxx_compiler_flags cxx_flag_var) set(flag_list "${ARGN}") foreach(flag IN LISTS flag_list) string(REPLACE "=" "_" flag_var ${flag} ) - ITK_CHECK_CXX_COMPILER_FLAG(${flag} CXX_HAS_WARNING${flag_var}) + if(CMAKE_VERSION VERSION_LESS 2.8.9) + ITK_CHECK_CXX_COMPILER_FLAG(${flag} CXX_HAS_WARNING${flag_var}) + else() + check_cxx_compiler_flag(${flag} CXX_HAS_WARNING${flag_var}) + endif() if(${CXX_HAS_WARNING${flag_var}}) set(local_cxx_flags "${local_cxx_flags} ${flag}") endif() @@ -103,7 +113,7 @@ function(check_compiler_warning_flags c_warning_flags_var cxx_warning_flags_var) # Check this list on both C and C++ compilers set(c_and_cxx_flags ${VerboseWarningsFlag} - -Wno-long-double #Needed on APPLE + -Wno-long-double #Needed on APPLE -Wcast-align -Wdisabled-optimization -Wextra @@ -122,7 +132,7 @@ function(check_compiler_warning_flags c_warning_flags_var cxx_warning_flags_var) set(cxx_flags -Wno-deprecated -Wno-invalid-offsetof - -Wno-undefined-var-template # suppress invalid warning when explicitly instantiated in another translation unit + -Wno-undefined-var-template # suppress invalid warning when explicitly instantiated in another translation unit -Woverloaded-virtual -Wstrict-null-sentinel ) @@ -422,5 +432,4 @@ string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") string(REPLACE " " ";" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${PROJECT_NAME}_CXX_OPTIMIZATION_FLAGS} ${${PROJECT_NAME}_CXX_WARNING_FLAGS}") list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS) -string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - +string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index cb37c1f..969b254 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.7) if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) #3.12.0 `find_package()`` uses ``_ROOT`` variables. @@ -70,6 +70,14 @@ endif() option(${PRIMARY_PROJECT_NAME}_SUPERBUILD "Build ${PRIMARY_PROJECT_NAME} and the projects it depends on via SuperBuild.cmake." ${default_superbuild_value}) mark_as_advanced(${PRIMARY_PROJECT_NAME}_SUPERBUILD) +#----------------------------------------------------------------------------- +# Additional CXX/C Flags +#----------------------------------------------------------------------------- +set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags") +mark_as_advanced(ADDITIONAL_C_FLAGS) +set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags") +mark_as_advanced(ADDITIONAL_CXX_FLAGS) + #----------------------------------------------------------------------------- # Required by Slicer extension build system for reasons. See # https://github.com/Slicer/Slicer/commit/b160ec13f276a86306513954ef8b08a5332afc2e diff --git a/Common.cmake b/Common.cmake index 20af12d..9c9dcf1 100644 --- a/Common.cmake +++ b/Common.cmake @@ -1,6 +1,9 @@ include(ExternalProject) include(ExternalProjectDependency) +set(ep_common_c_flags "${CMAKE_C_FLAGS_INIT} ${ADDITIONAL_C_FLAGS}") +set(ep_common_cxx_flags "${CMAKE_CXX_FLAGS_INIT} ${ADDITIONAL_CXX_FLAGS}") + #----------------------------------------------------------------------------- if(APPLE) # Note: By setting CMAKE_OSX_* variables before any enable_language() or project() calls, diff --git a/SuperBuild.cmake b/SuperBuild.cmake index 46c598c..0f24a92 100644 --- a/SuperBuild.cmake +++ b/SuperBuild.cmake @@ -31,6 +31,7 @@ set_property(CACHE EXTERNAL_PROJECT_BUILD_TYPE PROPERTY option(USE_SYSTEM_ITK "Build using an externally defined version of ITK" OFF) option(USE_SYSTEM_SlicerExecutionModel "Build using an externally defined version of SlicerExecutionModel" OFF) option(USE_SYSTEM_VTK "Build using an externally defined version of VTK" OFF) +option(USE_SYSTEM_BOOST "Build using an externally defined version of BOOST" OFF) #------------------------------------------------------------------------------ set(SlicerExecutionModel_DEFAULT_CLI_RUNTIME_OUTPUT_DIRECTORY bin) diff --git a/SuperBuild/External_Boost.cmake b/SuperBuild/External_Boost.cmake index f3b4fc4..4eda1a4 100644 --- a/SuperBuild/External_Boost.cmake +++ b/SuperBuild/External_Boost.cmake @@ -1,132 +1,146 @@ -# Make sure that the ExtProjName/IntProjName variables are unique globally -# even if other External_${ExtProjName}.cmake files are sourced by -# SlicerMacroCheckExternalProjectDependency -set(extProjName BOOST) #The find_package known name -set(proj Boost) #This local name -set(${extProjName}_REQUIRED_VERSION "") #If a required version is necessary, then set this, else leave blank - -#if(${USE_SYSTEM_${extProjName}}) -# unset(${extProjName}_DIR CACHE) -#endif() - -# Sanity checks -if(DEFINED ${extProjName}_DIR AND NOT EXISTS ${${extProjName}_DIR}) - message(FATAL_ERROR "${extProjName}_DIR variable is defined but corresponds to non-existing directory (${${extProjName}_DIR})") -endif() - -# Set dependency list -set(${proj}_DEPENDENCIES "") - -# Include dependent projects if any -ExternalProject_Include_Dependencies(${proj} PROJECT_VAR proj DEPENDS_VAR ${proj}_DEPENDENCIES) - -if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" ) ) - #message(STATUS "${__indent}Adding project ${proj}") - - # Set CMake OSX variable to pass down the external project - set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS) - if(APPLE) - list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS - -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES} - -DCMAKE_OSX_SYSROOT:STRING=${CMAKE_OSX_SYSROOT} - -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}) - endif() - - ### --- Project specific additions here - set(Boost_Install_Dir ${CMAKE_CURRENT_BINARY_DIR}/${proj}-install) - - if(CMAKE_COMPILER_IS_CLANGXX) - set(CLANG_ARG -DCMAKE_COMPILER_IS_CLANGXX:BOOL=ON) - endif() - - ### --- End Project specific additions - if(CMAKE_COMPILER_IS_CLANGXX) - set(CLANG_ARG -DCMAKE_COMPILER_IS_CLANGXX:BOOL=ON) - endif() - set(BOOST_SOURCE_DIR ${SOURCE_DOWNLOAD_CACHE}/${proj}) - - if(UNIX) - set(Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.tar.gz") - set(Boost_md5 fea771fe8176828fabf9c09242ee8c26) - set(Boost_Bootstrap_Command ./bootstrap.sh) - set(Boost_b2_Command ./b2) - else() - if(WIN32) - set(Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.zip") - set(Boost_md5 a110ebd91a3d2c34c72ace09c92ae50b) - set(Boost_Bootstrap_Command ./bootstrap.bat) - set(Boost_b2_Command ./b2.exe) - endif() - endif() - - if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) - list(APPEND Boost_b2_Command toolset=msvc-8.0) - elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) - list(APPEND Boost_b2_Command toolset=msvc-9.0) - elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) - list(APPEND Boost_b2_Command toolset=msvc-10.0) - elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) - list(APPEND Boost_b2_Command toolset=msvc-11.0) - elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) - list(APPEND Boost_b2_Command toolset=msvc-12.0) - elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) - list(APPEND Boost_b2_Command toolset=msvc-14.0) - elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) - list(APPEND Boost_b2_Command toolset=msvc-14.1) - elseif(ENV{CC}) - # CMake apprarently puts the full path of the compiler into CC - # The user might specify a non-default gcc compiler through ENV - message(STATUS "ENV{CC}=$ENV{CC}") - get_filename_component( gccToolset "$ENV{CC}" NAME ) - - # see: https://svn.boost.org/trac/boost/ticket/5917 - string(TOLOWER ${gccToolset} gccToolset) - if(gccToolset STREQUAL "cc") - set(gccToolset "gcc") - endif() - list(APPEND Boost_b2_Command toolset=${gccToolset}) - endif() - - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(Boost_address_model 64) - else() - set(Boost_address_model 32) - endif() - - ExternalProject_Add(${proj} - ${${proj}_EP_ARGS} - BUILD_IN_SOURCE 1 - URL ${Boost_url} - URL_MD5 ${Boost_md5} - UPDATE_COMMAND "" - CONFIGURE_COMMAND ${Boost_Bootstrap_Command} --prefix=${Boost_Install_Dir}/lib - BUILD_COMMAND ${Boost_b2_Command} install -j8 --prefix=${Boost_Install_Dir} --with-thread --with-filesystem --with-system --with-date_time --with-program_options --with-atomic address-model=${Boost_address_model} link=static,shared - INSTALL_COMMAND "" - ) - - if(NOT WIN32) - set(BOOST_ROOT ${Boost_Install_Dir}) - set(BOOST_INCLUDE_DIR ${Boost_Install_Dir}/include) - else() - set(BOOST_ROOT ${Boost_Install_Dir}) - set(Boost_INCLUDE_DIR ${Boost_Install_Dir}/include/boost-1_70) - endif() - - set(Boost_LIBRARY_DIR ${Boost_Install_Dir}/lib) - -else() - if(${USE_SYSTEM_${extProjName}}) - find_package(${proj} ${${extProjName}_REQUIRED_VERSION} REQUIRED) - message("USING the system ${extProjName}, set ${extProjName}_DIR=${${extProjName}_DIR}") - endif() - # The project is provided using ${extProjName}_DIR, nevertheless since other - # project may depend on ${extProjName}, let's add an 'empty' one - ExternalProject_Add_Empty(${proj} "${${proj}_DEPENDENCIES}") -endif() - -mark_as_superbuild( - VARS - ${extProjName}_DIR:PATH - LABELS - "FIND_PACKAGE" -) +# Make sure that the ExtProjName/IntProjName variables are unique globally +# even if other External_${ExtProjName}.cmake files are sourced by +# SlicerMacroCheckExternalProjectDependency +set(extProjName BOOST) #The find_package known name +set(proj Boost) #This local name +set(${extProjName}_REQUIRED_VERSION "") #If a required version is necessary, then set this, else leave blank + +#if(${USE_SYSTEM_${extProjName}}) +# unset(${extProjName}_DIR CACHE) +#endif() + +# Sanity checks +if(DEFINED ${extProjName}_DIR AND NOT EXISTS ${${extProjName}_DIR}) + message(FATAL_ERROR "${extProjName}_DIR variable is defined but corresponds to non-existing directory (${${extProjName}_DIR})") +endif() + +# Set dependency list +set(${proj}_DEPENDENCIES "") + +# Include dependent projects if any +ExternalProject_Include_Dependencies(${proj} PROJECT_VAR proj DEPENDS_VAR ${proj}_DEPENDENCIES) + +if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" ) ) + #message(STATUS "${__indent}Adding project ${proj}") + + # Set CMake OSX variable to pass down the external project + set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS) + if(APPLE) + list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS + -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES} + -DCMAKE_OSX_SYSROOT:STRING=${CMAKE_OSX_SYSROOT} + -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}) + endif() + + ### --- Project specific additions here + set(Boost_Install_Dir ${CMAKE_CURRENT_BINARY_DIR}/${proj}-install) + + if(CMAKE_COMPILER_IS_CLANGXX) + set(CLANG_ARG -DCMAKE_COMPILER_IS_CLANGXX:BOOL=ON) + endif() + + ### --- End Project specific additions + if(CMAKE_COMPILER_IS_CLANGXX) + set(CLANG_ARG -DCMAKE_COMPILER_IS_CLANGXX:BOOL=ON) + endif() + set(BOOST_SOURCE_DIR ${SOURCE_DOWNLOAD_CACHE}/${proj}) + + if(UNIX) + set(Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.tar.gz") + set(Boost_md5 fea771fe8176828fabf9c09242ee8c26) + set(Boost_Bootstrap_Command ./bootstrap.sh) + set(Boost_b2_Command ./b2) + else() + if(WIN32) + set(Boost_url "http://sourceforge.net/projects/boost/files/boost/1.70.0/boost_1_70_0.zip") + set(Boost_md5 a110ebd91a3d2c34c72ace09c92ae50b) + set(Boost_Bootstrap_Command ./bootstrap.bat) + set(Boost_b2_Command b2) + endif() + endif() + + if(MSVC) + if(MSVC_VERSION GREATER_EQUAL 1400 AND MSVC_VERSION LESS 1500) + list(APPEND Boost_b2_Command toolset=msvc-8.0) + elseif(MSVC_VERSION GREATER_EQUAL 1500 AND MSVC_VERSION LESS 1600) + list(APPEND Boost_b2_Command toolset=msvc-9.0) + elseif(MSVC_VERSION GREATER_EQUAL 1600 AND MSVC_VERSION LESS 1700) + list(APPEND Boost_b2_Command toolset=msvc-10.0) + elseif(MSVC_VERSION GREATER_EQUAL 1700 AND MSVC_VERSION LESS 1800) + list(APPEND Boost_b2_Command toolset=msvc-11.0) + elseif(MSVC_VERSION GREATER_EQUAL 1800 AND MSVC_VERSION LESS 1900) + list(APPEND Boost_b2_Command toolset=msvc-12.0) + elseif(MSVC_VERSION GREATER_EQUAL 1900 AND MSVC_VERSION LESS 1910) + list(APPEND Boost_b2_Command toolset=msvc-14.0) + elseif(MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS 1920) + list(APPEND Boost_b2_Command toolset=msvc-14.1) + elseif(MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1922) + list(APPEND Boost_b2_Command toolset=msvc-14.2) + else() + message(FATAL_ERROR "Unknown MSVC compiler version [${MSVC_VERSION}]") + endif() + endif() + + if(XCODE_VERSION OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + list(APPEND Boost_b2_Command toolset=clang) + elseif(CMAKE_COMPILER_IS_GNUCXX) + list(APPEND Boost_b2_Command toolset=gcc) + endif() + + if(ENV{CC}) + # CMake apprarently puts the full path of the compiler into CC + # The user might specify a non-default gcc compiler through ENV + message(STATUS "ENV{CC}=$ENV{CC}") + get_filename_component( gccToolset "$ENV{CC}" NAME ) + + # see: https://svn.boost.org/trac/boost/ticket/5917 + string(TOLOWER ${gccToolset} gccToolset) + if(gccToolset STREQUAL "cc") + set(gccToolset "gcc") + endif() + list(APPEND Boost_b2_Command toolset=${gccToolset}) + endif() + + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(Boost_address_model 64) + else() + set(Boost_address_model 32) + endif() + + ExternalProject_Add(${proj} + ${${proj}_EP_ARGS} + BUILD_IN_SOURCE 1 + URL ${Boost_url} + URL_MD5 ${Boost_md5} + UPDATE_COMMAND "" + CONFIGURE_COMMAND ${Boost_Bootstrap_Command} --prefix=${Boost_Install_Dir}/lib + BUILD_COMMAND ${Boost_b2_Command} install -j8 --prefix=${Boost_Install_Dir} --with-thread --with-filesystem --with-system --with-date_time --with-program_options --with-atomic address-model=${Boost_address_model} link=static + INSTALL_COMMAND "" + ) + + if(NOT WIN32) + set(BOOST_ROOT ${Boost_Install_Dir}) + set(BOOST_INCLUDE_DIR ${Boost_Install_Dir}/include) + else() + set(BOOST_ROOT ${Boost_Install_Dir}) + set(Boost_INCLUDE_DIR ${Boost_Install_Dir}/include/boost-1_70) + endif() + + set(Boost_LIBRARY_DIR ${Boost_Install_Dir}/lib) + +else() + if(${USE_SYSTEM_${extProjName}}) + find_package(${proj} ${${extProjName}_REQUIRED_VERSION} REQUIRED) + message("USING the system ${extProjName}, set ${extProjName}_DIR=${${extProjName}_DIR}") + endif() + # The project is provided using ${extProjName}_DIR, nevertheless since other + # project may depend on ${extProjName}, let's add an 'empty' one + ExternalProject_Add_Empty(${proj} "${${proj}_DEPENDENCIES}") +endif() + +mark_as_superbuild( + VARS + ${extProjName}_DIR:PATH + LABELS + "FIND_PACKAGE" +) \ No newline at end of file diff --git a/SuperBuild/External_Eigen.cmake b/SuperBuild/External_Eigen.cmake index bb8ddae..691fd85 100644 --- a/SuperBuild/External_Eigen.cmake +++ b/SuperBuild/External_Eigen.cmake @@ -48,7 +48,7 @@ if(NOT ( DEFINED "USE_SYSTEM_${extProjName}" AND "${USE_SYSTEM_${extProjName}}" LOG_INSTALL 0 # Wrap install in script to to ignore log output from dashboards INSTALL_DIR ${${proj}_INSTALL_DIR} CMAKE_GENERATOR ${gen} - CMAKE_ARGS -Wno-dev --no-warn-unused-cli -DBOOST_ROOT:PATH=${BOOST_ROOT} -DBoost_NO_BOOST_CMAKE=TRUE -DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_LIBRARY_DIRS:FILEPATH=${BOOST_ROOT}/lib + CMAKE_ARGS -Wno-dev --no-warn-unused-cli -DBOOST_ROOT:PATH=${BOOST_ROOT} -DBoost_NO_BOOST_CMAKE:BOOL=TRUE -DBoost_NO_SYSTEM_PATHS:BOOL=TRUE -DBoost_LIBRARY_DIRS:FILEPATH=${BOOST_ROOT}/lib CMAKE_CACHE_ARGS ${CMAKE_OSX_EXTERNAL_PROJECT_ARGS} ${COMMON_EXTERNAL_PROJECT_ARGS} diff --git a/SuperBuild/External_ITK.cmake b/SuperBuild/External_ITK.cmake index 8c5e574..241ec5e 100644 --- a/SuperBuild/External_ITK.cmake +++ b/SuperBuild/External_ITK.cmake @@ -26,7 +26,7 @@ if(NOT DEFINED ITK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}) ExternalProject_SetIfNotDefined( ${CMAKE_PROJECT_NAME}_${proj}_GIT_TAG - "f9ae0a051440b674c82dfa41c5054b2c7308417e" # slicer-v4.13.0-2017-12-20-d92873e-2 + "f9ae0a051440b674c82dfa41c5054b2c7308417e" # 9825d546c457ebe84948fd6f9db3d2a966811ace # slicer-v4.13.0-2017-12-20-d92873e-2 QUIET ) @@ -45,10 +45,11 @@ if(NOT DEFINED ITK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}) ${${proj}_EP_ARGS} GIT_REPOSITORY "${${CMAKE_PROJECT_NAME}_${proj}_GIT_REPOSITORY}" GIT_TAG "${${CMAKE_PROJECT_NAME}_${proj}_GIT_TAG}" - GIT_SHALLOW TRUE + #GIT_SHALLOW TRUE SOURCE_DIR ${EP_SOURCE_DIR} BINARY_DIR ${EP_BINARY_DIR} CMAKE_CACHE_ARGS + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags} -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} diff --git a/SuperBuild/External_SlicerExecutionModel.cmake b/SuperBuild/External_SlicerExecutionModel.cmake index 2e2d23e..01e54af 100644 --- a/SuperBuild/External_SlicerExecutionModel.cmake +++ b/SuperBuild/External_SlicerExecutionModel.cmake @@ -60,6 +60,7 @@ if(NOT DEFINED SlicerExecutionModel_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM CMAKE_ARGS -Wno-dev --no-warn-unused-cli CMAKE_CACHE_ARGS ${COMMON_EXTERNAL_PROJECT_ARGS} + -DCMAKE_BUILD_TYPE:STRING=Debug -DBUILD_TESTING:BOOL=OFF -DITK_DIR:PATH=${ITK_DIR} -DSlicerExecutionModel_LIBRARY_PROPERTIES:STRING=${Slicer_LIBRARY_PROPERTIES} diff --git a/SuperBuild/External_VTK.cmake b/SuperBuild/External_VTK.cmake index 0c8ab40..97c24a8 100644 --- a/SuperBuild/External_VTK.cmake +++ b/SuperBuild/External_VTK.cmake @@ -24,10 +24,19 @@ if(DEFINED VTK_SOURCE_DIR AND NOT EXISTS ${VTK_SOURCE_DIR}) message(FATAL_ERROR "VTK_SOURCE_DIR variable is defined but corresponds to non-existing directory") endif() +# For MinGW for case of compilation failure cause of 'too many sections' error +if (CMAKE_SIZEOF_VOID_P EQUAL 8) + if(MINGW) + set(ep_common_cxx_flags "${ep_common_cxx_flags} -Wa,-mbig-obj") + elseif(MSVC) + set(ep_common_cxx_flags "${ep_common_cxx_flags} /bigobj") + endif() +endif() + if((NOT DEFINED VTK_DIR OR NOT DEFINED VTK_SOURCE_DIR) AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}) set(${proj}_GIT_REPOSITORY "${git_protocol}://www.vtk.org/VTK.git" CACHE STRING "Repository from which to get VTK" FORCE) - set(${proj}_GIT_TAG "b86da7eef93f75c4a7f524b3644523ae6b651bc4") # VTK v7.1.1 + set(${proj}_GIT_TAG "v7.1.1") #"b86da7eef93f75c4a7f524b3644523ae6b651bc4") # VTK v7.1.1 ## Use ../VTK/Utilities/Maintenance/WhatModulesVTK.py ../VTK ./ ## to identify necessary modules for VTK @@ -41,6 +50,13 @@ if((NOT DEFINED VTK_DIR OR NOT DEFINED VTK_SOURCE_DIR) AND NOT ${CMAKE_PROJECT_N CMAKE_ARGS -Wno-dev --no-warn-unused-cli CMAKE_CACHE_ARGS ${COMMON_EXTERNAL_PROJECT_ARGS} + -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} + -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags} + -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} + -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags} + -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} + -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED} + -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS} -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/${proj}-install -DCMAKE_INCLUDE_DIRECTORIES_BEFORE:BOOL=OFF -DBUILD_TESTING:BOOL=OFF diff --git a/SuperBuild/External_zlib.cmake b/SuperBuild/External_zlib.cmake index 00357d2..3818364 100644 --- a/SuperBuild/External_zlib.cmake +++ b/SuperBuild/External_zlib.cmake @@ -61,7 +61,11 @@ if(NOT DEFINED zlib_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj}) set(ZLIB_ROOT ${zlib_DIR}) set(ZLIB_INCLUDE_DIR ${zlib_DIR}/include) if(WIN32) - set(ZLIB_LIBRARY ${zlib_DIR}/lib/zlib.lib) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") #to make compatible with msys2 gcc build + set(ZLIB_LIBRARY ${zlib_DIR}/lib/libzlib.a) + else() + set(ZLIB_LIBRARY ${zlib_DIR}/lib/zlib.lib) + endif() else() set(ZLIB_LIBRARY ${zlib_DIR}/lib/libzlib.a) endif() diff --git a/UKFTractography.cmake b/UKFTractography.cmake index ae34df7..a976bd7 100644 --- a/UKFTractography.cmake +++ b/UKFTractography.cmake @@ -77,6 +77,13 @@ endif() #----------------------------------------------------------------------------- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common) +set(UKF_STATIC) +if(NOT BUILD_SHARED_LIBS) + set(UKF_STATIC 1) + if(WIN32) + add_definitions("-DUKF_STATIC") + endif() +endif() add_subdirectory(ukf) add_subdirectory(UKFTractography) diff --git a/UKFTractography/CMakeLists.txt b/UKFTractography/CMakeLists.txt index f99c242..2e388d9 100644 --- a/UKFTractography/CMakeLists.txt +++ b/UKFTractography/CMakeLists.txt @@ -19,7 +19,6 @@ set(MODULE_TARGET_LIBRARIES UKFBase ) - #----------------------------------------------------------------------------- SEMMacroBuildCLI( NAME UKFTractography diff --git a/fibertractdispersion/computedispersion.cxx b/fibertractdispersion/computedispersion.cxx index af88b03..ec60a05 100644 --- a/fibertractdispersion/computedispersion.cxx +++ b/fibertractdispersion/computedispersion.cxx @@ -97,7 +97,7 @@ typedef Eigen::Matrix VectorType; void cell2mat(const MatrixVector &fibers /*in*/,MatrixType &tractMatrix /*out*/) { - const unsigned int fibersSize(fibers.size()); + const size_t fibersSize(fibers.size()); unsigned int numCols(0); for(unsigned i = 0; i < fibersSize; ++i) { @@ -144,7 +144,7 @@ void FiberVector2EigenFiberVector(const fiberbundle::FiberVector &fv /* in */, MatrixVector &lv) { - const unsigned long fiberSize(fv.size()); + const size_t fiberSize(fv.size()); lv.clear(); // possibly reusing existing vector lv.resize(fiberSize); // same size as input fiberbundle @@ -152,7 +152,7 @@ FiberVector2EigenFiberVector(const fiberbundle::FiberVector &fv /* in */, for(unsigned long i = 0; i < fiberSize; ++i) { const stdVec_t &curFiber = fv[i].Points; - const unsigned long curFiberSize(curFiber.size()); + const size_t curFiberSize(curFiber.size()); MatrixType &curLocalFiber = lv[i]; curLocalFiber.conservativeResize(3, curFiberSize); diff --git a/fibertractdispersion/fiberbundle.cxx b/fibertractdispersion/fiberbundle.cxx index f7b0c94..1013b8d 100644 --- a/fibertractdispersion/fiberbundle.cxx +++ b/fibertractdispersion/fiberbundle.cxx @@ -90,7 +90,7 @@ ::WriteFibers( std::string outputFibersFileName, bool writeAscii, bool writeUnCo for(FiberVector::iterator it = this->m_FiberBundle.begin(); it != this->m_FiberBundle.end(); ++it) { - int fiber_size = (*it).Points.size(); + int fiber_size = static_cast((*it).Points.size()); vtkIdType *ids = new vtkIdType[fiber_size]; for(vtkIdType curPoint = 0; curPoint < fiber_size; ++curPoint,++counter) { diff --git a/ukf/NrrdData.cc b/ukf/NrrdData.cc index f63c718..bdb02d9 100644 --- a/ukf/NrrdData.cc +++ b/ukf/NrrdData.cc @@ -244,9 +244,9 @@ void NrrdData::GetSeeds(const std::vector& labels, std::vector::const_iterator cit; // Go through the volume. - int nx = _seed_nrrd->axis[2].size; - int ny = _seed_nrrd->axis[1].size; - int nz = _seed_nrrd->axis[0].size; + size_t nx = _seed_nrrd->axis[2].size; + size_t ny = _seed_nrrd->axis[1].size; + size_t nz = _seed_nrrd->axis[0].size; assert(_seed_data); if ( !(nx == _dim[0] && ny == _dim[1] && nz == _dim[2]) ) @@ -254,16 +254,16 @@ void NrrdData::GetSeeds(const std::vector& labels, itkGenericExceptionMacro(<< "Labelmap ROI volume dimensions DO NOT match DWI dimensions"); } - for( int i = 0; i < nx; ++i ) + for( size_t i = 0; i < nx; ++i ) { - for( int j = 0; j < ny; ++j ) + for( size_t j = 0; j < ny; ++j ) { - for( int k = 0; k < nz; ++k ) + for( size_t k = 0; k < nz; ++k ) { for( cit = labels.begin(); cit != labels.end(); ++cit ) { int value = 0; - int index = ny * nz * i + nz * j + k; + size_t index = ny * nz * i + nz * j + k; switch( _seed_data_type ) { @@ -475,7 +475,7 @@ bool NrrdData::LoadSignal(Nrrd* input_nrrd, const bool normalizedDWIData) // otherwise the bValues are taken from the header // if bValue not in header also take the norm // normalizing the gradients - const unsigned int gradientCount = _gradients.size(); + const size_t gradientCount = _gradients.size(); _b_values.resize(gradientCount * 2 ); for( unsigned int i = 0; i < gradientCount; ++i ) { @@ -518,7 +518,7 @@ bool NrrdData::LoadSignal(Nrrd* input_nrrd, const bool normalizedDWIData) // std::cout << "dim: " << _dim[0] << " " << _dim[1] << " " << _dim[2] << std::endl; - _num_gradients = _data_nrrd->axis[0].size; + _num_gradients = static_cast(_data_nrrd->axis[0].size); assert(_num_gradients == static_cast(gradientCount ) ); // Get the measurement frame. @@ -600,7 +600,7 @@ bool NrrdData::LoadSignal(Nrrd* input_nrrd, const bool normalizedDWIData) // To get the data for the other half-sphere, simply reverse the gradients and duplicate the signals for( unsigned int i = 0; i < gradientCount; ++i ) { - const unsigned int dupIndex = i + gradientCount; + const unsigned int dupIndex = static_cast(i + gradientCount); // Duplicate and reverse direction. _gradients.push_back(-_gradients[i]); _b_values[dupIndex] =_b_values[i]; diff --git a/ukf/QuadProg++_Eigen.cc b/ukf/QuadProg++_Eigen.cc index aeaada5..5b8b593 100644 --- a/ukf/QuadProg++_Eigen.cc +++ b/ukf/QuadProg++_Eigen.cc @@ -29,7 +29,7 @@ namespace QuadProgPP // Utility functions for updating some data needed by the solution method inline void compute_d(ukfVectorType& d, const ukfMatrixType& J, const ukfVectorType& np) { - const int n = d.size(); + const int n = static_cast(d.size()); /* compute d = H^T * np */ for( int c = 0; c < n; ++c ) @@ -45,7 +45,7 @@ inline void compute_d(ukfVectorType& d, const ukfMatrixType& J, const ukfVectorT inline void update_z(ukfVectorType& z, const ukfMatrixType& J, const ukfVectorType& d, int iq) { - const int n = z.size(); + const int n = static_cast(z.size()); /* setting of z = H * d */ for( int i = 0; i < n; ++i ) @@ -91,7 +91,7 @@ inline ukfPrecisionType distance(ukfPrecisionType a, ukfPrecisionType b) bool add_constraint(ukfMatrixType& R, ukfMatrixType& J, ukfVectorType& d, int& iq, ukfPrecisionType& R_norm) { - const int n = d.size(); + const int n = static_cast(d.size()); #ifdef TRACE_SOLVER std::cout << "Add constraint " << iq << '/'; @@ -252,7 +252,7 @@ void delete_constraint(ukfMatrixType& R, ukfMatrixType& J, Eigen::VectorXi& A, u void cholesky_decomposition(ukfMatrixType& A) { - const int n = A.rows(); + const int n = static_cast(A.rows()); for( int i = 0; i < n; ++i ) { @@ -289,7 +289,7 @@ void cholesky_decomposition(ukfMatrixType& A) inline void forward_elimination(const ukfMatrixType& L, ukfVectorType& y, const ukfVectorType& b) { - const int n = L.rows(); + const int n = static_cast(L.rows()); y[0] = b[0] / L(0,0); for( int i = 1; i < n; ++i ) @@ -305,7 +305,7 @@ inline void forward_elimination(const ukfMatrixType& L, ukfVectorType& y, const inline void backward_elimination(const ukfMatrixType& U, ukfVectorType& x, const ukfVectorType& y) { - const int n = U.rows(); + const int n = static_cast(U.rows()); x[n - 1] = y[n - 1] / U(n - 1,n - 1); for( int i = n - 2; i >= 0; i-- ) @@ -321,7 +321,7 @@ inline void backward_elimination(const ukfMatrixType& U, ukfVectorType& x, const void cholesky_solve(const ukfMatrixType& L, ukfVectorType& x, const ukfVectorType& b) { - const int n = L.rows(); + const int n = static_cast(L.rows()); ukfVectorType y(n); @@ -334,7 +334,7 @@ void cholesky_solve(const ukfMatrixType& L, ukfVectorType& x, const ukfVectorTyp inline ukfPrecisionType dot_product(const ukfVectorType& x, const ukfVectorType& y) { - int n = x.size(); + int n = static_cast(x.size()); ukfPrecisionType sum; sum = ukfZero; @@ -353,11 +353,11 @@ void print_matrix(const char* name, const ukfMatrixType& A, int n, int m) if( n == -1 ) { - n = A.rows(); + n = static_cast(A.rows()); } if( m == -1 ) { - m = A.cols(); + m = static_cast(A.cols()); } s << name << ": " << std::endl; @@ -423,9 +423,9 @@ ukfPrecisionType solve_quadprog(ukfMatrixType& G, ukfVectorType& g0, throw std::logic_error(msg.str()); } - const int n = G.cols(); - const int p = CE.cols(); - const int m = CI.cols(); + const int n = static_cast(G.cols()); + const int p = static_cast(CE.cols()); + const int m = static_cast(CI.cols()); if( (int)G.rows() != n ) { diff --git a/ukf/cli.cc b/ukf/cli.cc index 91ed49b..cc807e6 100644 --- a/ukf/cli.cc +++ b/ukf/cli.cc @@ -30,7 +30,7 @@ void ukf_tell(const ukfPrecisionType & x, const std::string &name) } }; // anonymous namespace -UKFBASELIB_EXPORTS int ukf_parse_cli(int argc, char** argv, UKFSettings& s) +int ukf_parse_cli(int argc, char** argv, UKFSettings& s) { PARSE_ARGS ; diff --git a/ukf/unscented_kalman_filter.cc b/ukf/unscented_kalman_filter.cc index 2be3d81..eacc123 100644 --- a/ukf/unscented_kalman_filter.cc +++ b/ukf/unscented_kalman_filter.cc @@ -96,7 +96,7 @@ void UnscentedKalmanFilter::Constrain(ukfVectorType& x, const ukfMatrixType& W) // matrix version void UnscentedKalmanFilter::Constrain(ukfMatrixType& localX, const ukfMatrixType& localW) { - const unsigned int numCols = localX.cols(); + const unsigned int numCols = static_cast(localX.cols()); for( unsigned int i = 0; i < numCols; ++i ) { diff --git a/ukf/utilities.cc b/ukf/utilities.cc index 8d64133..e9f8542 100644 --- a/ukf/utilities.cc +++ b/ukf/utilities.cc @@ -28,7 +28,7 @@ ukfPrecisionType l2fa(ukfPrecisionType l1, ukfPrecisionType l2, ukfPrecisionType ukfPrecisionType s2ga(const ukfMatrixType& signal) { - int n = signal.rows(); + int n = static_cast(signal.rows()); assert(signal.cols() == 1); @@ -55,7 +55,7 @@ ukfPrecisionType s2ga(const ukfMatrixType& signal) ukfPrecisionType s2adc(const ukfMatrixType& signal) { - int n = signal.rows(); + int n = static_cast(signal.rows()); assert(signal.cols() == 1); @@ -72,7 +72,7 @@ ukfPrecisionType s2adc(const ukfMatrixType& signal) ukfPrecisionType curve_radius(const stdVec_t& fiber) { - int length = fiber.size(); + size_t length = fiber.size(); if( length < 3 ) { diff --git a/ukf/vtk_writer.cc b/ukf/vtk_writer.cc index 952aeda..e93d834 100644 --- a/ukf/vtk_writer.cc +++ b/ukf/vtk_writer.cc @@ -146,9 +146,9 @@ ::PopulateFibersAndTensors(vtkPolyData* polyData, vtkIdType counter = 0; for(size_t i = 0; i < num_fibers; ++i) { - size_t fiber_size = fibers[i].position.size(); + int fiber_size = static_cast(fibers[i].position.size()); vtkIdType *ids = new vtkIdType[fiber_size]; - for(size_t j = 0; j < fiber_size; ++j) + for(int j = 0; j < fiber_size; ++j) { ids[j] = counter; counter++; @@ -199,7 +199,7 @@ ::PopulateFibersAndTensors(vtkPolyData* polyData, curTensor->InsertNextTuple(tmp); } } - const size_t idx = pointData->AddArray(curTensor); + const int idx = static_cast(pointData->AddArray(curTensor)); pointData->SetActiveAttribute(idx,vtkDataSetAttributes::TENSORS); } } @@ -312,8 +312,8 @@ ::Write(const std::string& file_name, // object. vtkPointData *pointData = polyData->GetPointData(); - int num_fibers = fibers.size(); - int num_points = 0; + int num_fibers = static_cast(fibers.size()); + size_t num_points = 0; for( int i = 0; i < num_fibers; ++i ) { num_points += fibers[i].position.size(); @@ -327,8 +327,8 @@ ::Write(const std::string& file_name, norms->SetName("EstimatedUncertainty"); for( int i = 0; i < num_fibers; ++i ) { - int fiber_size = fibers[i].position.size(); - for( int j = 0; j < fiber_size; ++j) + size_t fiber_size = fibers[i].position.size(); + for ( size_t j = 0; j < fiber_size; ++j ) { norms->InsertNextValue(fibers[i].norm[j]); } @@ -349,8 +349,8 @@ ::Write(const std::string& file_name, fa->SetName("FA1"); for( int i = 0; i < num_fibers; ++i ) { - int fiber_size = fibers[i].position.size(); - for( int j = 0; j < fiber_size; ++j ) + size_t fiber_size = fibers[i].position.size(); + for ( size_t j = 0; j < fiber_size; ++j ) { fa->InsertNextValue(fibers[i].fa[j]); } @@ -371,8 +371,8 @@ ::Write(const std::string& file_name, fa2->Allocate(num_points); for( int i = 0; i < num_fibers; ++i ) { - int fiber_size = fibers[i].position.size(); - for( int j = 0; j < fiber_size; ++j ) + size_t fiber_size = fibers[i].position.size(); + for( size_t j = 0; j < fiber_size; ++j ) { fa2->InsertNextValue(fibers[i].fa2[j]); } @@ -393,8 +393,8 @@ ::Write(const std::string& file_name, trace->SetName("trace1"); for( int i = 0; i < num_fibers; ++i ) { - int fiber_size = fibers[i].position.size(); - for( int j = 0; j < fiber_size; ++j ) + size_t fiber_size = fibers[i].position.size(); + for( size_t j = 0; j < fiber_size; ++j ) { trace->InsertNextValue(fibers[i].trace[j]); } @@ -415,8 +415,8 @@ ::Write(const std::string& file_name, trace2->SetName("trace2"); for( int i = 0; i < num_fibers; ++i ) { - int fiber_size = fibers[i].position.size(); - for( int j = 0; j < fiber_size; ++j ) + size_t fiber_size = fibers[i].position.size(); + for( size_t j = 0; j < fiber_size; ++j ) { trace2->InsertNextValue(fibers[i].trace2[j]); } @@ -436,8 +436,8 @@ ::Write(const std::string& file_name, free_water->SetName("FreeWater"); for( int i = 0; i < num_fibers; ++i ) { - int fiber_size = fibers[i].position.size(); - for( int j = 0; j < fiber_size; ++j ) + size_t fiber_size = fibers[i].position.size(); + for( size_t j = 0; j < fiber_size; ++j ) { free_water->InsertNextValue(fibers[i].free_water[j]); } @@ -456,8 +456,8 @@ ::Write(const std::string& file_name, normMSE->SetName("NormalizedSignalEstimationError"); for( int i = 0; i < num_fibers; ++i ) { - int fiber_size = fibers[i].position.size(); - for( int j = 0; j < fiber_size; ++j ) + size_t fiber_size = fibers[i].position.size(); + for( size_t j = 0; j < fiber_size; ++j ) { normMSE->InsertNextValue(fibers[i].normMSE[j]); nmse_sum += fibers[i].normMSE[j]; @@ -552,22 +552,22 @@ int VtkWriter::WriteGlyphs(const std::string& file_name, vtkSmartPointer polyData = vtkSmartPointer::New(); vtkSmartPointer points = vtkSmartPointer::New(); - int num_fibers = fibers.size(); - int num_points = 0; - for( int i = 0; i < num_fibers; ++i ) + size_t num_fibers = fibers.size(); + size_t num_points = 0; + for( size_t i = 0; i < num_fibers; ++i ) { num_points += fibers[i].position.size(); } - int num_tensors = fibers[0].state[0].size() / 5; + size_t num_tensors = fibers[0].state[0].size() / 5; const ukfPrecisionType scale = ukfHalf * _scale_glyphs; - for( int i = 0; i < num_fibers; ++i ) + for( size_t i = 0; i < num_fibers; ++i ) { - int fiber_size = fibers[i].position.size(); - for( int j = 0; j < fiber_size; ++j ) + size_t fiber_size = fibers[i].position.size(); + for( size_t j = 0; j < fiber_size; ++j ) { vec3_t point = fibers[i].position[j]; const State& state = fibers[i].state[j]; @@ -680,7 +680,7 @@ int VtkWriter::WriteGlyphs(const std::string& file_name, // do the lines vtkSmartPointer lines = vtkSmartPointer::New(); - for( int i = 0; i < num_points * num_tensors; ++i ) + for( size_t i = 0; i < num_points * num_tensors; ++i ) { vtkSmartPointer line = vtkSmartPointer::New(); vtkIdType ids[2]; diff --git a/vtk2mask/Converter.cc b/vtk2mask/Converter.cc index 845e087..72a4507 100644 --- a/vtk2mask/Converter.cc +++ b/vtk2mask/Converter.cc @@ -42,7 +42,7 @@ bool Converter::Run() LoadLabel(); if( _bVerbose ) { - std::cout << "Using Label " << (uint)_nLabelOfInterest << " from label file\n"; + std::cout << "Using Label " << (unsigned int)_nLabelOfInterest << " from label file\n"; } } @@ -213,7 +213,7 @@ void Converter::AverageVoxels() current[0] = x; current[1] = y; current[2] = z; - if( (!_bHasLabel || _Label->GetPixel( current) == (uint)_nLabelOfInterest) && _matField->_[x][y][z].size() > 0 ) + if( (!_bHasLabel || _Label->GetPixel( current) == (unsigned int)_nLabelOfInterest) && _matField->_[x][y][z].size() > 0 ) { mean = CalcMean(_matField->_[x][y][z]); _nrrdDataOut->SetPixel( current, mean ); @@ -332,7 +332,7 @@ float Converter::CalcStdDev(const std::vector & vec, const float & mean) { float sum = 0; - for( uint i = 0; i < vec.size(); ++i ) + for(unsigned int i = 0; i < vec.size(); ++i ) { sum += (vec[i] - mean) * (vec[i] - mean); } diff --git a/vtkFilter/vtkWriter.cc b/vtkFilter/vtkWriter.cc index a8b5547..cde30aa 100644 --- a/vtkFilter/vtkWriter.cc +++ b/vtkFilter/vtkWriter.cc @@ -50,8 +50,8 @@ void vtkWriter::SetInputFibers(std::vector & fibers) _fiberLengths.resize(_nNumOfFibers); _nNumOfPoints = 0; - int nCurrSize; - for( int i = 0; i < _nNumOfFibers; ++i ) + size_t nCurrSize; + for( size_t i = 0; i < _nNumOfFibers; ++i ) { nCurrSize = (*_fibers)[i].Points.size(); _fiberLengths[i] = nCurrSize; @@ -78,9 +78,9 @@ void vtkWriter::WritePoints(std::ofstream & output) output << "POINTS " << _nNumOfPoints << " float"; int nCounter = 0; - for( int i = 0; i < _nNumOfFibers; ++i ) + for( size_t i = 0; i < _nNumOfFibers; ++i ) { - for( int j = 0; j < _fiberLengths[i]; ++j ) + for( size_t j = 0; j < _fiberLengths[i]; ++j ) { if( nCounter % 3 == 0 ) { @@ -106,10 +106,10 @@ void vtkWriter::WriteLines(std::ofstream & output) output << _nNumOfFibers << " " << _nNumOfFibers + _nNumOfPoints << std::endl; int counter = 0; - for( int i = 0; i < _nNumOfFibers; ++i ) + for( size_t i = 0; i < _nNumOfFibers; ++i ) { output << _fiberLengths[i]; - for( int j = 0; j < _fiberLengths[i]; ++j ) + for( size_t j = 0; j < _fiberLengths[i]; ++j ) { output << " " << counter++; } @@ -131,9 +131,9 @@ void vtkWriter::WriteFields(std::ofstream & output) output << cit->first; output << " 1 " << _nNumOfPoints; output << " float" << std::endl; - for( int i = 0; i < _nNumOfFibers; ++i ) + for( size_t i = 0; i < _nNumOfFibers; ++i ) { - for( int j = 0; j < _fiberLengths[i]; ++j ) + for( size_t j = 0; j < _fiberLengths[i]; ++j ) { output << (*_fibers)[i].Fields[cit->first][j]; nCounter++; diff --git a/vtkFilter/vtkWriter.h b/vtkFilter/vtkWriter.h index b07c0dd..7872e3b 100644 --- a/vtkFilter/vtkWriter.h +++ b/vtkFilter/vtkWriter.h @@ -49,16 +49,16 @@ class vtkWriter std::vector * _fibers; /** Number of points of all fibers */ - int _nNumOfPoints; + size_t _nNumOfPoints; /** Number of fibers */ - int _nNumOfFibers; + size_t _nNumOfFibers; /** Number of scalar fields of the fiber */ - int _nNumOfFields; + size_t _nNumOfFields; /** The respective lengths of each fiber */ - std::vector _fiberLengths; + std::vector _fiberLengths; /** Write the top line of the vtk file */ void WriteHeader(std::ofstream & output);