diff --git a/UserMacros.cmake b/UserMacros.cmake index d7d3ef9b21..bf609e5bed 100644 --- a/UserMacros.cmake +++ b/UserMacros.cmake @@ -3,15 +3,34 @@ ######################################################## #----------------------------------------------------------------------------- -# Option to Build with User Defined Values -#----------------------------------------------------------------------------- -MACRO (MACRO_USER_DEFINED_LIBS) - SET (USER_DEFINED_VALUE "FALSE") -ENDMACRO (MACRO_USER_DEFINED_LIBS) - +# Option to Build with Static CRT libraries on Windows #------------------------------------------------------------------------------- -OPTION (BUILD_USER_DEFINED_LIBS "Build With User Defined Values" OFF) -IF (BUILD_USER_DEFINED_LIBS) - MACRO_USER_DEFINED_LIBS () -ENDIF (BUILD_USER_DEFINED_LIBS) +MACRO (TARGET_STATIC_CRT_FLAGS) + IF (MSVC AND NOT BUILD_SHARED_LIBS) + FOREACH (flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + IF (${flag_var} MATCHES "/MD") + STRING (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") + ENDIF (${flag_var} MATCHES "/MD") + ENDFOREACH (flag_var) + FOREACH (flag_var + CMAKE_Fortran_FLAGS CMAKE_Fortran_FLAGS_DEBUG CMAKE_Fortran_FLAGS_RELEASE + CMAKE_Fortran_FLAGS_MINSIZEREL CMAKE_Fortran_FLAGS_RELWITHDEBINFO) + IF (${flag_var} MATCHES "/libs:dll") + STRING (REGEX REPLACE "/libs:dll" "/libs:static" ${flag_var} "${${flag_var}}") + ENDIF (${flag_var} MATCHES "/libs:dll") + ENDFOREACH (flag_var) + SET (WIN_COMPILE_FLAGS "/MT") + SET (WIN_LINK_FLAGS "/NODEFAULTLIB:MSVCRT") + ENDIF (MSVC AND NOT BUILD_SHARED_LIBS) +ENDMACRO (TARGET_STATIC_CRT_FLAGS) + +#----------------------------------------------------------------------------- +OPTION (BUILD_STATIC_CRT_LIBS "Build With Static CRT Libraries" OFF) +IF (BUILD_STATIC_CRT_LIBS) + TARGET_STATIC_CRT_FLAGS () +ENDIF (BUILD_STATIC_CRT_LIBS) \ No newline at end of file diff --git a/config/cmake/HDFMacros.cmake b/config/cmake/HDFMacros.cmake index e9e9665f7d..1a2d11bda3 100644 --- a/config/cmake/HDFMacros.cmake +++ b/config/cmake/HDFMacros.cmake @@ -132,7 +132,7 @@ MACRO (TARGET_C_PROPERTIES wintarget addcompileflags addlinkflags) LINK_FLAGS "${addlinkflags}" ) ELSE (BUILD_SHARED_LIBS) - SET_TARGET_PROPERTIES (${forttarget} + SET_TARGET_PROPERTIES (${wintarget} PROPERTIES COMPILE_FLAGS "${addcompileflags}" LINK_FLAGS "${addlinkflags}" @@ -151,7 +151,7 @@ MACRO (TARGET_MSVC_PROPERTIES wintarget addcompileflags addlinkflags) LINK_FLAGS "/SUBSYSTEM:CONSOLE ${addlinkflags}" ) ELSE (BUILD_SHARED_LIBS) - SET_TARGET_PROPERTIES (${forttarget} + SET_TARGET_PROPERTIES (${wintarget} PROPERTIES COMPILE_FLAGS "${addcompileflags}" LINK_FLAGS "/SUBSYSTEM:CONSOLE ${addlinkflags}"