From bdd11030c2f74c1d912658e2e4f86b2775ca21e7 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sun, 1 May 2016 12:56:09 +0200 Subject: [PATCH] minor cmake improvements on windows --- CMakeLists.txt | 24 +++++++++++++----------- docs/cmake.rst | 24 +++++++++++++----------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4440b904..1a344bda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,17 +148,19 @@ endforeach() if (WIN32) if (MSVC) - # /bigobj is needed for bigger binding projects due to the limit to 64k - # addressable sections. /MP enables multithreaded builds (relevant when - # there are many files). - set_target_properties(example PROPERTIES COMPILE_FLAGS "/MP /bigobj ") - - if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG) - # Enforce size-based optimization and link time code generation on MSVC - # (~30% smaller binaries in experiments). - set_target_properties(example APPEND_STRING PROPERTY COMPILE_FLAGS "/Os /GL ") - set_target_properties(example APPEND_STRING PROPERTY LINK_FLAGS "/LTCG ") - endif() + # /MP enables multithreaded builds (relevant when there are many files), /bigobj is + # needed for bigger binding projects due to the limit to 64k addressable sections + set_property(TARGET example APPEND PROPERTY COMPILE_OPTIONS /MP /bigobj) + # Enforce size-based optimization and link time code generation on MSVC + # (~30% smaller binaries in experiments); do nothing in debug mode. + set_property(TARGET example APPEND PROPERTY COMPILE_OPTIONS + "$<$:/Os>" "$<$:/GL>" + "$<$:/Os>" "$<$:/GL>" + "$<$:/Os>" "$<$:/GL>" + ) + set_property(TARGET example APPEND_STRING PROPERTY LINK_FLAGS_RELEASE "/LTCG ") + set_property(TARGET example APPEND_STRING PROPERTY LINK_FLAGS_MINSIZEREL "/LTCG ") + set_property(TARGET example APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO "/LTCG ") endif() # .PYD file extension on Windows diff --git a/docs/cmake.rst b/docs/cmake.rst index 7236ea8b..02983030 100644 --- a/docs/cmake.rst +++ b/docs/cmake.rst @@ -106,17 +106,19 @@ subdirectory named :file:`pybind11`. if (WIN32) if (MSVC) - # /bigobj is needed for bigger binding projects due to the limit to 64k - # addressable sections. /MP enables multithreaded builds (relevant when - # there are many files). - set_target_properties(example PROPERTIES COMPILE_FLAGS "/MP /bigobj ") - - if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG) - # Enforce size-based optimization and link time code generation on MSVC - # (~30% smaller binaries in experiments). - set_target_properties(example APPEND_STRING PROPERTY COMPILE_FLAGS "/Os /GL ") - set_target_properties(example APPEND_STRING PROPERTY LINK_FLAGS "/LTCG ") - endif() + # /MP enables multithreaded builds (relevant when there are many files), /bigobj is + # needed for bigger binding projects due to the limit to 64k addressable sections + set_property(TARGET example APPEND PROPERTY COMPILE_OPTIONS /MP /bigobj) + # Enforce size-based optimization and link time code generation on MSVC + # (~30% smaller binaries in experiments); do nothing in debug mode. + set_property(TARGET example APPEND PROPERTY COMPILE_OPTIONS + "$<$:/Os>" "$<$:/GL>" + "$<$:/Os>" "$<$:/GL>" + "$<$:/Os>" "$<$:/GL>" + ) + set_property(TARGET example APPEND_STRING PROPERTY LINK_FLAGS_RELEASE "/LTCG ") + set_property(TARGET example APPEND_STRING PROPERTY LINK_FLAGS_MINSIZEREL "/LTCG ") + set_property(TARGET example APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO "/LTCG ") endif() # .PYD file extension on Windows