Skip to content

Commit

Permalink
update tetgen handling to avoid CMake deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
schuhmaj committed Dec 10, 2024
1 parent b4828a3 commit d7a705c
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions cmake/tetgen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
target_compile_options(tetgen_lib PRIVATE -w)

0 comments on commit d7a705c

Please sign in to comment.