I've been trying to build gflags using vcpkg. I know you can getting using vcpkg install gflags
The problem is that aparently I need to build it with component shared. this is the error I'm getting when I run cmake with -DCMAKE_TOOLCHAIN_FILE=D:\MTC_source_code\vcpkg\scripts\buildsystems\vcpkg.cmake
CMake Error at D:/src/vcpkg/installed/x64-windows/share/gflags/gflags-config.cmake:40 (message):
Package gflags was installed without required component shared!
I notice that if I build gflags from scratch and then install it I get the correct behavior. I installed it from source in the following way.
git clone https://github.com/gflags/gflags.git
cd gflags
mkdir _build
cd _build
cmake .. -G "NMake Makefiles" -DGFLAGS_BUILD_SHARED_LIBS="ON" -DBUILD_SHARED_LIBS="ON"
nmake
nmake install/local
That gets rid of the component shared issue.
I try to replicate this in vcpkg by creating a port overlay for gflags, I tried two things:
- Modifying portfile.cmake to reflect the needed flags:
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DGFLAGS_REGISTER_BUILD_DIR:BOOL=OFF
-DGFLAGS_REGISTER_INSTALL_PREFIX:BOOL=OFF
-DBUILD_gflags_nothreads_LIB:BOOL=ON
-DGFLAGS_USE_TARGET_NAMESPACE:BOOL=ON
-DCMAKE_DEBUG_POSTFIX=d
-DGFLAGS_BUILD_SHARED_LIBS="ON"
-DBUILD_SHARED_LIBS="ON"
)
But this didnt solve the issue.
- I then tried to create a patch, and apply it to portfile.cmake and it didnt work either.
Content of the patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 53e77cb..17faeb4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -93,7 +93,8 @@ set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set (PACKAGE_BUGREPORT "https://github.com/gflags/gflags/issues")
set (PACKAGE_DESCRIPTION "A commandline flags library that allows for distributed flags.")
set (PACKAGE_URL "http://gflags.github.io/gflags")
-
+set (GFLAGS_BUILD_SHARED_LIBS "ON")
+set (BUILD_SHARED_LIBS "ON")
project (${PACKAGE_NAME} VERSION ${PACKAGE_VERSION} LANGUAGES CXX)
if (CMAKE_VERSION VERSION_LESS 3.4)
# C language still needed because the following required CMake modules
It still fails with:
CMake Error at D:/src/vcpkg/installed/x64-windows/share/gflags/gflags-config.cmake:40 (message):
Package gflags was installed without required component shared!
Interestingly enough, if I find the gflags folder in the vcpkg archives (vcpkg\buildtrees\gflags\src\v2.2.2-d9283b9285), dont modify anything and then build using:
mkdir _build
cd _build
cmake .. -G "NMake Makefiles"
nmake
nmake install/local
it works, it seems like it only fails when built and installed from vcpkg.
What am I missing to get what I require?
vcpkg sets
-DBUILD_SHARED_LIBS="ON"
on its own depending onVCPKG_LIBRARY_LINKAGE
withinvcpkg_cmake_configure
. Since it is added afterOPTIONS
in the portfile it will simply overrule the setting. You can either changeVCPKG_LIBRARY_LINKAGE
to static within the portfile/triplet or useVCPKG_CMAKE_CONFIGURE_OPTIONS
to force your setting.