У меня есть следующий проект в CMake 3.14.0, который создает проект для 64-разрядного генератора Visual Studio 2017 (минимальная версия - 3.10.0, потому что другие разработчики могут иметь предыдущие версии CMake, но больше 3.9.0). :
cmake_minimum_required (VERSION 3.10.0)
project (data)
add_definitions (-DDATA_EXPORTS)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
set (PROJECT_SRC
Player.cpp
LLA.cpp
Attitude.cpp
)
add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
target_compile_features (${PROJECT_NAME} PUBLIC cxx_std_17)
# Enable IPO
include(CheckIPOSupported)
check_ipo_supported(RESULT iporesult)
if(iporesult)
message (STATUS "IPO supported for project ${PROJECT_NAME}")
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
Я добавил несколько команд для добавления поддержки LTO в Visual Studio. Я видел, что я должен проверить поддержку IPO и, если все в порядке, я должен установить свойство INTERPROCEDURAL_OPTIMIZATION
, это то, что я сделал
Когда я запускаю проект, я получаю следующее сообщение (я также использую vcpkg, и в этом причина первой строки):
[cmake] IPO supported for project data
...
[cmake] CMake Warning (dev) at D:/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake:198 (_add_library):
[cmake] Policy CMP0069 is not set: INTERPROCEDURAL_OPTIMIZATION is enforced when
[cmake] enabled. Run "cmake --help-policy CMP0069" for policy details. Use the
[cmake] cmake_policy command to set the policy and suppress this warning.
[cmake]
[cmake] INTERPROCEDURAL_OPTIMIZATION property will be ignored for target 'data'.
[cmake] Call Stack (most recent call first):
[cmake] src/Data/CMakeLists.txt:18 (add_library)
[cmake] This warning is for project developers. Use -Wno-dev to suppress it.
Насколько я видел, оптимизация времени соединения не включена для проекта. Я также открыл проект в Visual Studio и проверил командную строку проекта, и вот результат для сборки:
/GS /TP /W3 /Zc:wchar_t /I"M:\project\src\Data\.." /Zi /Gm- /Od /Ob0 /Fd"data.dir\Debug\vc141.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_WINDOWS" /D "DATA_EXPORTS" /D "CMAKE_INTDIR=\"Debug\"" /D "data_EXPORTS" /D "_WINDLL" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /MDd /std:c++17 /Fa"Debug/" /EHsc /nologo /Fo"data.dir\Debug\" /Fp"data.dir\Debug\data.pch" /diagnostics:classic
и для связи
/OUT:"M:\project\build\vscode\build\bin\Debug\data.dll" /MANIFEST /NXCOMPAT /PDB:"M:/project/build/vscode/build/bin/Debug/data.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" /IMPLIB:"M:/project/build/vscode/build/lib/Debug/data.lib" /DEBUG /DLL /MACHINE:X64 /INCREMENTAL /PGD:"M:\project\build\vscode\build\bin\Debug\data.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"data.dir\Debug\data.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
Я не вижу флагов для LTO.
Я выполнил команду для политики, и вот результат:
cmake --help-policy CMP0069
CMP0069
-------
``INTERPROCEDURAL_OPTIMIZATION`` is enforced when enabled.
CMake 3.9 and newer prefer to add IPO flags whenever the
``INTERPROCEDURAL_OPTIMIZATION`` target property is enabled and
produce an error if flags are not known to CMake for the current compiler.
Since a given compiler may not support IPO flags in all environments in which
it is used, it is now the project's responsibility to use the
``CheckIPOSupported`` module to check for support before enabling the
``INTERPROCEDURAL_OPTIMIZATION`` target property. This approach
allows a project to conditionally activate IPO when supported. It also
allows an end user to set the ``CMAKE_INTERPROCEDURAL_OPTIMIZATION``
variable in an environment known to support IPO even if the project does
not enable the property.
Since CMake 3.8 and lower only honored ``INTERPROCEDURAL_OPTIMIZATION``
for the Intel compiler on Linux, some projects may unconditionally enable the
target property. Policy ``CMP0069`` provides compatibility with such projects.
This policy takes effect whenever the IPO property is enabled. The ``OLD``
behavior for this policy is to add IPO flags only for Intel compiler on Linux.
The ``NEW`` behavior for this policy is to add IPO flags for the current
compiler or produce an error if CMake does not know the flags.
This policy was introduced in CMake version 3.9. CMake version
3.14.0 warns when the policy is not set and uses ``OLD`` behavior.
Use the ``cmake_policy()`` command to set it to ``OLD`` or ``NEW``
explicitly.
.. note::
The ``OLD`` behavior of a policy is
``deprecated by definition``
and may be removed in a future version of CMake.
Examples
^^^^^^^^
Behave like CMake 3.8 and do not apply any IPO flags except for Intel compiler
on Linux:
cmake_minimum_required(VERSION 3.8)
project(foo)
# ...
set_property(TARGET ... PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
Use the ``CheckIPOSupported`` module to detect whether IPO is
supported by the current compiler, environment, and CMake version.
Produce a fatal error if support is not available:
cmake_minimum_required(VERSION 3.9) # CMP0069 NEW
project(foo)
include(CheckIPOSupported)
check_ipo_supported()
# ...
set_property(TARGET ... PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
Apply IPO flags only if compiler supports it:
cmake_minimum_required(VERSION 3.9) # CMP0069 NEW
project(foo)
include(CheckIPOSupported)
# ...
check_ipo_supported(RESULT result)
if(result)
set_property(TARGET ... PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
Apply IPO flags without any checks. This may lead to build errors if IPO
is not supported by the compiler in the current environment. Produce an
error if CMake does not know IPO flags for the current compiler:
cmake_minimum_required(VERSION 3.9) # CMP0069 NEW
project(foo)
# ...
set_property(TARGET ... PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
Кажется, я правильно его использую.
Я не понимаю, почему свойство не применяется, если команда check_ipo_supported
рассказывает мне другую историю.
Что я делаю не так?