Skip to content

Commit

Permalink
Merge pull request #8003 from lrineau/Polyhedron_demo-fix_CTest_depen…
Browse files Browse the repository at this point in the history
…dencies-GF

Add a hook CGAL_hook_fix_ctest_dependencies
  • Loading branch information
lrineau committed Feb 13, 2024
2 parents 6d5d091 + 3664fc8 commit 3b4d0cf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,36 @@ function(CGAL_hook_fix_ctest_depending_on_Qt6)
endforeach()
endfunction()

function(CGAL_hook_fix_ctest_dependencies)
get_property(_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
# message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR} targets: ${_targets}")
foreach(_target ${_targets})
if(NOT TEST "compilation of ${_target}")
continue()
endif()
get_property(linked_libraries TARGET "${_target}" PROPERTY LINK_LIBRARIES)
get_property(deps TARGET "${_target}" PROPERTY MANUALLY_ADDED_DEPENDENCIES)
list(APPEND deps ${linked_libraries})
# message(" ${_target} depends on: ${deps}")
foreach(dep ${deps})
if(TARGET ${dep} AND NOT dep MATCHES "^CGAL::|^CGAL_|^CGAL$" )
get_target_property(imported ${dep} IMPORTED)
if(NOT imported)
# message(STATUS "The target ${dep} is a dependency of ${_target}.")
set_property(TEST "compilation of ${_target}"
APPEND PROPERTY DEPENDS "compilation of ${dep}")
endif()
endif()
endforeach()
endforeach()
endfunction()

function(CGAL_hooks_at_end_of_all_directories)
CGAL_hook_check_targets()
CGAL_hook_check_unused_cpp_files()
if(CGAL_ENABLE_TESTING)
CGAL_hook_fix_ctest_depending_on_Qt6()
CGAL_hook_fix_ctest_dependencies()
endif()
endfunction()

Expand Down Expand Up @@ -155,6 +180,11 @@ function(CGAL_run_at_the_end_of_configuration variable access value current_list
endfunction()

function(CGAL_install_hooks)
get_property(PROPERTY_CGAL_hooks_installed DIRECTORY PROPERTY CGAL_hooks_installed)
if(PROPERTY_CGAL_hooks_installed)
return()
endif()
# message(STATUS "Installing hooks in ${CMAKE_CURRENT_SOURCE_DIR}")
if(CMAKE_VERSION VERSION_LESS 3.19)
variable_watch("CMAKE_CURRENT_LIST_DIR" CGAL_run_at_the_end_of_configuration)
else()
Expand All @@ -163,6 +193,7 @@ function(CGAL_install_hooks)
cmake_language(DEFER CALL CGAL_hook_check_CMAKE_BUILD_TYPE)
endif()
endif()
set_property(DIRECTORY PROPERTY CGAL_hooks_installed TRUE)
endfunction()

CGAL_install_hooks()
Expand Down
19 changes: 18 additions & 1 deletion Polyhedron/demo/Polyhedron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,19 @@ if(CGAL_Qt6_FOUND AND Qt6_FOUND)
message(STATUS "Qt6WebSockets was found. Using WebSockets is therefore possible.")
endif()

#compilation_of__demo_framework is defined in polyhedron_demo_macros.cmake
# This custom target is useless. It is used only as a flag to
# detect that the test has already been created.
add_custom_target("compilation_of__demo_framework")
cgal_add_compilation_test(demo_framework)
if(TEST "compilation of demo_framework")
set_property(TEST "compilation of demo_framework"
APPEND PROPERTY LABELS "CGAL_build_system" "Installation" "${PROJECT_NAME}")
set_property(TEST "compilation of demo_framework"
APPEND PROPERTY FIXTURES_SETUP "demo_framework_SetupFixture")
set_property(TEST "compilation of demo_framework"
APPEND PROPERTY DEPENDS "check build system" "compilation of CGAL_Qt6_moc_and_resources")
endif()

# Let's define `three_EXPORT` during the compilation of `demo_framework`,
# in addition of `demo_framework_EXPORT` (defined automatically by
# CMake). That is to deal with the visibility of symbols of
Expand All @@ -219,13 +231,16 @@ if(CGAL_Qt6_FOUND AND Qt6_FOUND)
${Show_point_dialogUI_FILES})
target_link_libraries(point_dialog PUBLIC Qt6::OpenGLWidgets Qt6::Gui
Qt6::Widgets)
cgal_add_compilation_test(point_dialog)

macro(add_item item_name)
add_library(${item_name} SHARED ${ARGN})
target_link_libraries(
${item_name} PUBLIC demo_framework CGAL::CGAL_Qt6 Qt6::OpenGLWidgets Qt6::Gui
Qt6::Widgets)
cgal_add_compilation_test(${item_name})
add_to_cached_list(CGAL_EXECUTABLE_TARGETS ${item_name})
CGAL_install_hooks()
endmacro(add_item)

add_item(scene_triangulation_3_item Scene_triangulation_3_item.cpp)
Expand Down Expand Up @@ -360,9 +375,11 @@ if(CGAL_Qt6_FOUND AND Qt6_FOUND)
target_compile_definitions(demo_framework PRIVATE -DCGAL_USE_WEBSOCKETS)
target_link_libraries(polyhedron_demo PRIVATE Qt6::WebSockets)
endif()
cgal_add_compilation_test(polyhedron_demo)
add_executable(Polyhedron_3 Polyhedron_3.cpp)
target_link_libraries(Polyhedron_3 PRIVATE polyhedron_demo)
add_to_cached_list(CGAL_EXECUTABLE_TARGETS Polyhedron_3)
cgal_add_compilation_test(Polyhedron_3)

target_link_libraries(Polyhedron_3 PRIVATE demo_framework)

Expand Down
20 changes: 2 additions & 18 deletions Polyhedron/demo/Polyhedron/polyhedron_demo_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,11 @@ include(${CGAL_MODULES_DIR}/CGAL_add_test.cmake)
if(TARGET demo_framework)
target_link_libraries( ${plugin_name} PUBLIC demo_framework)
add_dependencies(${plugin_name} demo_framework)
if(CGAL_ENABLE_TESTING AND NOT CMAKE_VS_MSBUILD_COMMAND)
if(NOT TARGET "compilation_of__demo_framework")
# This custom target is useless. It is used only as a flag to
# detect that the test has already been created.
add_custom_target("compilation_of__demo_framework")
add_dependencies( "compilation_of__demo_framework" demo_framework )
add_test(NAME "compilation of demo_framework"
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target "demo_framework" --config "$<CONFIG>")

set_property(TEST "compilation of demo_framework"
APPEND PROPERTY LABELS "CGAL_build_system" "Installation" "${PROJECT_NAME}")
set_property(TEST "compilation of demo_framework"
APPEND PROPERTY FIXTURES_SETUP "demo_framework_SetupFixture")
set_property(TEST "compilation of demo_framework"
APPEND PROPERTY DEPENDS "check build system" "compilation of CGAL_Qt6_moc_and_resources")
endif()
endif()
else()
target_link_libraries( ${plugin_name} PUBLIC Polyhedron_demo_framework)
add_dependencies(${plugin_name} Polyhedron_demo_framework)
endif()
if(TARGET "compilation_of__demo_framework")
if(TARGET "compilation_of__demo_framework" AND TEST "compilation of ${plugin_name}")
set_property(TEST "compilation of ${plugin_name}" APPEND PROPERTY FIXTURES_REQUIRED demo_framework_SetupFixture)
endif()
# Link with CGAL
Expand Down Expand Up @@ -98,4 +81,5 @@ include(${CGAL_MODULES_DIR}/CGAL_add_test.cmake)
string(TIMESTAMP VERSION "%Y-%m-%d %H:%M")
file(APPEND ${filename} "\"ConfigDate\" : \"${VERSION}\" }")
endif()
CGAL_install_hooks()
endmacro(polyhedron_demo_plugin)

0 comments on commit 3b4d0cf

Please sign in to comment.