Skip to content

Commit

Permalink
Windows build: improvement to DLL copying
Browse files Browse the repository at this point in the history
Copy the Windows DLL with a single call to `cmake -E` rather than one call per
DLL. This slightly speeds up the build for a better experience in iterative
developement on Windows.

Also moves the DLL copying to POST_BUILD rather then PRE_BUILD as there's
no point in copying the DLLs if there's going to be a compile error
during iterative development.
  • Loading branch information
agalasso committed Jan 4, 2025
1 parent 6b2676b commit 7340b90
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 109 deletions.
46 changes: 43 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,50 @@ elseif(WIN32)

target_include_directories(phd2 PRIVATE "C:/Program Files (x86)/Visual Leak Detector/include")

# Delayed load for all DLLs below in the original project. Now using delay load only for the necessary stuff
#sbigudrv.dll;ICFilterContainer.dll;TIS_DShowLib09.dll;TIS_UDSHL09_vc9.dll;FCApi.dll;OSPL130RT.dll;DLCWB.dll;cfitsio.dll;CMOSDll.dll;DSCI.dll;inpout32.dll;ShoestringGPUSB_DLL.dll;ShoestringLXUSB_DLL.dll;SXUSB.dll;AsiCamera.dll;%(DelayLoadDLLs)
# copy DLL files into the output directory

copy_dependency_with_config(phd2 PHD_COPY_EXTERNAL_ALL PHD_COPY_EXTERNAL_DBG PHD_COPY_EXTERNAL_REL)
set(_copyfiles_dbg ${PHD_COPY_EXTERNAL_ALL} ${PHD_COPY_EXTERNAL_DBG})
set(_copyfiles_rel ${PHD_COPY_EXTERNAL_ALL} ${PHD_COPY_EXTERNAL_REL})
foreach(_file IN LISTS _copyfiles_dbg _copyfiles_rel)
if(NOT EXISTS ${_file})
message(FATAL_ERROR "Dependency ${_file} does not exist")
endif()
endforeach()
foreach(_config dbg rel)
set(_realpaths_${_config})
foreach(_file ${_copyfiles_${_config}})
get_filename_component(_realpath ${_file} REALPATH)
list(APPEND _realpaths_${_config} ${_realpath})
endforeach()
list(REMOVE_DUPLICATES _realpaths_${_config})
endforeach()
unset(_file)
unset(_config)

add_custom_command(
TARGET phd2
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
$<$<CONFIG:Debug>:copy_if_different>
$<$<NOT:$<CONFIG:Debug>>:true>
${_realpaths_dbg}
$<TARGET_FILE_DIR:phd2>/.
COMMAND_EXPAND_LISTS VERBATIM
COMMENT "$<$<CONFIG:Debug>:Copy debug libs to output folder>"
)
add_custom_command(
TARGET phd2
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
$<$<CONFIG:Release>:copy_if_different>
$<$<NOT:$<CONFIG:Release>>:true>
${_realpaths_rel}
$<TARGET_FILE_DIR:phd2>/.
COMMAND_EXPAND_LISTS VERBATIM
COMMENT "$<$<CONFIG:Release>:Copy release libs to output folder>"
)
unset(_realpaths_dbg)
unset(_realpaths_rel)

## #########################
## Unix
Expand Down
106 changes: 0 additions & 106 deletions thirdparty/thirdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,112 +93,6 @@ if(WIN32)
include_directories(${VCPKG_INCLUDE})
endif()

#
# copies the dependency files into the target output directory
#
macro(copy_dependency_with_config target_name dependency_list_all dependency_list_dbg dependency_list_release)


set(dependency_list_dbg_with_all ${${dependency_list_dbg}} ${${dependency_list_all}})
set(dependency_list_dbg_with_all_cleaned)
foreach(_element ${dependency_list_dbg_with_all})
if(NOT EXISTS ${_element})
message(FATAL_ERROR "Dependency ${_element} does not exist")
endif()
#message(STATUS "copyX ${_element}")
get_filename_component(_element1 ${_element} REALPATH)
set(dependency_list_dbg_with_all_cleaned ${dependency_list_dbg_with_all_cleaned} ${_element1})
unset(_element1)
endforeach()

list(REMOVE_DUPLICATES dependency_list_dbg_with_all_cleaned)
set(dependency_list_dbg_with_all ${dependency_list_dbg_with_all_cleaned})
unset(dependency_list_dbg_with_all_cleaned)
unset(_element)

foreach(_element ${dependency_list_dbg_with_all})
get_filename_component(_element_name ${_element} NAME)
add_custom_command(
TARGET ${target_name}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
$<$<CONFIG:Debug>:echo>
$<$<CONFIG:Debug>:"Copy ${_element_name} to $<TARGET_FILE_DIR:${target_name}>/.">
$<$<NOT:$<CONFIG:Debug>>:echo_append>
$<$<NOT:$<CONFIG:Debug>>:".">
COMMAND ${CMAKE_COMMAND} -E
$<$<CONFIG:Debug>:copy_if_different>
$<$<CONFIG:Debug>:${_element}>
$<$<CONFIG:Debug>:$<TARGET_FILE_DIR:${target_name}>/.>
$<$<NOT:$<CONFIG:Debug>>:echo_append>
$<$<NOT:$<CONFIG:Debug>>:"">
COMMENT "Copy ${target_name} dependencies into the output folder")



#message(STATUS "copy ${_element_name}")
# add_custom_command(
# TARGET ${target_name}
# PRE_BUILD
# COMMAND ${CMAKE_COMMAND} -E echo Copy ${_element_name} into $<TARGET_FILE_DIR:${target_name}>/.

# COMMAND ${CMAKE_COMMAND} -E $<$<CONFIG:Debug>:copy_if_different>$<$<NOT:$<CONFIG:Debug>>:echo> ${_element} $<TARGET_FILE_DIR:${target_name}>/.
# COMMENT "Copy ${target_name} dependencies into the output folder")

unset(_element_name)
endforeach()
unset(dependency_list_dbg_with_all)
unset(_element)


set(dependency_list_release_with_all ${${dependency_list_release}} ${${dependency_list_all}})
set(dependency_list_release_with_all_cleaned)
foreach(_element ${dependency_list_release_with_all})
if(NOT EXISTS ${_element})
message(FATAL_ERROR "Dependency ${_element} does not exist")
endif()
get_filename_component(_element1 ${_element} REALPATH)
set(dependency_list_release_with_all_cleaned ${dependency_list_release_with_all_cleaned} ${_element1})
unset(_element1)
endforeach()
list(REMOVE_DUPLICATES dependency_list_release_with_all_cleaned)
set(dependency_list_release_with_all ${dependency_list_release_with_all_cleaned})
unset(dependency_list_release_with_all_cleaned)
unset(_element)

foreach(_element ${dependency_list_release_with_all})
get_filename_component(_element_name ${_element} NAME)
add_custom_command(
TARGET ${target_name}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
$<$<CONFIG:Release>:echo> #$<$<NOT:$<CONFIG:Release>>:echo> ${_element} $<TARGET_FILE_DIR:${target_name}>/.
$<$<CONFIG:Release>:"Copy ${_element_name} to $<TARGET_FILE_DIR:${target_name}>/.">
$<$<NOT:$<CONFIG:Release>>:echo_append>
$<$<NOT:$<CONFIG:Release>>:".">
COMMAND ${CMAKE_COMMAND} -E
$<$<CONFIG:Release>:copy_if_different>
$<$<CONFIG:Release>:${_element}>
$<$<CONFIG:Release>:$<TARGET_FILE_DIR:${target_name}>/.>
$<$<NOT:$<CONFIG:Release>>:echo_append>
$<$<NOT:$<CONFIG:Release>>:"">
COMMENT "Copy ${target_name} dependencies into the output folder")
unset(_element_name)
endforeach()
unset(dependency_list_release_with_all)
unset(_element)

# we can also use this thing to install external stuff
#install( FILES ${dependency_name_debug}
# DESTINATION bin
# CONFIGURATIONS Debug)
#install( FILES ${dependency_name_non_debug}
# DESTINATION bin
# CONFIGURATIONS Release)


endmacro(copy_dependency_with_config)

if(APPLE)
find_library(quicktimeFramework QuickTime)
find_library(iokitFramework IOKit)
Expand Down

0 comments on commit 7340b90

Please sign in to comment.