From d7a705ccaa0bbecf80e5780b57dd0faccd14b95a Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Tue, 10 Dec 2024 15:06:06 +0100 Subject: [PATCH] update tetgen handling to avoid CMake deprecation warning --- cmake/tetgen.cmake | 59 ++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/cmake/tetgen.cmake b/cmake/tetgen.cmake index 3e56303..1788ab0 100644 --- a/cmake/tetgen.cmake +++ b/cmake/tetgen.cmake @@ -3,47 +3,44 @@ include(FetchContent) message(STATUS "Setting up tetgen") # IMPORTANT NOTE -# We do ot use findPackage here, as we modify the one source file slightly to suppress output via stdout!!! +# We do not use find_package here, as we modify the one source file slightly to suppress output via stdout!!! -#Fetches the version 1.6 for tetgen +# Fetches the version 1.6 for tetgen FetchContent_Declare(tetgen GIT_REPOSITORY https://github.com/libigl/tetgen.git GIT_TAG 4f3bfba3997f20aa1f96cfaff604313a8c2c85b6 # release 1.6 - ) +) -FetchContent_GetProperties(tetgen) -if(NOT tetgen_POPULATED) - FetchContent_Populate(tetgen) +FetchContent_MakeAvailable(tetgen) - # This is ugly, but functional - # We modify one source file in order to prevent console output from the printf function - # without polluting the global include path (which would cause to more uglier issues) - if(NOT EXISTS ${tetgen_SOURCE_DIR}/tetgen_mod.cxx) - message(STATUS "Creating modified tetgen.cxx in order to prevent console output from library") - file(READ ${tetgen_SOURCE_DIR}/tetgen.cxx TETGEN_CXX) +# Modify the tetgen library to suppress console output from the printf function +if(NOT EXISTS ${tetgen_SOURCE_DIR}/tetgen_mod.cxx) + message(STATUS "Creating modified tetgen.cxx in order to prevent console output from library") + file(READ ${tetgen_SOURCE_DIR}/tetgen.cxx TETGEN_CXX) - string(REPLACE - "#include \"tetgen.h\"" - "#include \"tetgen.h\"\n#define printf(fmt, ...) (0)\n" - TETGEN_CXX "${TETGEN_CXX}") + string(REPLACE + "#include \"tetgen.h\"" + "#include \"tetgen.h\"\n#define printf(fmt, ...) (0)\n" + TETGEN_CXX "${TETGEN_CXX}") - file(WRITE ${tetgen_SOURCE_DIR}/tetgen_mod.cxx - "${TETGEN_CXX}" - ) - else() - message(STATUS "A modified tetgen.cxx already exists! It is assumed that is the correct one disabling output") - endif() - - add_library(tetgen STATIC - ${tetgen_SOURCE_DIR}/tetgen_mod.cxx - ${tetgen_SOURCE_DIR}/predicates.cxx - ) + file(WRITE ${tetgen_SOURCE_DIR}/tetgen_mod.cxx + "${TETGEN_CXX}" + ) +else() + message(STATUS "A modified tetgen.cxx already exists! It is assumed that it is the correct one disabling output") +endif() - target_compile_definitions(tetgen PRIVATE -DTETLIBRARY) +# Add the modified version of the tetgen library +add_library(tetgen_lib STATIC + ${tetgen_SOURCE_DIR}/tetgen_mod.cxx + ${tetgen_SOURCE_DIR}/predicates.cxx +) - target_include_directories(tetgen INTERFACE "${tetgen_SOURCE_DIR}") +# Define the TETLIBRARY macro for usage +target_compile_definitions(tetgen_lib PRIVATE -DTETLIBRARY) -endif() +# Include the tetgen source directory for the library +target_include_directories(tetgen_lib INTERFACE "${tetgen_SOURCE_DIR}") # Disable warnings from the library target -target_compile_options(tetgen PRIVATE -w) \ No newline at end of file +target_compile_options(tetgen_lib PRIVATE -w) \ No newline at end of file