How to Switch to Static Runtime on Command Line?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to Switch to Static Runtime on Command Line?

Osman Zakir
Hi. 

I'm trying to build LLVM 10.0.0 with CMake on the command line (Developer Command Prompt for VS2019) and I need to know how to switch to a static runtime.  I've tried specifying LLVM's variable for this, but it didn't work.  I still have a dynamic runtime.  Along with that, I also need to know how to enable C++ exceptions.  

One thing I tried was to do "-DCMAKE_CXX_FLAGS="/std:c++17 /MT /EHsc /permissive-"" but this also didn't work.  Specifying these on the CXXFLAGS environment variable didn't do anything either.  I was using the same session of the Developer Command Prompt, but I made sure to run "refreshenv" to take the new environment from the registry before continuing.  

Note: I don't want to edit the CMakeLists.txt file because I want to be able to run "git pull" without having to stage any changes (I cloned the LLVM GitHub repository for the source code).  

Any help is appreciated.  Thanks in advance.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Mateusz Loskot
On Mon, 28 Oct 2019 at 12:01, Osman Zakir <[hidden email]> wrote:
>
> I'm trying to build LLVM 10.0.0 with CMake on the command line (Developer Command Prompt for VS2019)
> and I need to know how to switch to a static runtime.

This may help (CMake 3.15 or later only):

https://cmake.org/cmake/help/latest/policy/CMP0091.html
https://cmake.org/cmake/help/v3.15/prop_tgt/MSVC_RUNTIME_LIBRARY.html

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Osman Zakir
Thanks for the reply.  

What about enabling C++ exceptions?  

And I should do "-DCMAKE_MSVC_RUNTIME_LIBRARY=/MT" to set the runtime type to static, right?

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Osman Zakir
In reply to this post by Mateusz Loskot
I tried "-DCMAKE_MSVC_RUNTIME_LIBRARY=MT" and also "-DCMAKE_MSVC_RUNTIME_LIBRARY=/MT" before that, along with "-DCMAKE_BUILD_TYPE=Release", but I still get "Using Release VC++ CRT: MD".  What's going on?  I also did "-DCMAKE_CXX_FLAGS="/permissive- /EHsc /std:c++17 /O2 /MT /D_SILENCE_ALL_CXX_DEPRECATION_WARNINGS"" but this also didn't help.  Do you have any ideas?

The command I ran was "cmake -S../llvm -G"Visual Studio 16 2019" -Thost=x64 -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY=MT -DCMAKE_CXX_FLAGS="/permissive- /EHsc /std:c++17 /O2 /MT /D_SILENCE_ALL_CXX_DEPRECATION_WARNINGS" -DLLVM_ENABLE_RTTI=On -DLLVM_ENABLE_EH=ON -DCMAKE_CXX_STANDARD=17 -DPYTHON_HOME=C:/Users/Osman/AppData/Local/Programs/Python/Python38 -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;libcxx;libcxxabi"".  

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Mateusz Loskot
In reply to this post by Osman Zakir
On Mon, 28 Oct 2019 at 12:22, Osman Zakir <[hidden email]> wrote:
>
> And I should do "-DCMAKE_MSVC_RUNTIME_LIBRARY=/MT"

Man, read the docs I pasted!!!
https://cmake.org/cmake/help/v3.15/prop_tgt/MSVC_RUNTIME_LIBRARY.html

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Osman Zakir
Okay, actually I can't enable a static runtime for LLVM on the command line.  I was told about a patch I need to apply.  

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Eric Doenges
In reply to this post by Mateusz Loskot

I think it is worth adding to what Mateusz wrote that the MSVC_RUNTIME_LIBRARY property / CMAKE_MSVC_RUNTIME_LIBRARY variable are only available if policy CMP0091 is set to NEW, which it will not be because LLVM's CMakeLists.txt only requires CMake 3.4.3 or later (and thus all policies introduced after 3.4.3 are set to OLD for compatibility). So if you do not want to edit LLVM's CMakeLists.txt, you need to use the options provided by LLVM's CMake project to control the build.

We select the CRT LLVM's libraries will use with the LLVM_USE_CRT_DEBUG and LLVM_USE_CRT_RELEASE options, i.e. to build with a static MSVC runtime we use

-DLLVM_USE_CRT_DEBUG=MTd -DLLVM_USE_CRT_RELEASE=MT

These options are not documented on the "Building LLVM with CMake" page, but can be found by looking into LLVM's cmake directory.

Am 28.10.19 um 12:53 schrieb Mateusz Loskot:
On Mon, 28 Oct 2019 at 12:22, Osman Zakir [hidden email] wrote:
And I should do "-DCMAKE_MSVC_RUNTIME_LIBRARY=/MT"
Man, read the docs I pasted!!!
https://cmake.org/cmake/help/v3.15/prop_tgt/MSVC_RUNTIME_LIBRARY.html

Best regards,
--

Dr. Eric Dönges
Senior Software Engineer

MVTec Software GmbH | Arnulfstr. 205 | 80634 Munich | Germany
[hidden email] | Tel: +49 89 457 695-0 | www.mvtec.com

Find our privacy policy here.

 Sign up for our MVTec Newsletter!

Geschäftsführer: Dr. Wolfgang Eckstein, Dr. Olaf Munkelt
Amtsgericht München HRB 114695

 

MVTec Software GmbH Logo

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Mateusz Loskot
In reply to this post by Mateusz Loskot
On Mon, 28 Oct 2019 at 13:09, Osman Zakir <[hidden email]> wrote:
>
> I did read that.
> I tried to specify CMAKE_MSVC_RUNTIME_LIBRARY and MSVC_RUNTIME_LIBRARY as /MT, -MT and MT, but nothing worked.

I'm sorry, but that confirms you did not read that document.

Hint 1: "The allowed values are"

Hint 2: In CMake, for XXX property there is a corresponding variable
https://cmake.org/cmake/help/v3.15/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Mateusz Loskot
In reply to this post by Eric Doenges
On Mon, 28 Oct 2019 at 13:23, Eric Doenges <[hidden email]> wrote:

I think it is worth adding to what Mateusz wrote that the MSVC_RUNTIME_LIBRARY property / CMAKE_MSVC_RUNTIME_LIBRARY variable are only available if policy CMP0091 is set to NEW


Yes, indeed. FWIW, it is also documented in the frame "Note" on docs page of the property/variable.

Best regards,
--

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Eric Doenges
In reply to this post by Eric Doenges

By default, CMake will use /EHsc when compiling for the Windows platform, with no option to change this that I am aware of. If a project wants different settings, it needs to handle this itself. And in fact, LLVM 3.4.2 conditionally modifies /EHsc to /EHs-c- in cmake/modules/LLVMProcessSources.cmake, so I wouldn't be surprised if LLVM 10.0.0 does something similar (I don't have a more recent version of LLVM lying about, so I can't check).


To figure out what option(s) you need to set or what files you need to modify, you either need to ask the LLVM developers, or dig through the LLVM cmake project to figure out what it is doing with the /EHsc option.


Am 28.10.19 um 13:33 schrieb Osman Zakir:
Alright, thanks.  What about enabling C++ exceptions?  I tried setting LLVM_ENABLE_EH to On, but it didn't help.  Setting CMAKE_CXX_FLAGS to /EHsc doesn't help either.  
--

Dr. Eric Dönges
Senior Software Engineer

MVTec Software GmbH | Arnulfstr. 205 | 80634 Munich | Germany
[hidden email] | Tel: +49 89 457 695-0 | www.mvtec.com

Find our privacy policy here.

 Sign up for our MVTec Newsletter!

Geschäftsführer: Dr. Wolfgang Eckstein, Dr. Olaf Munkelt
Amtsgericht München HRB 114695

 

MVTec Software GmbH Logo

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to Switch to Static Runtime on Command Line?

Juan Sanchez
In reply to this post by Osman Zakir
Hello,

It has been a while since I've looked at this stuff, but I do use exceptions in my project.  So I add the /EHsc: 
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:strict /EHsc ${WARNINGS_IGNORE}")
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fp:strict ${WARNINGS_IGNORE}")

and I also add a linker flag:
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB:python3")
SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")

According to the M$ documentation, SAFESEH is relevant for x86, but not x64:

In order to change runtimes, I have also had to enable defaultlib's in case they got in through other libraries or header files:
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCMT")

According to this instruction you can disable all of the libraries you do not want:

For example, above I had to do:
/NODEFAULTLIB:python3

because the Python header files in my project were force linking the wrong library.

Regards









On Mon, Oct 28, 2019 at 6:02 AM Osman Zakir <[hidden email]> wrote:
Hi. 

I'm trying to build LLVM 10.0.0 with CMake on the command line (Developer Command Prompt for VS2019) and I need to know how to switch to a static runtime.  I've tried specifying LLVM's variable for this, but it didn't work.  I still have a dynamic runtime.  Along with that, I also need to know how to enable C++ exceptions.  

One thing I tried was to do "-DCMAKE_CXX_FLAGS="/std:c++17 /MT /EHsc /permissive-"" but this also didn't work.  Specifying these on the CXXFLAGS environment variable didn't do anything either.  I was using the same session of the Developer Command Prompt, but I made sure to run "refreshenv" to take the new environment from the registry before continuing.  

Note: I don't want to edit the CMakeLists.txt file because I want to be able to run "git pull" without having to stage any changes (I cloned the LLVM GitHub repository for the source code).  

Any help is appreciated.  Thanks in advance.
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake