C.M.
C.M.

Reputation: 3383

How to add a compiler option to every port being built?

Is there a way to add a compiler option to every vcpkg port being built?

In particular I need every port to be compiled with -fdata-section -ffunction-section -flto in my Linux vcpkg instance.

Upvotes: 1

Views: 3013

Answers (1)

C.M.
C.M.

Reputation: 3383

Kudos to "isanych" (see this):

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.

Note: as of now VCPKG_LINKER_FLAGS_RELEASE isn't being used particularly wide amongst ports.

Upvotes: 1

Related Questions