[pcre-dev] [Bug 1681] New: CMake compiles PCRE dynamically e…

Top Page
Delete this message
Author: admin
Date:  
To: pcre-dev
New-Topics: [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static, [pcre-dev] [Bug 1681] CMake compiles PCRE dynamically even when set to static
Subject: [pcre-dev] [Bug 1681] New: CMake compiles PCRE dynamically even when set to static
https://bugs.exim.org/show_bug.cgi?id=1681

            Bug ID: 1681
           Summary: CMake compiles PCRE dynamically even when set to
                    static
           Product: PCRE
           Version: 8.37
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: bug
          Priority: medium
         Component: Code
          Assignee: ph10@???
          Reporter: chris+exim@???
                CC: pcre-dev@???


Created attachment 833
--> https://bugs.exim.org/attachment.cgi?id=833&action=edit
CMake configuration file to enable static runtime

The CMake configuration allows building a "static library", but this is
compiled by MSVC with the "/MD" (DLL) option, so it uses the dynamic runtime
instead of static, which makes it impossible to produce a fully static binary
as output.

The solution is to modify the CMAKE_C_FLAGS when building statically. This
seems to be a well-known limitation of CMake:

http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
http://www.cmake.org/pipermail/cmake/2010-January/034592.html
https://raw.githubusercontent.com/webmproject/libwebm/master/build/msvc_runtime.cmake
http://stackoverflow.com/questions/16212682/why-does-this-cmake-project-not-set-the-appropriate-msvc-runtime

I added the following file as cmake/msvc_runtime.cmake (derived from the WebM
file linked above):

## Copyright (c) 2015 The WebM project authors. All Rights Reserved.
##
## Use of this source code is governed by a BSD-style license
## that can be found in the LICENSE file in the root of the source
## tree. An additional intellectual property rights grant can be found
## in the file PATENTS. All contributing project authors may
## be found in the AUTHORS file in the root of the source tree.
cmake_minimum_required(VERSION 2.8)

if(WIN32)
  # CMake defaults to producing code linked to the DLL MSVC runtime. In libwebm
  # static is typically desired. Force static code generation unless the user
  # running CMake set MSVC_RUNTIME to dll.
  if(PCRE_STATIC)
    message(STATUS "MSVC -> forcing use of statically-linked runtime.")
    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)


      string(REPLACE "/MD " "/MT " ${flag_var} "${${flag_var}}")
      string(REPLACE "/MDd " "/MTd " ${flag_var} "${${flag_var}}")
    endforeach(flag_var)
  endif(PCRE_STATIC)
endif(WIN32)


And then added the following line to CMakeLists.txt after "ENDIF(NOT
BUILD_SHARED_LIBS)":

INCLUDE(msvc_runtime)

Thanks for your consideration!

--
You are receiving this mail because:
You are on the CC list for the bug.