From 9160a61d8e3fbca8b59944d66f6e7c232cddde0b Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Mon, 11 May 2020 00:32:09 +0200 Subject: [PATCH] Added build target with static linking --- CMakeLists.txt | 21 +++++++++++++++++++++ CMakeSettings.json | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 984df14e..cc057bb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,5 +58,26 @@ endif() # visual studio debugger set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT magicseteditor) +# Static linking on windows +if (${VCPKG_TARGET_TRIPLET} MATCHES ".*-static") + message("Static linking") + set(CompilerFlags CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE) + foreach(CompilerFlag ${CompilerFlags}) + string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") + endforeach() + # Need explicit dependencies on wx's dependencies + find_package(png REQUIRED) + find_package(tiff REQUIRED) + find_package(jpeg REQUIRED) + find_package(zlib REQUIRED) + target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} ${JPEG_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} ${TIFF_LIBRARIES}) + # Defines + add_definitions(-DSTATIC) + add_definitions(-DHUNSPELL_STATIC) +endif() + # Test suite include(test/tests.cmake) diff --git a/CMakeSettings.json b/CMakeSettings.json index 63e82082..94002c59 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -23,6 +23,42 @@ "ctestCommandArgs": "", "inheritEnvironments": [ "msvc_x86" ], "variables": [] + }, + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "-v", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ], + "variables": [] + }, + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "-v", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ], + "variables": [] + }, + { + "name": "x86-Release-static", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "-DVCPKG_TARGET_TRIPLET=x86-windows-static", + "buildCommandArgs": "-v", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x86" ], + "variables": [] } ] } \ No newline at end of file