Open Tradias opened 1 year ago
cmake_minimum_required(VERSION 3.10)
project(libzmq)
# Option to enable link-time optimization (LTCG) and whole program optimization (GL)
option(ZMQ_ENABLE_LTO "Enable link-time optimization (LTCG) and whole program optimization (GL)" OFF)
# Add the necessary flags based on the option
if (BUILD_SHARED)
if (ZMQ_ENABLE_LTO)
add_compile_options("/GL")
add_link_options("/LTCG")
endif()
endif()
# Your other CMake configuration code...
# Check for build type and set IPO if enabled
if (CMAKE_BUILD_TYPE STREQUAL "Release")
if (ZMQ_ENABLE_LTO)
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${CMAKE_INTERPROCEDURAL_OPTIMIZATION})
endif()
endif()
Issue description
When building through CMake with MSVC,
BUILD_SHARED=on
andCMAKE_BUILD_TYPE != Debug
then /GL and /LTCG are automatically added to the compilation. This forces consumers to also link their application with /LTCG which is not always desired. Recommendation: Allow users to choose link-time optimization themselves, e.g. by setting CMAKE_INTERPROCEDURAL_OPTIMIZATION.Environment
Minimal test code / Steps to reproduce the issue
What's the actual result? (include assertion message & call stack if applicable)
What's the expected result?
Nothing