Unidata / UDUNITS-2

API and utility for arithmetic manipulation of units of physical quantities
http://www.unidata.ucar.edu/software/udunits
Other
62 stars 36 forks source link

option for static CRT linking on MSCV #54

Open pedro-vicente opened 6 years ago

pedro-vicente commented 6 years ago

Could you add an option to link with static CRT

https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx

this avoids shipping/dependency of Microsoft DLLs

this can be done in CMake with

#//////////////////////////
#compile as C++/static CRT on Visual Studio 
#//////////////////////////

set(MSVC_USE_STATIC_CRT off CACHE BOOL "Use MT flags when compiling in MSVC")
if (MSVC)
  if (MSVC_USE_STATIC_CRT)
     message("-- Using static CRT linking ${MSVC_USE_STATIC_CRT}")
     foreach(flag_var CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
                          CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
                          CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
                          CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
       string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
     endforeach()
  endif()
endif()

an option of the package is to use static CRT

I set up a repository that lists all the dependencies

https://github.com/pedro-vicente/nco_bld

zlib
szip
hdf5
curl
netcdf
expat
udunits
gsl
antlr

for each one, the CMake support for static CRT varies from

non existing
existing as non default
existing as default ( for GSL)

if Microsoft includes static CRT as an option, the CMake scripts should allow us to choose also

the reason being the shipped final package with static CRT does not need any additional DLLs. The end user of the software might or might not have those DLLs installed, we don't know. If they don't, the package is broken