Sfoglia il codice sorgente

refactor & feat: 修复vs运行时问题

SongZihuan 3 anni fa
parent
commit
f19dde116a
2 ha cambiato i file con 35 aggiunte e 33 eliminazioni
  1. 21 8
      cmake/FindFFlags.cmake
  2. 14 25
      cmake/WindowsInstall.cmake

+ 21 - 8
cmake/FindFFlags.cmake

@@ -17,20 +17,33 @@ find_library(fflags_lib NAMES FFlags libFFlags HINTS ${_root}/lib DOC "FFlags li
 set(fflags_INCLUDE_DIRS ${fflags_h})
 set(fflags_LIBRARIES ${fflags_lib})
 
+if (WIN32 AND NOT CYGWIN)
+    find_file(fflags_dll NAMES FFlags.dll libFFlags.dll HINTS ${_root}/bin DOC "FFlags ddl" NO_DEFAULT_PATH)
+    if (fflags_dll)
+        set(fflags_DLL ${fflags_dll})
+    else()
+        set(fflags_DLL)
+    endif()
+else()
+    set(fflags_DLL ${fflags_LIBRARIES})
+endif()
+
 unset(fflags_h CACHE)
 unset(fflags_lib CACHE)
 
 find_package_handle_standard_args(FFlags
-                                  FOUND_VAR FFlags_FOUND
-                                  REQUIRED_VARS
-                                  fflags_INCLUDE_DIRS
-                                  fflags_LIBRARIES)  # 强制搜不到包
+        FOUND_VAR FFlags_FOUND
+        REQUIRED_VARS
+        fflags_INCLUDE_DIRS
+        fflags_LIBRARIES
+        fflags_DLL)  # 强制搜不到包
 
 if (FFlags_FOUND)
     add_library(FFlags::fflags STATIC IMPORTED)
     set_target_properties(FFlags::fflags PROPERTIES
-                          IMPORTED_LOCATION "${fflags_LIBRARIES}"
-                          INTERFACE_INCLUDE_DIRECTORIES "${fflags_INCLUDE_DIRS}"
-                          INTERFACE_SOURCES "${fflags_INCLUDE_DIRS}/fflags.h"
-                          PUBLIC_HEADER "${fflags_INCLUDE_DIRS}/fflags.h")
+            IMPORTED_IMPLIB "${fflags_DLL}"
+            IMPORTED_LOCATION "${fflags_LIBRARIES}"
+            INTERFACE_INCLUDE_DIRECTORIES "${fflags_INCLUDE_DIRS}"
+            INTERFACE_SOURCES "${fflags_INCLUDE_DIRS}/fflags.h"
+            PUBLIC_HEADER "${fflags_INCLUDE_DIRS}/fflags.h")
 endif()

+ 14 - 25
cmake/WindowsInstall.cmake

@@ -1,7 +1,7 @@
 include_guard(GLOBAL)  # 防止二次导入
 
 # 安装 dll
-function(_wi_install_import_inline target run lib)
+function(_wi_install_import_inline target run)
     if(WIN32 OR CYGWIN)  # 只有windows需要执行该操作 (包括cygwin也需要处理.dll依赖的问题)
         if (CMAKE_BUILD_TYPE)
             string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
@@ -9,21 +9,9 @@ function(_wi_install_import_inline target run lib)
             set(_build_type DEBUG)
         endif()
 
-        get_target_property(imp ${target} IMPORTED_IMPLIB)
-        get_target_property(imp_t ${target} IMPORTED_IMPLIB_${_build_type})
-
         get_target_property(loc ${target} IMPORTED_LOCATION)
         get_target_property(loc_t ${target} IMPORTED_LOCATION_${_build_type})
 
-        if(lib)
-            if (imp)
-                install(FILES ${imp} DESTINATION ${lib})
-            endif()
-            if (imp_t)
-                install(FILES ${imp_t} DESTINATION ${lib})
-            endif()
-        endif()
-
         if(run)
             if (loc)
                 install(FILES ${loc} DESTINATION ${run})
@@ -37,14 +25,15 @@ endfunction()
 
 # 拷贝dll
 # 添加 target
-if (NOT TARGET import_build)
-    add_custom_target(import_build ALL COMMENT "Copy import target.")
+if (NOT TARGET deps-copy)
+    add_custom_target(deps-copy COMMENT "Copy import target.")
 endif()
 
 macro(set_copy_command target a b)
     add_custom_command(TARGET ${target} POST_BUILD
-            COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${a}" "${b}"
-            COMMENT "Copy ${a}.")
+            COMMAND "${CMAKE_COMMAND}" "-E" "copy_if_different" "${a}" "${b}"
+            COMMENT "Copy ${a} to ${b}."
+            WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 endmacro()
 
 function(_wi_build_import_inline target run lib)
@@ -62,21 +51,21 @@ function(_wi_build_import_inline target run lib)
         get_target_property(loc_t ${target} IMPORTED_LOCATION_${_build_type})
 
         if(lib)
-            if (imp)
-                set_copy_command(import_build ${imp} ${lib})
+            if (imp AND imp MATCHES ".+dll")
+                set_copy_command(deps-copy ${imp} ${lib})
             endif()
 
-            if (imp_t)
-                set_copy_command(import_build ${imp_t} ${lib})
+            if (imp_t AND imp_t MATCHES ".+dll")
+                set_copy_command(deps-copy ${imp_t} ${lib})
             endif()
         endif()
 
         if(run)
-            if (loc)
-                set_copy_command(import_build ${loc} ${run})
+            if (loc AND loc MATCHES ".+dll")
+                set_copy_command(deps-copy ${loc} ${run})
             endif()
-            if (loc_t)
-                set_copy_command(import_build ${loc_t} ${run})
+            if (loc_t AND loc_t MATCHES ".+dll")
+                set_copy_command(deps-copy ${loc_t} ${run})
             endif()
         endif()
     endif()