Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a build issue related to Qt dll files. #798

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
"variables": []
}
]
}
}
228 changes: 10 additions & 218 deletions config/component_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ macro( add_component_executable )
# Prefix for export
if( NOT DEFINED ace_PREFIX AND NOT DEFINED ace_NOEXPORT)
message( FATAL_ERROR
"add_component_executable requires a PREFIX value to allow EXPORT of this target
or the target must be labeled NOEXPORT.")
"add_component_executable requires a PREFIX value to allow EXPORT of this
target or the target must be labeled NOEXPORT.")
endif()

# Default link language is C++
if( "${ace_LINK_LANGUAGE}x" STREQUAL "x" )
if( NOT DEFINED ace_LINK_LANGUAGE )
set( ace_LINK_LANGUAGE CXX )
endif()

Expand Down Expand Up @@ -294,10 +294,6 @@ or the target must be labeled NOEXPORT.")
"${${ace_PREFIX}_EXPORT_TARGET_PROPERTIES}" PARENT_SCOPE)
unset(desc)
endif()

# If Win32, copy dll files into binary directory.
copy_dll_link_libraries_to_build_dir( ${ace_TARGET} )

endmacro()

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -649,202 +645,6 @@ macro( register_parallel_test targetname numPE command cmd_args )
unset( lverbose )
endmacro()

#------------------------------------------------------------------------------#
# Special post-build options for Win32 platforms
# -----------------------------------------------------------------------------#
# copy_dll_link_libraries_to_build_dir( target )
#
# For Win32 with shared libraries, all dll dependencies must be located in the
# PATH or in the application directory. This cmake function creates POST_BUILD
# rules for unit tests and applications to ensure that the most up-to-date
# versions of all dependencies are in the same directory as the application.
#------------------------------------------------------------------------------#
function( copy_dll_link_libraries_to_build_dir target )

if( NOT MSVC )
# Win32 platforms require all dll libraries to be in the local directory
# (or $PATH)
return()
endif()

# Debug dependencies for a particular target (uncomment the next line and
# provide the targetname): "Ut_${compname}_${testname}_exe"
if( "Ut_FortranChecks_foo_exe" STREQUAL ${target} )
set(lverbose ON)
endif()
if( lverbose )
include(print_target_properties)
endif()

# For Win32 with shared libraries, the package dll must be located in the test
# directory.

# Discover all library dependencies for this unit test.
get_target_property( link_libs ${target} LINK_LIBRARIES )
if( lverbose )
message("\nDebugging dependencies for target ${target}")
message(" Dependencies = ${link_libs}\n")
endif()
if( "${link_libs}" MATCHES NOTFOUND )
return() # nothing to do
endif()

set( old_link_libs "" )
# Walk through the library dependencies to build a list of all .dll
# dependencies.
while( NOT "${old_link_libs}" STREQUAL "${link_libs}" )
if(lverbose)
message("Found new libraries (old_link_libs != link_libs). Restarting"
" search loop...\n")
endif()
set( old_link_libs ${link_libs} )
foreach( lib ${link_libs} )
if( lverbose )
# message("\n examine dependencies for lib = ${lib}\n")
print_targets_properties("${lib}")
endif()
# $lib will either be a cmake target (e.g.: Lib_dsxx, Lib_c4) or an actual
# path to a library (c:\lib\gsl.lib).
if( NOT EXISTS ${lib} AND TARGET ${lib} )
# Must be a CMake target... find it's dependencies...
# The target may be
# 1. A target defined within the current build system (e.g.: Lib_c4),
# or
# 2. an 'imported' targets like GSL::gsl.
get_target_property( isimp ${lib} IMPORTED )
if(isimp)
get_target_property( link_libs3 ${lib} INTERFACE_LINK_LIBRARIES)
else()
get_target_property( link_libs2 ${lib} LINK_LIBRARIES )
endif()
list( APPEND link_libs ${link_libs2} )
list( APPEND link_libs ${link_libs3} )
endif()
endforeach()
# Loop through all current dependencies, remove static libraries
#(they do not need to be in the run directory).
list( REMOVE_DUPLICATES link_libs )
foreach( lib ${link_libs} )
if( "${lib}" MATCHES "NOTFOUND" )
# nothing to add so remove from list
list( REMOVE_ITEM link_libs ${lib} )
if( lverbose )
message("lib = ${lib} is NOTFOUND --> remove it from the list")
endif()
elseif( "${lib}" MATCHES "[$]<")
# We have a generator expression. This routine does not support this,
# so drop it.
list( REMOVE_ITEM link_libs ${lib} )
if( lverbose )
message("lib = ${lib} is a generator expression --> remove it from"
" the list")
endif()
elseif( "${lib}" MATCHES ".[lL]ib$" )
# We have a path to a static library. Static libraries do not
# need to be copied.
list( REMOVE_ITEM link_libs ${lib} )
if( lverbose )
message("lib = ${lib} is a static lib --> remove it from the list")
endif()
# However, if there is a corresponding dll, we should add it
# to the list.
string( REPLACE ".lib" ".dll" dll_lib ${lib} )
if( ${dll_lib} MATCHES "[.]dll$" AND EXISTS ${dll_lib} )
list( APPEND link_libs "${dll_lib}" )
if( lverbose )
message("lib = ${lib} has a dll --> replace it with ${dll_lib}")
endif()
endif()
endif()
endforeach()
if( lverbose )
message("Updated dependencies list: ${target} --> ${link_libs}\n")
endif()

endwhile()

list( REMOVE_DUPLICATES link_libs )
# if( ${compname} MATCHES Fortran )
# message(" ${compname}_${testname} --> ${link_libs}")
# endif()

if( lverbose )
message("Creating post build commands for target = ${target}")
endif()

# Add a post-build command to copy each dll into the test directory.
foreach( lib ${link_libs} )
# We do not need to the post_build copy command for Draco Lib_* files.
# These should already be in the correct location.
if( NOT ${lib} MATCHES "Lib_" )
if( lverbose )
message(" looking at ${lib}")
endif()
unset( target_loc )
if( NOT TARGET ${lib})
if (lverbose )
message(" ${lib} is not a target. skip it.")
endif()
continue()
endif()
# TYPE = {STATIC_LIBRARY, MODULE_LIBRARY, SHARED_LIBRARY,
# INTERFACE_LIBRARY, EXECUTABLE}
# We cannot query INTERFACE_LIBRARY targets.
get_target_property(lib_type ${lib} TYPE )
if( ${lib_type} STREQUAL "INTERFACE_LIBRARY" )
if( lverbose )
message(" I think ${lib} is an INTERFACE_LIBRARY. Skipping to next "
"dependency.")
endif()
continue()
endif()
get_target_property(is_imported ${lib} IMPORTED )
if( is_imported )
get_target_property(target_loc_rel ${lib} IMPORTED_LOCATION_RELEASE )
get_target_property(target_loc_deb ${lib} IMPORTED_LOCATION_DEBUG )
get_target_property(target_loc ${lib} IMPORTED_LOCATION )
if( ${target_loc_rel} MATCHES "NOTFOUND" AND
${target_loc_deb} MATCHES "NOTFOUND" AND
${target_loc} MATCHES "NOTFOUND" )
# path not found, ignore.
if (lverbose )
message(" ${lib} does not have an IMPORTED_LOCATION value. "
"skip it.")
endif()
continue()
else()
set(target_loc "$<TARGET_FILE:${lib}>")
endif()
get_target_property(target_gnutoms ${lib} GNUtoMS)
elseif( EXISTS ${lib} )
# If $lib is a full path to a library, add it to the list
if (lverbose )
message(" ${lib} is the full path to a library; adding to the list.")
endif()
set( target_loc ${lib} )
set( target_gnutoms NOTFOUND )
else()
if (lverbose )
message(" ${lib} is a target that points to $<TARGET:${lib}>.")
endif()
set( target_loc $<TARGET_FILE:${lib}> )
get_target_property( target_gnutoms ${lib} GNUtoMS )
endif()

add_custom_command( TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${target_loc}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} )

if( lverbose )
message(" CMAKE_COMMAND -E copy_if_different ${target_loc} "
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}")
endif()

endif()
endforeach()
unset( lverbose )
endfunction( copy_dll_link_libraries_to_build_dir )

#----------------------------------------------------------------------#
# add_scalar_tests
#
Expand Down Expand Up @@ -987,13 +787,7 @@ macro( add_scalar_tests test_sources )
target_link_libraries(
Ut_${compname}_${testname}_exe
${test_lib_target_name}
${addscalartest_DEPS}
)

# Special post-build options for Win32 platforms
# ------------------------------------------------------------
copy_dll_link_libraries_to_build_dir( Ut_${compname}_${testname}_exe )

${addscalartest_DEPS} )
endforeach()

# Register the unit test
Expand Down Expand Up @@ -1032,8 +826,8 @@ endmacro(add_scalar_tests)
# Optional parameters that require arguments.
#
# SOURCES - semi-colon delimited list of files.
# PE_LIST - semi-colon deliminte list of integers (number
# of MPI ranks).
# PE_LIST - semi-colon delimited list of integers (number of MPI
# ranks).
# DEPS - CMake target dependencies.
# TEST_ARGS - Command line arguments to use when running the test.
# PASS_REGEX - This regex must exist in the output to produce
Expand Down Expand Up @@ -1153,12 +947,7 @@ macro( add_parallel_tests )
target_link_libraries(
Ut_${compname}_${testname}_exe
${test_lib_target_name}
${addparalleltest_DEPS}
)

# Special post-build options for Win32 platforms
# ------------------------------------------------------------
copy_dll_link_libraries_to_build_dir( Ut_${compname}_${testname}_exe )
${addparalleltest_DEPS} )

endforeach()

Expand Down Expand Up @@ -1262,6 +1051,9 @@ macro( provide_aux_files )
endif()
endif()
set( outfile ${PROJECT_BINARY_DIR}/${srcfilenameonly} )
if( "${file}x" STREQUAL "x" OR "${outfile}x" STREQUAL "x")
message( FATAL_ERROR " COMMAND ${CMAKE_COMMAND} -E copy_if_different ${file} ${outfile}")
endif()
add_custom_command(
OUTPUT ${outfile}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${file} ${outfile}
Expand Down
12 changes: 4 additions & 8 deletions src/diagnostics/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ project( diagnostics_qt CXX )
# Special options for Qt applications
# ---------------------------------------------------------------------------- #

# Instruct CMake to run moc automatically when needed (only for subdirectories
# Instruct CMake to run MOC automatically when needed (only for subdirectories
# that need Qt)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
Expand Down Expand Up @@ -43,21 +43,17 @@ add_component_executable(
FOLDER diagnostics
NOCOMMANDWINDOW )

# Disable IPO for appliations that link to Qt SDK, as this causes compile
# Disable IPO for applications that link to Qt SDK, as this causes compile
# warnings for the Intel compiler (and it refuses to run IPO for this
# application anyway).
if( CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set_target_properties( Exe_draco_info_gui PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF )
endif()

# Copy Qt dll files to build directory
# copy_dll_link_libraries_to_build_dir( Exe_draco_info_gui )
if (WIN32)
file( GLOB qtdlls ${QTDIR}/bin/*.dll )
# Copy necessary dll files to build directory
if (WIN32)
add_custom_command( TARGET Exe_draco_info_gui POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${qtdlls}
$<TARGET_FILE_DIR:Exe_draco_info_gui>
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Lib_dsxx>
$<TARGET_FILE_DIR:Exe_draco_info_gui>
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Lib_c4>
Expand Down