diff options
| author | ruki <[email protected]> | 2021-09-29 00:44:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-29 00:44:27 +0800 |
| commit | f27971ea0d01415aa9cc7e4c69114149bccc15c1 (patch) | |
| tree | 9f40810ffcedd55e2d5ed170dc769d114ef5ebbd | |
| parent | 9adbd3eaa529a66ef9f070d39f6896d45221f9b6 (diff) | |
improve vs runtime for cmake generator
| -rw-r--r-- | xmake/plugins/project/cmake/cmakelists.lua | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 0c51d7817..2d26a7888 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -74,10 +74,9 @@ function _add_project(cmakelists) ]], project.name() or "") cmakelists:print("# project") cmakelists:print("cmake_minimum_required(VERSION %s)", cmake_version) - -- see https://github.com/xmake-io/xmake/issues/1661#issuecomment-927951660 - if cmake_version:ge("3.15") then + if cmake_version:ge("3.15.0") then + -- for MSVC_RUNTIME_LIBRARY cmakelists:print("cmake_policy(SET CMP0091 NEW)") - cmakelists:print('set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")') end local project_name = project.name() if not project_name then @@ -373,6 +372,32 @@ function _add_target_optimization(cmakelists, target) end end +-- add target vs runtime +-- +-- https://github.com/xmake-io/xmake/issues/1661#issuecomment-927979489 +-- https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html +-- +function _add_target_vs_runtime(cmakelists, target) + local cmake_minver = _get_cmake_minver() + if true then--cmake_minver:ge("3.15.0") then + local vs_runtime = target:get("runtimes") + if vs_runtime then + cmakelists:print("if(MSVC)") + if vs_runtime == "MT" then + vs_runtime = "MultiThreaded" + elseif vs_runtime == "MTd" then + vs_runtime = "MultiThreadedDebug" + elseif vs_runtime == "MD" then + vs_runtime = "MultiThreadedDLL" + elseif vs_runtime == "MDd" then + vs_runtime = "MultiThreadedDebugDLL" + end + cmakelists:print(' set_property(TARGET %s PROPERTY MSVC_RUNTIME_LIBRARY "%s")', target:name(), vs_runtime) + cmakelists:print("endif()") + end + end +end + -- add target link libraries function _add_target_link_libraries(cmakelists, target) @@ -509,6 +534,9 @@ function _add_target(cmakelists, target) -- add target optimization _add_target_optimization(cmakelists, target) + -- add vs runtime for msvc + _add_target_vs_runtime(cmakelists, target) + -- add target link libraries _add_target_link_libraries(cmakelists, target) |
