Skip to content

Commit

Permalink
add static linking CMake setup for MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
j-schultz committed Mar 5, 2024
1 parent ab4e835 commit 18cd6d4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ get_package_version(PACKAGE_VERSION PROJECT_VERSION)

project(Opus LANGUAGES C VERSION ${PROJECT_VERSION})

if(MSVC)
option(MSVC_LINK_STATIC_RUNTIME "Use static linking of msvc runtime" OFF)
endif()

# switch from dynamic to static linking
if(MSVC AND MSVC_LINK_STATIC_RUNTIME)
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)

if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()

include(OpusFunctions)
include(OpusBuildtype)
include(OpusConfig)
Expand Down

0 comments on commit 18cd6d4

Please sign in to comment.