Vcpkg: passing same options (-ffunction-sections, -fdata-sections, etc) to every port

Created on 17 Jul 2019  路  6Comments  路  Source: microsoft/vcpkg

Is there a way to build every port with a certain option?

In particular, for x64-linux triplet (which builds everything as static lib) I need -ffunction-sections -fdata-sections -flto to be used everywhere (to reduce size of my final binary).

question

Most helpful comment

You can use VCPKG_C_FLAGS* VCPKG_CXX_FLAGS* VCPKG_LINKER_FLAGS* variables in you custom triplet files. Here how I do lto on linux:

set(VCPKG_CXX_FLAGS_RELEASE -flto)
set(VCPKG_C_FLAGS_RELEASE -flto)
set(VCPKG_LINKER_FLAGS_RELEASE -flto)

and on windows:

set(VCPKG_CXX_FLAGS_RELEASE "/GL /Gw /GS-")
set(VCPKG_C_FLAGS_RELEASE "/GL /Gw /GS-")
set(VCPKG_LINKER_FLAGS_RELEASE "/OPT:ICF=3 /LTCG")

There is an issue #7159 with multiple flags in boost, with fix #7160

All 6 comments

You can use VCPKG_C_FLAGS* VCPKG_CXX_FLAGS* VCPKG_LINKER_FLAGS* variables in you custom triplet files. Here how I do lto on linux:

set(VCPKG_CXX_FLAGS_RELEASE -flto)
set(VCPKG_C_FLAGS_RELEASE -flto)
set(VCPKG_LINKER_FLAGS_RELEASE -flto)

and on windows:

set(VCPKG_CXX_FLAGS_RELEASE "/GL /Gw /GS-")
set(VCPKG_C_FLAGS_RELEASE "/GL /Gw /GS-")
set(VCPKG_LINKER_FLAGS_RELEASE "/OPT:ICF=3 /LTCG")

There is an issue #7159 with multiple flags in boost, with fix #7160

@crusader-mike please use the method suggested by @isanych, that is the intended way to pass flags to the build.

It looks like I'll have to wait for PR #7160 to be merged, but it looks like it is almost there.

Thank you, guys!

Hmm... All logs are littered with "plugin needed to handle lto" messages. Somehow I need to force vcpkg to use gcc-ranlib/gcc-ar instead of ranlib/ar:

[1/15] /opt/rh/devtoolset-8/root/usr/bin/cc  -I. -fPIC -flto -fno-fat-lto-objects  -O3 -DNDEBUG   -include /home/user/vcpkg/buildtrees/libuuid/x64-linux-rel/config.h -MD -MT CMakeFiles/uuid.dir/isnull.c.o -MF CMakeFiles/uuid.dir/isnull.c.o.d -o CMakeFiles/uuid.dir/isnull.c.o   -c /home/user/vcpkg/buildtrees/libuuid/src/libuuid-1.0.3/isnull.c

...
/opt/rh/devtoolset-8/root/usr/bin/ar: CMakeFiles/uuid.dir/unpack.c.o: plugin needed to handle lto object
/opt/rh/devtoolset-8/root/usr/bin/ar: CMakeFiles/uuid.dir/unparse.c.o: plugin needed to handle lto object
/opt/rh/devtoolset-8/root/usr/bin/ar: CMakeFiles/uuid.dir/uuid_time.c.o: plugin needed to handle lto object
/opt/rh/devtoolset-8/root/usr/bin/ranlib: libuuid.a(clear.c.o): plugin needed to handle lto object
/opt/rh/devtoolset-8/root/usr/bin/ranlib: libuuid.a(compare.c.o): plugin needed to handle lto object
/opt/rh/devtoolset-8/root/usr/bin/ranlib: libuuid.a(copy.c.o): plugin needed to handle lto object
/opt/rh/devtoolset-8/root/usr/bin/ranlib: libuuid.a(gen_uuid.c.o): plugin needed to handle lto object
...

Any ideas?

Is it possible to set this globally during vcpkg build:

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)

?

FYI: VCPKG_LINKER_FLAGS_RELEASE seems to be practically unused in vcpkg (which is fine for x64-linux, since it produces static libs only).

Was this page helpful?
0 / 5 - 0 ratings