Skip to content

Commit

Permalink
Fix for MS Win build
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinat Mukhometzianov committed Jun 28, 2019
1 parent d0fbb14 commit 5769afe
Show file tree
Hide file tree
Showing 23 changed files with 282 additions and 219 deletions.
21 changes: 15 additions & 6 deletions CMake/ITKSetStandardCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
)
Expand Down Expand Up @@ -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}")
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 ``<PackageName>_ROOT`` variables.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Common.cmake
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
278 changes: 146 additions & 132 deletions SuperBuild/External_Boost.cmake
Original file line number Diff line number Diff line change
@@ -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"
)
2 changes: 1 addition & 1 deletion SuperBuild/External_Eigen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading

0 comments on commit 5769afe

Please sign in to comment.