How to set BUILD_SHARED_LIBS for an included directory

I have a very simple CMake project that uses Google Test. I want to build it as a dll, and the CMakeLists.txt file in gtest indicates what BUILD_SHARED_LIBS

needs to be installed in order for gtest to be built as a shared library.

My problem is that I cannot figure out how to set BUILD_SHARED_LIBS

it to appear. If I use cmake-gui, set the value in the cache, then I can actually see that the generated build attempt created the dll.

Below is my CMakeLists.txt. I would appreciate any suggestions on how to set its BUILD_SHARED_LIBS.

CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR)
PROJECT(MyProj)
SET(BUILD_SHARED_LIBS ON)
ADD_EXECUTABLE(MyProj main.cpp)
ADD_LIBRARY(MyLib STATIC mylib.cpp)
TARGET_LINK_LIBRARIES(MyProj MyLib)
ADD_SUBDIRECTORY(gtest-1.7.0)

      


Google Test will only build as a shared library (DLL) if BUILD_SHARED_LIBS is set. So I want to set this in this CmakeLists.txt file. I know how to make my own library available, but I cannot figure out how to set this variable so that the gtestLists.txt file sees it.

+3


source to share


1 answer


In your code

 ADD_LIBRARY(MyLib STATIC mylib.cpp) // Your code STATIC lib

      



Go to this line

 ADD_LIBRARY(MyLib SHARED mylib.cpp)  // Shared Lib is added

      

+1


source







All Articles