Skip to content

Commit

Permalink
Link statically (with LTCG) on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobo1 committed Mar 3, 2016
1 parent e9aff3f commit b4e5dec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# override default c/c++ flags, add /MT to link VC++ runtime statically.
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/c_flag_overrides.cmake)
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_flag_overrides.cmake)

cmake_minimum_required(VERSION 3.0.0)
project(chewing-editor VERSION 0.0.1)

Expand Down Expand Up @@ -136,6 +140,18 @@ target_link_libraries(chewing-editor
importer
util
)
if(MSVC)
target_link_libraries(chewing-editor # append libraries
Qt5::Widgets
"${_qt5Widgets_install_prefix}/lib/qtpcre.lib"
"${_qt5Widgets_install_prefix}/lib/qtfreetype.lib"
"${_qt5Widgets_install_prefix}/lib/qtharfbuzzng.lib"
imm32.lib
winmm.lib
Ws2_32.lib
)
endif()

qt5_use_modules(chewing-editor Widgets)
install(PROGRAMS ${CMAKE_BINARY_DIR}/chewing-editor DESTINATION ${CMAKE_INSTALL_BINDIR})

Expand Down
7 changes: 7 additions & 0 deletions cmake/c_flag_overrides.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(MSVC)
set(CMAKE_C_FLAGS_DEBUG_INIT "/MTd /Zi /Ob0 /Od /RTC1 /D_DEBUG")
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /GL /Gw /D NDEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /OPT:REF /OPT:ICF")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()
7 changes: 7 additions & 0 deletions cmake/cxx_flag_overrides.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG_INIT "/MTd /Zi /Ob0 /Od /RTC1 /D_DEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /GL /Gw /D NDEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /OPT:REF /OPT:ICF")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()

0 comments on commit b4e5dec

Please sign in to comment.