From d1fc84605e66dabc643e6618dd9908d2792ff91f Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 3 Oct 2024 20:01:08 +0800 Subject: [PATCH 01/10] format cmake files --- .cmake-format.py | 37 ++++++ CMakeLists.txt | 224 ++++++++++++++++++--------------- bindings/CMakeLists.txt | 9 +- bindings/c/CMakeLists.txt | 38 ++---- bindings/python/CMakeLists.txt | 68 +++++----- bindings/wasm/CMakeLists.txt | 50 ++++---- extras/CMakeLists.txt | 14 +-- samples/CMakeLists.txt | 19 +-- scripts/format.sh | 7 ++ src/CMakeLists.txt | 101 +++++++-------- test/CMakeLists.txt | 80 ++++++------ 11 files changed, 326 insertions(+), 321 deletions(-) create mode 100644 .cmake-format.py diff --git a/.cmake-format.py b/.cmake-format.py new file mode 100644 index 000000000..bb940abf6 --- /dev/null +++ b/.cmake-format.py @@ -0,0 +1,37 @@ +# ----------------------------- +# Options effecting formatting. +# ----------------------------- +with section("format"): + + # How wide to allow formatted cmake files + line_width = 80 + + # How many spaces to tab for indent + tab_size = 2 + + # If true, separate flow control names from their parentheses with a space + separate_ctrl_name_with_space = False + + # If true, separate function names from parentheses with a space + separate_fn_name_with_space = False + + # If a statement is wrapped to more than one line, than dangle the closing + # parenthesis on its own line. + dangle_parens = False + +with section("markup"): + enable_markup = False + +# parse kwargs for nanobind_add_stub, to not interpret keywords as args +with section("parse"): + additional_commands = { + "nanobind_add_stub": { + "kwargs": { + "MODULE": "*", + "OUTPUT": "*", + "PYTHON_PATH": "*", + "DEPENDS": "*", + "PATTERN_FILE": "*", + } + } + } diff --git a/CMakeLists.txt b/CMakeLists.txt index b198a7ec7..0eb2b6fd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,30 +26,35 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(MANIFOLD_VERSION_MAJOR 2) set(MANIFOLD_VERSION_MINOR 5) set(MANIFOLD_VERSION_PATCH 1) -set(MANIFOLD_VERSION "${MANIFOLD_VERSION_MAJOR}.${MANIFOLD_VERSION_MINOR}.${MANIFOLD_VERSION_PATCH}") +set(MANIFOLD_VERSION + "${MANIFOLD_VERSION_MAJOR}.${MANIFOLD_VERSION_MINOR}.${MANIFOLD_VERSION_PATCH}" +) # Correct MANIFOLD_PAR values to on/off (previous NONE/TBB values should still # work this way) -if (DEFINED MANIFOLD_PAR) - if ("${MANIFOLD_PAR}" STREQUAL "" OR "${MANIFOLD_PAR}" STREQUAL "NONE" OR "${MANIFOLD_PAR}" STREQUAL "OFF") +if(DEFINED MANIFOLD_PAR) + if("${MANIFOLD_PAR}" STREQUAL "" + OR "${MANIFOLD_PAR}" STREQUAL "NONE" + OR "${MANIFOLD_PAR}" STREQUAL "OFF") set(MANIFOLD_PAR OFF) else() set(MANIFOLD_PAR ON) - endif () -endif () + endif() +endif() # Primary user facing options option(MANIFOLD_CROSS_SECTION "Build CrossSection for 2D support" ON) option(MANIFOLD_DEBUG "Enable debug tracing/timing" OFF) -option(MANIFOLD_DOWNLOADS "Allow Manifold build to download missing dependencies" ON) +option(MANIFOLD_DOWNLOADS + "Allow Manifold build to download missing dependencies" ON) option(MANIFOLD_EXCEPTIONS "Build manifold with exception enabled" ON) option(MANIFOLD_EXPORT "Build mesh export (via assimp) utility library" OFF) -option(MANIFOLD_FUZZ "Enable fuzzing tests" OFF) # fuzztest is a rather large dependency option(MANIFOLD_PAR "Enable Parallel backend" OFF) option(MANIFOLD_TEST "Enable testing suite" ON) option(BUILD_SHARED_LIBS "Build shared library" ON) include(CMakeDependentOption) -cmake_dependent_option(MANIFOLD_CBIND "Build C (FFI) bindings" ON "MANIFOLD_CROSS_SECTION" OFF) +cmake_dependent_option(MANIFOLD_CBIND "Build C (FFI) bindings" ON + "MANIFOLD_CROSS_SECTION" OFF) option(MANIFOLD_PYBIND "Build python bindings" OFF) cmake_dependent_option(MANIFOLD_JSBIND "Build js binding" ON "EMSCRIPTEN" OFF) @@ -57,8 +62,9 @@ cmake_dependent_option(MANIFOLD_JSBIND "Build js binding" ON "EMSCRIPTEN" OFF) if(NOT MANIFOLD_FLAGS) set(MANIFOLD_FLAGS "") endif() -set(MANIFOLD_FLAGS "" CACHE STRING "Manifold compiler flags") - +set(MANIFOLD_FLAGS + "" + CACHE STRING "Manifold compiler flags") # Development options option(TRACY_ENABLE "Use tracy profiling" OFF) @@ -68,6 +74,10 @@ mark_as_advanced(TRACY_ENABLE) mark_as_advanced(TRACY_MEMORY_USAGE) mark_as_advanced(BUILD_TEST_CGAL) +# fuzztest is a rather large dependency +option(MANIFOLD_FUZZ "Enable fuzzing tests" OFF) +mark_as_advanced(MANIFOLD_FUZZ) + # Define some paths for CMake include(GNUInstallDirs) @@ -77,23 +87,23 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Various Compiler Flags if(MANIFOLD_FUZZ) if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - message(FATAL_ERROR "fuzztest only supports clang" ) + message(FATAL_ERROR "fuzztest only supports clang") endif() # we should enable debug checks set(MANIFOLD_DEBUG ON) # enable fuzztest fuzzing mode set(FUZZTEST_FUZZING_MODE ON) # address sanitizer required - set(CMAKE_CXX_FLAGS "$CMAKE_CXX_FLAGS -fsanitize=address") + list(APPEND CMAKE_CXX_FLAGS -fsanitize=address) endif() if(TRACY_ENABLE) option(CMAKE_BUILD_TYPE "Build type" RelWithDebInfo) if(TRACY_MEMORY_USAGE) - set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} -DTRACY_MEMORY_USAGE) + list(APPEND MANIFOLD_FLAGS -DTRACY_MEMORY_USAGE) endif() if(NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer") + list(APPEND CMAKE_CXX_FLAGS -fno-omit-frame-pointer) endif() else() option(CMAKE_BUILD_TYPE "Build type" Release) @@ -102,11 +112,13 @@ endif() if(EMSCRIPTEN) message("Building for Emscripten") if(MANIFOLD_EXCEPTIONS) - set(MANIFOLD_FLAGS -fexceptions -D_LIBCUDACXX_HAS_THREAD_API_EXTERNAL -D_LIBCUDACXX_HAS_THREAD_API_CUDA) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sALLOW_MEMORY_GROWTH=1 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0") + list(APPEND MANIFOLD_FLAGS -fexceptions) + list(APPEND CMAKE_EXE_LINKER_FLAGS -sALLOW_MEMORY_GROWTH=1 -fexceptions + -sDISABLE_EXCEPTION_CATCHING=0) else() - set(MANIFOLD_FLAGS -D_LIBCUDACXX_HAS_THREAD_API_EXTERNAL -D_LIBCUDACXX_HAS_THREAD_API_CUDA) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sALLOW_MEMORY_GROWTH=1") + list(APPEND MANIFOLD_FLAGS -D_LIBCUDACXX_HAS_THREAD_API_EXTERNAL + -D_LIBCUDACXX_HAS_THREAD_API_CUDA) + list(APPEND CMAKE_EXE_LINKER_FLAGS -sALLOW_MEMORY_GROWTH=1) endif() set(MANIFOLD_PYBIND OFF) set(BUILD_SHARED_LIBS OFF) @@ -115,31 +127,38 @@ endif() if(CMAKE_EXPORT_COMPILE_COMMANDS AND NOT EMSCRIPTEN) # for nixos set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES - ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) + ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) endif() -if (MSVC) - set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} /DNOMINMAX /bigobj) +if(MSVC) + list(APPEND MANIFOLD_FLAGS /DNOMINMAX /bigobj) else() - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(WARNING_FLAGS -Wall -Wno-unused -Wno-array-bounds - -Wno-stringop-overflow -Wno-alloc-size-larger-than) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + list( + APPEND + WARNING_FLAGS + -Wall + -Wno-unused + -Wno-array-bounds + -Wno-stringop-overflow + -Wno-alloc-size-larger-than) else() - set(WARNING_FLAGS -Wall -Wno-unused -Wno-shorten-64-to-32) + list(APPEND WARNING_FLAGS -Wall -Wno-unused -Wno-shorten-64-to-32) endif() - if (CMAKE_SYSTEM_NAME STREQUAL "Windows") - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(WARNING_FLAGS ${WARNING_FLAGS} -Wno-format) + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + list(APPEND WARNING_FLAGS -Wno-format) endif() else() - set(WARNING_FLAGS ${WARNING_FLAGS} -Werror) + list(APPEND WARNING_FLAGS -Werror) endif() - set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} ${WARNING_FLAGS}) + list(APPEND MANIFOLD_FLAGS ${WARNING_FLAGS}) endif() if(CODE_COVERAGE AND NOT MSVC) - set(COVERAGE_FLAGS -coverage -fno-inline-small-functions -fkeep-inline-functions -fkeep-static-functions) - set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} ${COVERAGE_FLAGS}) + list(APPEND COVERAGE_FLAGS -coverage -fno-inline-small-functions + -fkeep-inline-functions -fkeep-static-functions) + list(APPEND MANIFOLD_FLAGS ${COVERAGE_FLAGS}) add_link_options("-coverage") endif() @@ -148,28 +167,41 @@ set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} isSystemDir) +list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} isSystemDir) if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) endif("${isSystemDir}" STREQUAL "-1") - # Dependencies include(FetchContent) +function(logMissingDep PKG) + if(NOT MANIFOLD_DOWNLOADS) + if(ARGC EQUAL 3) + set(MSG "${ARGV2} enabled, but ${PKG} was not found ") + string(APPEND MSG "and dependency downloading is disabled. ") + else() + set(MSG "${PKG} not found, and dependency downloading disabled. ") + endif() + string(APPEND MSG "Please install ${PKG} and reconfigure.\n") + message(FATAL_ERROR ${MSG}) + endif() +endfunction() + # GLM is required in all configurations. find_package(glm QUIET) if(NOT glm_FOUND) - if (NOT MANIFOLD_DOWNLOADS) - message(FATAL_ERROR "glm not found, and dependency downloading disabled. Please install glm and reconfigure.\n") - endif() + logmissingdep("glm") message(STATUS "glm not found, downloading from source") - set(GLM_BUILD_INSTALL "ON" CACHE STRING "") - FetchContent_Declare(glm + set(GLM_BUILD_INSTALL + "ON" + CACHE STRING "") + FetchContent_Declare( + glm GIT_REPOSITORY https://github.com/g-truc/glm.git GIT_TAG 1.0.1 - GIT_PROGRESS TRUE - ) + GIT_PROGRESS TRUE) FetchContent_MakeAvailable(glm) if(NOT EMSCRIPTEN) install(TARGETS glm) @@ -185,20 +217,21 @@ if(MANIFOLD_PAR) pkg_check_modules(TBB tbb) endif() if(NOT TBB_FOUND) - if (NOT MANIFOLD_DOWNLOADS) - message(FATAL_ERROR "Parallel mode enabled, but TBB was not found and dependency downloading is disabled. Please install TBB and reconfigure.\n") - endif() - + logmissingdep("TBB", "Parallel mode") # TODO - this isn't recommended by the TBB upstream - should we be # doing it? message(STATUS "TBB not found, downloading from source") - set(TBB_TEST OFF CACHE INTERNAL "" FORCE) - set(TBB_STRICT OFF CACHE INTERNAL "" FORCE) - FetchContent_Declare(TBB + set(TBB_TEST + OFF + CACHE INTERNAL "" FORCE) + set(TBB_STRICT + OFF + CACHE INTERNAL "" FORCE) + FetchContent_Declare( + TBB GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git - GIT_TAG v2021.11.0 - GIT_PROGRESS TRUE - ) + GIT_TAG v2021.11.0 + GIT_PROGRESS TRUE) FetchContent_MakeAvailable(TBB) set_property(DIRECTORY ${tbb_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES) # note: we do want to install tbb to the user machine when built from @@ -217,28 +250,28 @@ if(MANIFOLD_CROSS_SECTION) endif() if(Clipper2_FOUND) add_library(Clipper2 SHARED IMPORTED) - set_property(TARGET Clipper2 PROPERTY - IMPORTED_LOCATION ${Clipper2_LINK_LIBRARIES}) + set_property(TARGET Clipper2 PROPERTY IMPORTED_LOCATION + ${Clipper2_LINK_LIBRARIES}) if(WIN32) - set_property(TARGET Clipper2 PROPERTY - IMPORTED_IMPLIB ${Clipper2_LINK_LIBRARIES}) + set_property(TARGET Clipper2 PROPERTY IMPORTED_IMPLIB + ${Clipper2_LINK_LIBRARIES}) endif() target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS}) else() - if (NOT MANIFOLD_DOWNLOADS) - message(FATAL_ERROR "cross_section enabled, but Clipper2 was not found and dependency downloading is disabled. Please install Clipper2 and reconfigure.\n") - endif() + logmissingdep("Clipper2", "cross_section") message(STATUS "clipper2 not found, downloading from source") set(CLIPPER2_UTILS OFF) set(CLIPPER2_EXAMPLES OFF) set(CLIPPER2_TESTS OFF) - set(CLIPPER2_USINGZ "OFF" CACHE STRING "Preempt cache default of USINGZ (we only use 2d)") - FetchContent_Declare(Clipper2 + set(CLIPPER2_USINGZ + "OFF" + CACHE STRING "Preempt cache default of USINGZ (we only use 2d)") + FetchContent_Declare( + Clipper2 GIT_REPOSITORY https://github.com/AngusJohnson/Clipper2.git GIT_TAG ff378668baae3570e9d8070aa9eb339bdd5a6aba GIT_PROGRESS TRUE - SOURCE_SUBDIR CPP - ) + SOURCE_SUBDIR CPP) FetchContent_MakeAvailable(Clipper2) if(NOT EMSCRIPTEN) install(TARGETS Clipper2) @@ -263,17 +296,17 @@ message(STATUS "====================================") message(STATUS "Manifold Build Configuration Summary") message(STATUS "====================================") message(STATUS " ") -if (MXECROSS) +if(MXECROSS) message(STATUS "Environment: MXE") -elseif (APPLE) +elseif(APPLE) message(STATUS "Environment: macOS") -elseif (WIN32) - if (MINGW) +elseif(WIN32) + if(MINGW) message(STATUS "Environment: msys2") else() message(STATUS "Environment: Windows") endif() -elseif (LINUX) +elseif(LINUX) message(STATUS "Environment: Linux") elseif(UNIX) message(STATUS "Environment: Unknown Unix") @@ -289,7 +322,7 @@ message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}") -if (APPLE) +if(APPLE) message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") endif() @@ -312,52 +345,47 @@ if(EMSCRIPTEN) return() endif() - # CMake exports -configure_file(manifoldConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake @ONLY) +configure_file(manifoldConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake @ONLY) include(CMakePackageConfigHelpers) write_basic_package_version_file( ${CMAKE_BINARY_DIR}/cmake/manifoldConfigVersion.cmake VERSION ${MANIFOLD_VERSION} - COMPATIBILITY SameMajorVersion - ) + COMPATIBILITY SameMajorVersion) # Location of inputs for CMake find_package - see: # https://cmake.org/cmake/help/latest/command/find_package.html set(EXPORT_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake) -install(EXPORT manifoldTargets +install( + EXPORT manifoldTargets NAMESPACE manifold:: - DESTINATION ${EXPORT_INSTALL_DIR}/manifold - ) -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake - ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake - DESTINATION ${EXPORT_INSTALL_DIR}/manifold - ) + DESTINATION ${EXPORT_INSTALL_DIR}/manifold) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake + DESTINATION ${EXPORT_INSTALL_DIR}/manifold) # install public headers set(MANIFOLD_PUBLIC_HDRS - include/manifold/common.h - include/manifold/iters.h - include/manifold/manifold.h - include/manifold/optional_assert.h - include/manifold/parallel.h - include/manifold/polygon.h - include/manifold/vec_view.h - ) - -if (MANIFOLD_CROSS_SECTION) + include/manifold/common.h + include/manifold/iters.h + include/manifold/manifold.h + include/manifold/optional_assert.h + include/manifold/parallel.h + include/manifold/polygon.h + include/manifold/vec_view.h) + +if(MANIFOLD_CROSS_SECTION) list(APPEND MANIFOLD_PUBLIC_HDRS include/manifold/cross_section.h) endif() -if (MANIFOLD_EXPORT) +if(MANIFOLD_EXPORT) list(APPEND MANIFOLD_PUBLIC_HDRS include/manifold/meshIO.h) endif() install(FILES ${MANIFOLD_PUBLIC_HDRS} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold - ) + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold) # PkgConfig file if(MANIFOLD_CROSS_SECTION) @@ -365,12 +393,4 @@ if(MANIFOLD_CROSS_SECTION) endif() configure_file(manifold.pc.in ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) - - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index d7f1d557a..dcf8429c4 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (NOT MANIFOLD_CROSS_SECTION) +if(NOT MANIFOLD_CROSS_SECTION) return() endif() @@ -27,10 +27,3 @@ endif() if(EMSCRIPTEN AND MANIFOLD_JSBIND) add_subdirectory(wasm) endif() - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index e7822925f..3e5392a6c 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -1,24 +1,16 @@ # this is a shared library for FFI bindings include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../include - ) + ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../include) -add_library(manifoldc SHARED - manifoldc.cpp - conv.cpp - box.cpp - cross.cpp - rect.cpp - ) +add_library(manifoldc SHARED manifoldc.cpp conv.cpp box.cpp cross.cpp rect.cpp) if(MSVC) set_target_properties(manifoldc PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) set_target_properties(manifoldc PROPERTIES RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/bin ) + ${CMAKE_BINARY_DIR}/bin) set_target_properties(manifoldc PROPERTIES LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/bin ) + ${CMAKE_BINARY_DIR}/bin) endif() if(MANIFOLD_EXPORT) @@ -28,22 +20,12 @@ endif() target_link_libraries(manifoldc PRIVATE manifold) -target_include_directories(manifoldc PUBLIC - $ - $ - ) +target_include_directories( + manifoldc PUBLIC $ + $) target_compile_options(manifoldc PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(manifoldc PRIVATE cxx_std_17) install(TARGETS manifoldc EXPORT manifoldTargets) -install(FILES - include/manifold/manifoldc.h - include/manifold/types.h DESTINATION - ${CMAKE_INSTALL_INCLUDEDIR}/manifold) - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 +install(FILES include/manifold/manifoldc.h include/manifold/types.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index cd8df5455..3ee50fa28 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -19,9 +19,15 @@ endif() project(python) if(Python_VERSION VERSION_LESS 3.12) - find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) + find_package( + Python + COMPONENTS Interpreter Development.Module + REQUIRED) else() - find_package(Python COMPONENTS Interpreter Development.SABIModule REQUIRED) + find_package( + Python + COMPONENTS Interpreter Development.SABIModule + REQUIRED) endif() if(Python_VERSION VERSION_GREATER_EQUAL 3.11) set(MANIFOLD_PYBIND_STUBGEN ON) @@ -33,22 +39,24 @@ endif() execute_process( COMMAND "${Python_EXECUTABLE}" -m nanobind --version - OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_VERSION) + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE NB_VERSION) # we are fine with 2.0.0 if(NB_VERSION VERSION_GREATER_EQUAL 2.0.0) message("Found nanobind, version ${NB_VERSION}") execute_process( COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir - OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT) + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE nanobind_ROOT) find_package(nanobind CONFIG REQUIRED) else() message(STATUS "nanobind not found, downloading from source") include(FetchContent) - FetchContent_Declare(nanobind + FetchContent_Declare( + nanobind GIT_REPOSITORY https://github.com/wjakob/nanobind.git GIT_TAG 9641bb7151f04120013b812789b3ebdfa7e7324f # v2.1.0 - GIT_PROGRESS TRUE - ) + GIT_PROGRESS TRUE) FetchContent_MakeAvailable(nanobind) endif() @@ -57,11 +65,8 @@ if(NB_VERSION VERSION_LESS 2.1.0) set(MANIFOLD_PYBIND_STUBGEN OFF) endif() -nanobind_add_module( - manifold3d - NB_STATIC STABLE_ABI LTO - autogen_docstrings.inl - manifold3d.cpp) +nanobind_add_module(manifold3d NB_STATIC STABLE_ABI LTO autogen_docstrings.inl + manifold3d.cpp) if(MANIFOLD_PYBIND_STUBGEN) nanobind_add_stub( @@ -70,31 +75,29 @@ if(MANIFOLD_PYBIND_STUBGEN) OUTPUT manifold3d.pyi PYTHON_PATH $ DEPENDS manifold3d - PATTERN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/stub_pattern.txt - ) + PATTERN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/stub_pattern.txt) endif() target_link_libraries(manifold3d PRIVATE manifold) -target_compile_options(manifold3d PRIVATE ${MANIFOLD_FLAGS} -DMODULE_NAME=manifold3d) +target_compile_options(manifold3d PRIVATE ${MANIFOLD_FLAGS} + -DMODULE_NAME=manifold3d) target_compile_features(manifold3d PUBLIC cxx_std_17) set_target_properties(manifold3d PROPERTIES OUTPUT_NAME "manifold3d") message(Python_EXECUTABLE = ${Python_EXECUTABLE}) # ideally we should generate a dependency file from python... set(DOCSTRING_DEPS - ${CMAKE_SOURCE_DIR}/src/manifold.cpp - ${CMAKE_SOURCE_DIR}/src/constructors.cpp - ${CMAKE_SOURCE_DIR}/src/sort.cpp - ${CMAKE_SOURCE_DIR}/src/cross_section/cross_section.cpp - ${CMAKE_SOURCE_DIR}/src/polygon.cpp - ${CMAKE_SOURCE_DIR}/include/manifold/common.h - ) + ${CMAKE_SOURCE_DIR}/src/manifold.cpp + ${CMAKE_SOURCE_DIR}/src/constructors.cpp + ${CMAKE_SOURCE_DIR}/src/sort.cpp + ${CMAKE_SOURCE_DIR}/src/cross_section/cross_section.cpp + ${CMAKE_SOURCE_DIR}/src/polygon.cpp + ${CMAKE_SOURCE_DIR}/include/manifold/common.h) add_custom_command( OUTPUT autogen_docstrings.inl DEPENDS ${DOCSTRING_DEPS} COMMAND ${Python_EXECUTABLE} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/gen_docs.py - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(manifold3d PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) if(SKBUILD) @@ -103,22 +106,11 @@ else() set(MANIFOLD_PYBIND_LIBDIR ${Python_SITEARCH}) endif() -install( - TARGETS manifold3d - LIBRARY DESTINATION ${MANIFOLD_PYBIND_LIBDIR} - COMPONENT bindings - ) +install(TARGETS manifold3d LIBRARY DESTINATION ${MANIFOLD_PYBIND_LIBDIR} + COMPONENT bindings) if(MANIFOLD_PYBIND_STUBGEN) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold3d.pyi DESTINATION ${MANIFOLD_PYBIND_LIBDIR} - COMPONENT bindings - ) + COMPONENT bindings) endif() - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 diff --git a/bindings/wasm/CMakeLists.txt b/bindings/wasm/CMakeLists.txt index e61a571b6..b07fb1467 100644 --- a/bindings/wasm/CMakeLists.txt +++ b/bindings/wasm/CMakeLists.txt @@ -16,11 +16,21 @@ project(wasm) add_executable(manifoldjs bindings.cpp) -set_source_files_properties(bindings.cpp PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js) +set_source_files_properties( + bindings.cpp PROPERTIES OBJECT_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js) target_link_libraries(manifoldjs manifold) target_compile_options(manifoldjs PRIVATE ${MANIFOLD_FLAGS}) -target_link_options(manifoldjs PUBLIC --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js --bind -sALLOW_TABLE_GROWTH=1 - -sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction -sMODULARIZE=1 -sEXPORT_ES6=1) +target_link_options( + manifoldjs + PUBLIC + --pre-js + ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js + --bind + -sALLOW_TABLE_GROWTH=1 + -sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction + -sMODULARIZE=1 + -sEXPORT_ES6=1) target_compile_features(manifoldjs PUBLIC cxx_std_17) set_target_properties(manifoldjs PROPERTIES OUTPUT_NAME "manifold") @@ -29,33 +39,25 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples/built) # ensure that interface files are copied over when modified add_custom_target(js_deps ALL - DEPENDS manifoldjs - ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts) + DEPENDS manifoldjs ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts) # copy WASM build back here for publishing to npm add_custom_command( - TARGET js_deps POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/manifold.* - ${CMAKE_CURRENT_SOURCE_DIR}) + TARGET js_deps + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/manifold.* + ${CMAKE_CURRENT_SOURCE_DIR}) # copy WASM build and TS declarations for Vite to package into ManifoldCAD.org add_custom_command( - TARGET js_deps POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/manifold* - ${CMAKE_CURRENT_SOURCE_DIR}/examples/built/) + TARGET js_deps + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/manifold* + ${CMAKE_CURRENT_SOURCE_DIR}/examples/built/) # copy TS declarations to public so they can be accessed by our editor add_custom_command( - TARGET js_deps POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts - ${CMAKE_CURRENT_SOURCE_DIR}/examples/public/) - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 + TARGET js_deps + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts + ${CMAKE_CURRENT_SOURCE_DIR}/examples/public/) diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index f46192b42..d71fd81ef 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -52,21 +52,15 @@ if(BUILD_TEST_CGAL) find_package(CGAL REQUIRED COMPONENTS Core) find_package(Boost REQUIRED COMPONENTS thread) target_compile_definitions(perfTestCGAL PRIVATE CGAL_USE_GMPXX) - target_link_libraries(perfTestCGAL manifold CGAL::CGAL CGAL::CGAL_Core Boost::thread) + target_link_libraries(perfTestCGAL manifold CGAL::CGAL CGAL::CGAL_Core + Boost::thread) target_compile_options(perfTestCGAL PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(perfTestCGAL PUBLIC cxx_std_17) add_executable(testHullPerformance test_hull_performance.cpp) target_compile_definitions(testHullPerformance PRIVATE CGAL_USE_GMPXX) - target_link_libraries(testHullPerformance manifold samples CGAL::CGAL CGAL::CGAL_Core Boost::thread) + target_link_libraries(testHullPerformance manifold samples CGAL::CGAL + CGAL::CGAL_Core Boost::thread) target_compile_options(testHullPerformance PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(testHullPerformance PUBLIC cxx_std_17) endif() - - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 20f8ad7da..d1c49e490 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -12,29 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (NOT MANIFOLD_TEST) +if(NOT MANIFOLD_TEST) return() endif() -add_library(samples src/menger_sponge.cpp - src/rounded_frame.cpp src/scallop.cpp src/tet_puzzle.cpp - src/gyroid_module.cpp src/condensed_matter.cpp) +add_library( + samples src/menger_sponge.cpp src/rounded_frame.cpp src/scallop.cpp + src/tet_puzzle.cpp src/gyroid_module.cpp src/condensed_matter.cpp) if(MANIFOLD_CROSS_SECTION) target_sources(samples PUBLIC src/bracelet.cpp src/knot.cpp) endif() -target_include_directories(samples - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include - ) +target_include_directories(samples PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(samples PUBLIC manifold) target_compile_options(samples PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(samples PUBLIC cxx_std_17) - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 diff --git a/scripts/format.sh b/scripts/format.sh index 13aa65241..487c9cb7b 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -17,3 +17,10 @@ $CLANG_FORMAT -i bindings/wasm/examples/public/*.{js,ts} $CLANG_FORMAT -i src/*/src/*.{h,cpp} $CLANG_FORMAT -i src/*/include/manifold/*.h black bindings/python/examples/*.py + +for f in $(find -name CMakeLists.txt); do + # skip build directories + if [[ $f != *build* ]]; then + cmake-format -i $f + fi +done diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2d417fcb4..37cf63ae0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,49 +16,43 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}") set(MANIFOLD_SRCS - boolean3.cpp - boolean_result.cpp - constructors.cpp - csg_tree.cpp - edge_op.cpp - face_op.cpp - impl.cpp - manifold.cpp - polygon.cpp - properties.cpp - quickhull.cpp - sdf.cpp - smoothing.cpp - sort.cpp - subdivision.cpp - ) + boolean3.cpp + boolean_result.cpp + constructors.cpp + csg_tree.cpp + edge_op.cpp + face_op.cpp + impl.cpp + manifold.cpp + polygon.cpp + properties.cpp + quickhull.cpp + sdf.cpp + smoothing.cpp + sort.cpp + subdivision.cpp) set(MANIFOLD_PRIVATE_HDRS - boolean3.h - collider.h - csg_tree.h - hashtable.h - impl.h - mesh_fixes.h - quickhull.h - shared.h - sparse.h - svd.h - tri_dist.h - utils.h - vec.h - ) + boolean3.h + collider.h + csg_tree.h + hashtable.h + impl.h + mesh_fixes.h + quickhull.h + shared.h + sparse.h + svd.h + tri_dist.h + utils.h + vec.h) if(MANIFOLD_CROSS_SECTION) - list(APPEND MANIFOLD_SRCS - cross_section/cross_section.cpp - ) + list(APPEND MANIFOLD_SRCS cross_section/cross_section.cpp) endif() if(MANIFOLD_EXPORT) - list(APPEND MANIFOLD_SRCS - meshIO/meshIO.cpp - ) + list(APPEND MANIFOLD_SRCS meshIO/meshIO.cpp) endif() # Dependency libraries @@ -79,9 +73,7 @@ if(MANIFOLD_PAR) endif() #Include directories -set(MANIFOLD_INCLUDE_DIRS - ${CMAKE_SOURCE_DIR}/include - ) +set(MANIFOLD_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/include) if(TBB_INCLUDE_DIRS) list(APPEND MANIFOLD_INCLUDE_DIRS ${TBB_INCLUDE_DIRS}) endif() @@ -90,17 +82,18 @@ add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) set_property(TARGET manifold PROPERTY VERSION "${MANIFOLD_VERSION}") set_property(TARGET manifold PROPERTY SOVERSION ${MANIFOLD_VERSION_MAJOR}) if(MSVC) - set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) + set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS + ON) endif() target_link_libraries(manifold PUBLIC ${MANIFOLD_LIBS}) if(MANIFOLD_FLAGS) target_compile_options(manifold PRIVATE ${MANIFOLD_FLAGS}) endif() -target_include_directories(manifold PUBLIC - $ - $ - PRIVATE ${MANIFOLD_INCLUDE_DIRS} - ) +target_include_directories( + manifold + PUBLIC $ + $ + PRIVATE ${MANIFOLD_INCLUDE_DIRS}) if(MANIFOLD_EXCEPTIONS) target_compile_options(manifold PRIVATE -DMANIFOLD_EXCEPTIONS=1) endif() @@ -119,25 +112,17 @@ endif() install(TARGETS manifold EXPORT manifoldTargets) # Tracy Support -if (MANIFOLD_DOWNLOADS) +if(MANIFOLD_DOWNLOADS) include(FetchContent) - if (TRACY_ENABLE) + if(TRACY_ENABLE) include(FetchContent) - FetchContent_Declare(tracy + FetchContent_Declare( + tracy GIT_REPOSITORY https://github.com/wolfpld/tracy.git GIT_TAG v0.10 GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - ) + GIT_PROGRESS TRUE) FetchContent_MakeAvailable(tracy) target_link_libraries(manifold INTERFACE TracyClient) endif() endif() - - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a41342435..a51d7ed57 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,27 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (NOT MANIFOLD_TEST) +if(NOT MANIFOLD_TEST) return() endif() -if (NOT MANIFOLD_DOWNLOADS) - message("Downloading is disabled, but testing requires googletest - skipping.\n") +if(NOT MANIFOLD_DOWNLOADS) + message( + "Downloading is disabled, but testing requires googletest - skipping.\n") endif() enable_testing() set(SOURCE_FILES - boolean_complex_test.cpp - boolean_test.cpp - hull_test.cpp - manifold_test.cpp - polygon_test.cpp - properties_test.cpp - samples_test.cpp - sdf_test.cpp - smooth_test.cpp - test_main.cpp - ) + boolean_complex_test.cpp + boolean_test.cpp + hull_test.cpp + manifold_test.cpp + polygon_test.cpp + properties_test.cpp + samples_test.cpp + sdf_test.cpp + smooth_test.cpp + test_main.cpp) if(MANIFOLD_CROSS_SECTION) list(APPEND SOURCE_FILES cross_section_test.cpp) @@ -42,19 +42,25 @@ if(MANIFOLD_CBIND AND NOT EMSCRIPTEN) list(APPEND SOURCE_FILES manifoldc_test.cpp) endif() -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +set(gtest_force_shared_crt + ON + CACHE BOOL "" FORCE) # Prevent installation of GTest with your project -set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) -set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) +set(INSTALL_GTEST + OFF + CACHE BOOL "" FORCE) +set(INSTALL_GMOCK + OFF + CACHE BOOL "" FORCE) include(FetchContent) -FetchContent_Declare(googletest +FetchContent_Declare( + googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - FIND_PACKAGE_ARGS NAMES GTest gtest - ) + GIT_TAG v1.14.0 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + FIND_PACKAGE_ARGS NAMES GTest gtest) FetchContent_MakeAvailable(googletest) if(NOT TARGET GTest::gtest_main) @@ -65,12 +71,12 @@ add_executable(manifold_test ${SOURCE_FILES}) target_link_libraries(manifold_test GTest::gtest_main manifold samples) if(MANIFOLD_FUZZ) - FetchContent_Declare(fuzztest + FetchContent_Declare( + fuzztest GIT_REPOSITORY https://github.com/google/fuzztest.git # note that if commit hash is used, it cannot be a shallow clone - GIT_TAG 2606e04a43e5a7730e437a849604a61f1cb0ff28 - GIT_PROGRESS TRUE - ) + GIT_TAG 2606e04a43e5a7730e437a849604a61f1cb0ff28 + GIT_PROGRESS TRUE) FetchContent_MakeAvailable(fuzztest) fuzztest_setup_fuzzing_flags() add_executable(polygon_fuzz polygon_fuzz.cpp) @@ -98,21 +104,17 @@ add_test(test_all manifold_test) target_precompile_headers(manifold_test INTERFACE test.h) if(EMSCRIPTEN) - set_target_properties(manifold_test PROPERTIES LINK_FLAGS - "-s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 --bind --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons") + set_target_properties( + manifold_test + PROPERTIES + LINK_FLAGS + "-s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 --bind --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons" + ) endif() if(MSVC) set_target_properties(manifold_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/bin ) + ${CMAKE_BINARY_DIR}/bin) set_target_properties(manifold_test PROPERTIES LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/bin ) + ${CMAKE_BINARY_DIR}/bin) endif() - - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 From 02194f6105c0a1ddf8914b4e57e3211128582415 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 3 Oct 2024 20:07:08 +0800 Subject: [PATCH 02/10] update format.sh --- manifoldConfig.cmake.in | 14 +++++++------- scripts/format.sh | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/manifoldConfig.cmake.in b/manifoldConfig.cmake.in index 06a019a8e..710f0f26f 100644 --- a/manifoldConfig.cmake.in +++ b/manifoldConfig.cmake.in @@ -15,18 +15,18 @@ set(glm_ROOT "${_FIND_ROOT}") find_package(glm REQUIRED) set(MANIFOLD_CROSS_SECTION "@MANIFOLD_CROSS_SECTION@") if(MANIFOLD_CROSS_SECTION) - set(Clipper2_ROOT "${_FIND_ROOT}") - find_package(Clipper2 REQUIRED) + set(Clipper2_ROOT "${_FIND_ROOT}") + find_package(Clipper2 REQUIRED) endif() set(MANIFOLD_PAR "@MANIFOLD_PAR@") if(MANIFOLD_PAR STREQUAL "ON") - find_package(TBB REQUIRED) - if(APPLE) - find_package(oneDPL REQUIRED) - endif() + find_package(TBB REQUIRED) + if(APPLE) + find_package(oneDPL REQUIRED) + endif() endif() set(MANIFOLD_EXPORT "@MANIFOLD_EXPORT@") if(MANIFOLD_EXPORT) - find_package(assimp REQUIRED) + find_package(assimp REQUIRED) endif(MANIFOLD_EXPORT) include("${CMAKE_CURRENT_LIST_DIR}/manifoldTargets.cmake") diff --git a/scripts/format.sh b/scripts/format.sh index 487c9cb7b..bc26793b2 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -6,16 +6,17 @@ CLANG_FORMAT=clang-format fi $CLANG_FORMAT -i extras/*.cpp -$CLANG_FORMAT -i meshIO/**/*.{h,cpp} -$CLANG_FORMAT -i samples/**/*.{h,cpp} +$CLANG_FORMAT -i samples/*/*.{h,cpp} $CLANG_FORMAT -i test/*.{h,cpp} $CLANG_FORMAT -i bindings/*/*.cpp $CLANG_FORMAT -i bindings/c/include/manifold/*.h $CLANG_FORMAT -i bindings/wasm/*.{js,ts} $CLANG_FORMAT -i bindings/wasm/examples/*.{js,ts,html} $CLANG_FORMAT -i bindings/wasm/examples/public/*.{js,ts} -$CLANG_FORMAT -i src/*/src/*.{h,cpp} -$CLANG_FORMAT -i src/*/include/manifold/*.h +$CLANG_FORMAT -i src/*.{h,cpp} +$CLANG_FORMAT -i src/*/*.cpp +$CLANG_FORMAT -i include/manifold/*.h + black bindings/python/examples/*.py for f in $(find -name CMakeLists.txt); do @@ -24,3 +25,10 @@ for f in $(find -name CMakeLists.txt); do cmake-format -i $f fi done + +for f in $(find -name '*.cmake.in'); do + # skip build directories + if [[ $f != *build* ]]; then + cmake-format -i $f + fi +done From b47e25124b301b97c289f9e7bbeb2b47c52604de Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 3 Oct 2024 20:14:17 +0800 Subject: [PATCH 03/10] fix linker flags for emscripten --- CMakeLists.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0eb2b6fd3..c05eb2f6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,12 +113,11 @@ if(EMSCRIPTEN) message("Building for Emscripten") if(MANIFOLD_EXCEPTIONS) list(APPEND MANIFOLD_FLAGS -fexceptions) - list(APPEND CMAKE_EXE_LINKER_FLAGS -sALLOW_MEMORY_GROWTH=1 -fexceptions - -sDISABLE_EXCEPTION_CATCHING=0) + string( + APPEND CMAKE_EXE_LINKER_FLAGS + "-sALLOW_MEMORY_GROWTH=1 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0 ") else() - list(APPEND MANIFOLD_FLAGS -D_LIBCUDACXX_HAS_THREAD_API_EXTERNAL - -D_LIBCUDACXX_HAS_THREAD_API_CUDA) - list(APPEND CMAKE_EXE_LINKER_FLAGS -sALLOW_MEMORY_GROWTH=1) + string(APPEND CMAKE_EXE_LINKER_FLAGS "-sALLOW_MEMORY_GROWTH=1 ") endif() set(MANIFOLD_PYBIND OFF) set(BUILD_SHARED_LIBS OFF) From dc46b08d6f0a02f5f15eafcd45e75c908121f601 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 3 Oct 2024 20:38:55 +0800 Subject: [PATCH 04/10] update readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84f60cd60..5920a98a0 100644 --- a/README.md +++ b/README.md @@ -161,10 +161,12 @@ Contributions are welcome! A lower barrier contribution is to simply make a PR t ### Formatting There is a formatting script `format.sh` that automatically formats everything. -It requires clang-format 11 and black formatter for python. +It requires clang-format, black formatter for python and [cmake-format](https://github.com/cheshirekow/cmake_format) for formatting cmake files. -If you have clang-format installed but without clang-11, you can specify the -clang-format executable by setting the `CLANG_FORMAT` environment variable. +Note that our script can run with clang-format older than 18, but the GitHub +action check may fail due to slight differences between different versions of +clang-format. In that case, either update your clang-format version or apply the +patch from the GitHub action log. ### Profiling From c78178cd989753283eee0c22da1248acc01c58cc Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 4 Oct 2024 11:11:23 +0800 Subject: [PATCH 05/10] use gersemi --- .cmake-format.py | 37 ------------------------------ .gersemirc | 2 ++ .github/workflows/check_format.yml | 9 ++++++++ README.md | 2 +- scripts/format.sh | 4 ++-- scripts/gersemi-check.sh | 25 ++++++++++++++++++++ 6 files changed, 39 insertions(+), 40 deletions(-) delete mode 100644 .cmake-format.py create mode 100644 .gersemirc create mode 100755 scripts/gersemi-check.sh diff --git a/.cmake-format.py b/.cmake-format.py deleted file mode 100644 index bb940abf6..000000000 --- a/.cmake-format.py +++ /dev/null @@ -1,37 +0,0 @@ -# ----------------------------- -# Options effecting formatting. -# ----------------------------- -with section("format"): - - # How wide to allow formatted cmake files - line_width = 80 - - # How many spaces to tab for indent - tab_size = 2 - - # If true, separate flow control names from their parentheses with a space - separate_ctrl_name_with_space = False - - # If true, separate function names from parentheses with a space - separate_fn_name_with_space = False - - # If a statement is wrapped to more than one line, than dangle the closing - # parenthesis on its own line. - dangle_parens = False - -with section("markup"): - enable_markup = False - -# parse kwargs for nanobind_add_stub, to not interpret keywords as args -with section("parse"): - additional_commands = { - "nanobind_add_stub": { - "kwargs": { - "MODULE": "*", - "OUTPUT": "*", - "PYTHON_PATH": "*", - "DEPENDS": "*", - "PATTERN_FILE": "*", - } - } - } diff --git a/.gersemirc b/.gersemirc new file mode 100644 index 000000000..697be5487 --- /dev/null +++ b/.gersemirc @@ -0,0 +1,2 @@ +line_length: 80 +indent: 2 diff --git a/.github/workflows/check_format.yml b/.github/workflows/check_format.yml index c91c3e451..bb82889e3 100644 --- a/.github/workflows/check_format.yml +++ b/.github/workflows/check_format.yml @@ -22,3 +22,12 @@ jobs: with: options: "--check --verbose" src: "./bindings/python/examples" + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' + - name: "gersemi cmake check" + run: | + pip3 install gersemi + ./scripts/gersemi-check.sh + diff --git a/README.md b/README.md index 5920a98a0..2a6ee6ba5 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ Contributions are welcome! A lower barrier contribution is to simply make a PR t ### Formatting There is a formatting script `format.sh` that automatically formats everything. -It requires clang-format, black formatter for python and [cmake-format](https://github.com/cheshirekow/cmake_format) for formatting cmake files. +It requires clang-format, black formatter for python and [gersemi](https://github.com/BlankSpruce/gersemi) for formatting cmake files. Note that our script can run with clang-format older than 18, but the GitHub action check may fail due to slight differences between different versions of diff --git a/scripts/format.sh b/scripts/format.sh index bc26793b2..723d3f2f5 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -22,13 +22,13 @@ black bindings/python/examples/*.py for f in $(find -name CMakeLists.txt); do # skip build directories if [[ $f != *build* ]]; then - cmake-format -i $f + gersemi -i $f fi done for f in $(find -name '*.cmake.in'); do # skip build directories if [[ $f != *build* ]]; then - cmake-format -i $f + gersemi -i $f fi done diff --git a/scripts/gersemi-check.sh b/scripts/gersemi-check.sh new file mode 100755 index 000000000..530499124 --- /dev/null +++ b/scripts/gersemi-check.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +FAILED=0 + +function check() { + if [[ $1 != *build* ]]; then + gersemi -c $1 2> /dev/null + if [ $? -ne 0 ]; then + gersemi --diff $1 2> /dev/null + FAILED=1 + fi + fi +} + +for f in $(find -name CMakeLists.txt); do + check $f +done + +for f in $(find -name '*.cmake.in'); do + check $f +done + +if [[ $FAILED -ne 0 ]]; then + exit 1 +fi From a675462932d6c67b5228b8a3a05533fc019cb345 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 4 Oct 2024 11:11:32 +0800 Subject: [PATCH 06/10] actual format --- CMakeLists.txt | 174 +++++++++++++++++++++------------ bindings/c/CMakeLists.txt | 41 +++++--- bindings/python/CMakeLists.txt | 65 ++++++------ bindings/wasm/CMakeLists.txt | 45 +++++---- extras/CMakeLists.txt | 19 +++- samples/CMakeLists.txt | 10 +- src/CMakeLists.txt | 81 ++++++++------- test/CMakeLists.txt | 59 +++++------ 8 files changed, 305 insertions(+), 189 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c05eb2f6b..feccf217c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,16 +26,19 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(MANIFOLD_VERSION_MAJOR 2) set(MANIFOLD_VERSION_MINOR 5) set(MANIFOLD_VERSION_PATCH 1) -set(MANIFOLD_VERSION - "${MANIFOLD_VERSION_MAJOR}.${MANIFOLD_VERSION_MINOR}.${MANIFOLD_VERSION_PATCH}" +set( + MANIFOLD_VERSION + "${MANIFOLD_VERSION_MAJOR}.${MANIFOLD_VERSION_MINOR}.${MANIFOLD_VERSION_PATCH}" ) # Correct MANIFOLD_PAR values to on/off (previous NONE/TBB values should still # work this way) if(DEFINED MANIFOLD_PAR) - if("${MANIFOLD_PAR}" STREQUAL "" - OR "${MANIFOLD_PAR}" STREQUAL "NONE" - OR "${MANIFOLD_PAR}" STREQUAL "OFF") + if( + "${MANIFOLD_PAR}" STREQUAL "" + OR "${MANIFOLD_PAR}" STREQUAL "NONE" + OR "${MANIFOLD_PAR}" STREQUAL "OFF" + ) set(MANIFOLD_PAR OFF) else() set(MANIFOLD_PAR ON) @@ -45,26 +48,38 @@ endif() # Primary user facing options option(MANIFOLD_CROSS_SECTION "Build CrossSection for 2D support" ON) option(MANIFOLD_DEBUG "Enable debug tracing/timing" OFF) -option(MANIFOLD_DOWNLOADS - "Allow Manifold build to download missing dependencies" ON) +option( + MANIFOLD_DOWNLOADS + "Allow Manifold build to download missing dependencies" + ON +) option(MANIFOLD_EXCEPTIONS "Build manifold with exception enabled" ON) option(MANIFOLD_EXPORT "Build mesh export (via assimp) utility library" OFF) option(MANIFOLD_PAR "Enable Parallel backend" OFF) option(MANIFOLD_TEST "Enable testing suite" ON) option(BUILD_SHARED_LIBS "Build shared library" ON) include(CMakeDependentOption) -cmake_dependent_option(MANIFOLD_CBIND "Build C (FFI) bindings" ON - "MANIFOLD_CROSS_SECTION" OFF) +cmake_dependent_option( + MANIFOLD_CBIND + "Build C (FFI) bindings" + ON + "MANIFOLD_CROSS_SECTION" + OFF +) option(MANIFOLD_PYBIND "Build python bindings" OFF) -cmake_dependent_option(MANIFOLD_JSBIND "Build js binding" ON "EMSCRIPTEN" OFF) +cmake_dependent_option( + MANIFOLD_JSBIND + "Build js binding" + ON + "EMSCRIPTEN" + OFF +) # Set some option values in the CMake cache if(NOT MANIFOLD_FLAGS) set(MANIFOLD_FLAGS "") endif() -set(MANIFOLD_FLAGS - "" - CACHE STRING "Manifold compiler flags") +set(MANIFOLD_FLAGS "" CACHE STRING "Manifold compiler flags") # Development options option(TRACY_ENABLE "Use tracy profiling" OFF) @@ -114,8 +129,10 @@ if(EMSCRIPTEN) if(MANIFOLD_EXCEPTIONS) list(APPEND MANIFOLD_FLAGS -fexceptions) string( - APPEND CMAKE_EXE_LINKER_FLAGS - "-sALLOW_MEMORY_GROWTH=1 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0 ") + APPEND + CMAKE_EXE_LINKER_FLAGS + "-sALLOW_MEMORY_GROWTH=1 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0 " + ) else() string(APPEND CMAKE_EXE_LINKER_FLAGS "-sALLOW_MEMORY_GROWTH=1 ") endif() @@ -125,8 +142,10 @@ endif() if(CMAKE_EXPORT_COMPILE_COMMANDS AND NOT EMSCRIPTEN) # for nixos - set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES - ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) + set( + CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES + ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} + ) endif() if(MSVC) @@ -140,7 +159,8 @@ else() -Wno-unused -Wno-array-bounds -Wno-stringop-overflow - -Wno-alloc-size-larger-than) + -Wno-alloc-size-larger-than + ) else() list(APPEND WARNING_FLAGS -Wall -Wno-unused -Wno-shorten-64-to-32) endif() @@ -155,8 +175,14 @@ else() endif() if(CODE_COVERAGE AND NOT MSVC) - list(APPEND COVERAGE_FLAGS -coverage -fno-inline-small-functions - -fkeep-inline-functions -fkeep-static-functions) + list( + APPEND + COVERAGE_FLAGS + -coverage + -fno-inline-small-functions + -fkeep-inline-functions + -fkeep-static-functions + ) list(APPEND MANIFOLD_FLAGS ${COVERAGE_FLAGS}) add_link_options("-coverage") endif() @@ -166,8 +192,12 @@ set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES - ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} isSystemDir) +list( + FIND + CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + isSystemDir +) if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) endif("${isSystemDir}" STREQUAL "-1") @@ -175,7 +205,7 @@ endif("${isSystemDir}" STREQUAL "-1") # Dependencies include(FetchContent) -function(logMissingDep PKG) +function(logmissingdep PKG) if(NOT MANIFOLD_DOWNLOADS) if(ARGC EQUAL 3) set(MSG "${ARGV2} enabled, but ${PKG} was not found ") @@ -193,14 +223,13 @@ find_package(glm QUIET) if(NOT glm_FOUND) logmissingdep("glm") message(STATUS "glm not found, downloading from source") - set(GLM_BUILD_INSTALL - "ON" - CACHE STRING "") + set(GLM_BUILD_INSTALL "ON" CACHE STRING "") FetchContent_Declare( glm GIT_REPOSITORY https://github.com/g-truc/glm.git GIT_TAG 1.0.1 - GIT_PROGRESS TRUE) + GIT_PROGRESS TRUE + ) FetchContent_MakeAvailable(glm) if(NOT EMSCRIPTEN) install(TARGETS glm) @@ -216,21 +245,18 @@ if(MANIFOLD_PAR) pkg_check_modules(TBB tbb) endif() if(NOT TBB_FOUND) - logmissingdep("TBB", "Parallel mode") + logmissingdep("TBB" , "Parallel mode") # TODO - this isn't recommended by the TBB upstream - should we be # doing it? message(STATUS "TBB not found, downloading from source") - set(TBB_TEST - OFF - CACHE INTERNAL "" FORCE) - set(TBB_STRICT - OFF - CACHE INTERNAL "" FORCE) + set(TBB_TEST OFF CACHE INTERNAL "" FORCE) + set(TBB_STRICT OFF CACHE INTERNAL "" FORCE) FetchContent_Declare( TBB GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git GIT_TAG v2021.11.0 - GIT_PROGRESS TRUE) + GIT_PROGRESS TRUE + ) FetchContent_MakeAvailable(TBB) set_property(DIRECTORY ${tbb_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES) # note: we do want to install tbb to the user machine when built from @@ -249,28 +275,36 @@ if(MANIFOLD_CROSS_SECTION) endif() if(Clipper2_FOUND) add_library(Clipper2 SHARED IMPORTED) - set_property(TARGET Clipper2 PROPERTY IMPORTED_LOCATION - ${Clipper2_LINK_LIBRARIES}) + set_property( + TARGET Clipper2 + PROPERTY IMPORTED_LOCATION ${Clipper2_LINK_LIBRARIES} + ) if(WIN32) - set_property(TARGET Clipper2 PROPERTY IMPORTED_IMPLIB - ${Clipper2_LINK_LIBRARIES}) + set_property( + TARGET Clipper2 + PROPERTY IMPORTED_IMPLIB ${Clipper2_LINK_LIBRARIES} + ) endif() target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS}) else() - logmissingdep("Clipper2", "cross_section") + logmissingdep("Clipper2" , "cross_section") message(STATUS "clipper2 not found, downloading from source") set(CLIPPER2_UTILS OFF) set(CLIPPER2_EXAMPLES OFF) set(CLIPPER2_TESTS OFF) - set(CLIPPER2_USINGZ - "OFF" - CACHE STRING "Preempt cache default of USINGZ (we only use 2d)") + set( + CLIPPER2_USINGZ + "OFF" + CACHE STRING + "Preempt cache default of USINGZ (we only use 2d)" + ) FetchContent_Declare( Clipper2 GIT_REPOSITORY https://github.com/AngusJohnson/Clipper2.git GIT_TAG ff378668baae3570e9d8070aa9eb339bdd5a6aba GIT_PROGRESS TRUE - SOURCE_SUBDIR CPP) + SOURCE_SUBDIR CPP + ) FetchContent_MakeAvailable(Clipper2) if(NOT EMSCRIPTEN) install(TARGETS Clipper2) @@ -345,13 +379,17 @@ if(EMSCRIPTEN) endif() # CMake exports -configure_file(manifoldConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake @ONLY) +configure_file( + manifoldConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake + @ONLY +) include(CMakePackageConfigHelpers) write_basic_package_version_file( ${CMAKE_BINARY_DIR}/cmake/manifoldConfigVersion.cmake VERSION ${MANIFOLD_VERSION} - COMPATIBILITY SameMajorVersion) + COMPATIBILITY SameMajorVersion +) # Location of inputs for CMake find_package - see: # https://cmake.org/cmake/help/latest/command/find_package.html @@ -360,20 +398,26 @@ set(EXPORT_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake) install( EXPORT manifoldTargets NAMESPACE manifold:: - DESTINATION ${EXPORT_INSTALL_DIR}/manifold) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake - ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake - DESTINATION ${EXPORT_INSTALL_DIR}/manifold) + DESTINATION ${EXPORT_INSTALL_DIR}/manifold +) +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake + DESTINATION ${EXPORT_INSTALL_DIR}/manifold +) # install public headers -set(MANIFOLD_PUBLIC_HDRS - include/manifold/common.h - include/manifold/iters.h - include/manifold/manifold.h - include/manifold/optional_assert.h - include/manifold/parallel.h - include/manifold/polygon.h - include/manifold/vec_view.h) +set( + MANIFOLD_PUBLIC_HDRS + include/manifold/common.h + include/manifold/iters.h + include/manifold/manifold.h + include/manifold/optional_assert.h + include/manifold/parallel.h + include/manifold/polygon.h + include/manifold/vec_view.h +) if(MANIFOLD_CROSS_SECTION) list(APPEND MANIFOLD_PUBLIC_HDRS include/manifold/cross_section.h) @@ -383,13 +427,17 @@ if(MANIFOLD_EXPORT) list(APPEND MANIFOLD_PUBLIC_HDRS include/manifold/meshIO.h) endif() -install(FILES ${MANIFOLD_PUBLIC_HDRS} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold) +install( + FILES ${MANIFOLD_PUBLIC_HDRS} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold +) # PkgConfig file if(MANIFOLD_CROSS_SECTION) set(TEMPLATE_OPTIONAL_CLIPPER "Clipper2") endif() configure_file(manifold.pc.in ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig +) diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 3e5392a6c..6c65476c4 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -1,16 +1,30 @@ # this is a shared library for FFI bindings include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../include) + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../include +) -add_library(manifoldc SHARED manifoldc.cpp conv.cpp box.cpp cross.cpp rect.cpp) +add_library( + manifoldc + SHARED + manifoldc.cpp + conv.cpp + box.cpp + cross.cpp + rect.cpp +) if(MSVC) set_target_properties(manifoldc PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) - set_target_properties(manifoldc PROPERTIES RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/bin) - set_target_properties(manifoldc PROPERTIES LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/bin) + set_target_properties( + manifoldc + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + ) + set_target_properties( + manifoldc + PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + ) endif() if(MANIFOLD_EXPORT) @@ -21,11 +35,16 @@ endif() target_link_libraries(manifoldc PRIVATE manifold) target_include_directories( - manifoldc PUBLIC $ - $) + manifoldc + PUBLIC + $ + $ +) target_compile_options(manifoldc PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(manifoldc PRIVATE cxx_std_17) install(TARGETS manifoldc EXPORT manifoldTargets) -install(FILES include/manifold/manifoldc.h include/manifold/types.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold) +install( + FILES include/manifold/manifoldc.h include/manifold/types.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold +) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 3ee50fa28..ee8c9b6a0 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -19,15 +19,9 @@ endif() project(python) if(Python_VERSION VERSION_LESS 3.12) - find_package( - Python - COMPONENTS Interpreter Development.Module - REQUIRED) + find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) else() - find_package( - Python - COMPONENTS Interpreter Development.SABIModule - REQUIRED) + find_package(Python COMPONENTS Interpreter Development.SABIModule REQUIRED) endif() if(Python_VERSION VERSION_GREATER_EQUAL 3.11) set(MANIFOLD_PYBIND_STUBGEN ON) @@ -40,14 +34,16 @@ endif() execute_process( COMMAND "${Python_EXECUTABLE}" -m nanobind --version OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE NB_VERSION) + OUTPUT_VARIABLE NB_VERSION +) # we are fine with 2.0.0 if(NB_VERSION VERSION_GREATER_EQUAL 2.0.0) message("Found nanobind, version ${NB_VERSION}") execute_process( COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE nanobind_ROOT) + OUTPUT_VARIABLE nanobind_ROOT + ) find_package(nanobind CONFIG REQUIRED) else() message(STATUS "nanobind not found, downloading from source") @@ -55,8 +51,10 @@ else() FetchContent_Declare( nanobind GIT_REPOSITORY https://github.com/wjakob/nanobind.git - GIT_TAG 9641bb7151f04120013b812789b3ebdfa7e7324f # v2.1.0 - GIT_PROGRESS TRUE) + GIT_TAG + 9641bb7151f04120013b812789b3ebdfa7e7324f # v2.1.0 + GIT_PROGRESS TRUE + ) FetchContent_MakeAvailable(nanobind) endif() @@ -66,7 +64,8 @@ if(NB_VERSION VERSION_LESS 2.1.0) endif() nanobind_add_module(manifold3d NB_STATIC STABLE_ABI LTO autogen_docstrings.inl - manifold3d.cpp) + manifold3d.cpp +) if(MANIFOLD_PYBIND_STUBGEN) nanobind_add_stub( @@ -75,29 +74,36 @@ if(MANIFOLD_PYBIND_STUBGEN) OUTPUT manifold3d.pyi PYTHON_PATH $ DEPENDS manifold3d - PATTERN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/stub_pattern.txt) + PATTERN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/stub_pattern.txt + ) endif() target_link_libraries(manifold3d PRIVATE manifold) -target_compile_options(manifold3d PRIVATE ${MANIFOLD_FLAGS} - -DMODULE_NAME=manifold3d) +target_compile_options( + manifold3d + PRIVATE ${MANIFOLD_FLAGS} -DMODULE_NAME=manifold3d +) target_compile_features(manifold3d PUBLIC cxx_std_17) set_target_properties(manifold3d PROPERTIES OUTPUT_NAME "manifold3d") message(Python_EXECUTABLE = ${Python_EXECUTABLE}) # ideally we should generate a dependency file from python... -set(DOCSTRING_DEPS - ${CMAKE_SOURCE_DIR}/src/manifold.cpp - ${CMAKE_SOURCE_DIR}/src/constructors.cpp - ${CMAKE_SOURCE_DIR}/src/sort.cpp - ${CMAKE_SOURCE_DIR}/src/cross_section/cross_section.cpp - ${CMAKE_SOURCE_DIR}/src/polygon.cpp - ${CMAKE_SOURCE_DIR}/include/manifold/common.h) +set( + DOCSTRING_DEPS + ${CMAKE_SOURCE_DIR}/src/manifold.cpp + ${CMAKE_SOURCE_DIR}/src/constructors.cpp + ${CMAKE_SOURCE_DIR}/src/sort.cpp + ${CMAKE_SOURCE_DIR}/src/cross_section/cross_section.cpp + ${CMAKE_SOURCE_DIR}/src/polygon.cpp + ${CMAKE_SOURCE_DIR}/include/manifold/common.h +) add_custom_command( OUTPUT autogen_docstrings.inl DEPENDS ${DOCSTRING_DEPS} - COMMAND ${Python_EXECUTABLE} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/gen_docs.py - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + COMMAND ${Python_EXECUTABLE} + ARGS ${CMAKE_CURRENT_SOURCE_DIR}/gen_docs.py + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) target_include_directories(manifold3d PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) if(SKBUILD) @@ -106,11 +112,14 @@ else() set(MANIFOLD_PYBIND_LIBDIR ${Python_SITEARCH}) endif() -install(TARGETS manifold3d LIBRARY DESTINATION ${MANIFOLD_PYBIND_LIBDIR} - COMPONENT bindings) +install( + TARGETS manifold3d + LIBRARY DESTINATION ${MANIFOLD_PYBIND_LIBDIR} COMPONENT bindings +) if(MANIFOLD_PYBIND_STUBGEN) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold3d.pyi DESTINATION ${MANIFOLD_PYBIND_LIBDIR} - COMPONENT bindings) + COMPONENT bindings + ) endif() diff --git a/bindings/wasm/CMakeLists.txt b/bindings/wasm/CMakeLists.txt index b07fb1467..e2431082d 100644 --- a/bindings/wasm/CMakeLists.txt +++ b/bindings/wasm/CMakeLists.txt @@ -17,20 +17,22 @@ project(wasm) add_executable(manifoldjs bindings.cpp) set_source_files_properties( - bindings.cpp PROPERTIES OBJECT_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js) + bindings.cpp + PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js +) target_link_libraries(manifoldjs manifold) target_compile_options(manifoldjs PRIVATE ${MANIFOLD_FLAGS}) target_link_options( manifoldjs PUBLIC - --pre-js - ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js - --bind - -sALLOW_TABLE_GROWTH=1 - -sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction - -sMODULARIZE=1 - -sEXPORT_ES6=1) + --pre-js + ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js + --bind + -sALLOW_TABLE_GROWTH=1 + -sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction + -sMODULARIZE=1 + -sEXPORT_ES6=1 +) target_compile_features(manifoldjs PUBLIC cxx_std_17) set_target_properties(manifoldjs PROPERTIES OUTPUT_NAME "manifold") @@ -38,26 +40,35 @@ set_target_properties(manifoldjs PROPERTIES OUTPUT_NAME "manifold") file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples/built) # ensure that interface files are copied over when modified -add_custom_target(js_deps ALL - DEPENDS manifoldjs ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts) +add_custom_target( + js_deps + ALL + DEPENDS manifoldjs ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts +) # copy WASM build back here for publishing to npm add_custom_command( TARGET js_deps POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/manifold.* - ${CMAKE_CURRENT_SOURCE_DIR}) + COMMAND + ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/manifold.* + ${CMAKE_CURRENT_SOURCE_DIR} +) # copy WASM build and TS declarations for Vite to package into ManifoldCAD.org add_custom_command( TARGET js_deps POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/manifold* - ${CMAKE_CURRENT_SOURCE_DIR}/examples/built/) + COMMAND + ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/manifold* + ${CMAKE_CURRENT_SOURCE_DIR}/examples/built/ +) # copy TS declarations to public so they can be accessed by our editor add_custom_command( TARGET js_deps POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts - ${CMAKE_CURRENT_SOURCE_DIR}/examples/public/) + COMMAND + ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts + ${CMAKE_CURRENT_SOURCE_DIR}/examples/public/ +) diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index d71fd81ef..ea9130cba 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -52,15 +52,26 @@ if(BUILD_TEST_CGAL) find_package(CGAL REQUIRED COMPONENTS Core) find_package(Boost REQUIRED COMPONENTS thread) target_compile_definitions(perfTestCGAL PRIVATE CGAL_USE_GMPXX) - target_link_libraries(perfTestCGAL manifold CGAL::CGAL CGAL::CGAL_Core - Boost::thread) + target_link_libraries( + perfTestCGAL + manifold + CGAL::CGAL + CGAL::CGAL_Core + Boost::thread + ) target_compile_options(perfTestCGAL PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(perfTestCGAL PUBLIC cxx_std_17) add_executable(testHullPerformance test_hull_performance.cpp) target_compile_definitions(testHullPerformance PRIVATE CGAL_USE_GMPXX) - target_link_libraries(testHullPerformance manifold samples CGAL::CGAL - CGAL::CGAL_Core Boost::thread) + target_link_libraries( + testHullPerformance + manifold + samples + CGAL::CGAL + CGAL::CGAL_Core + Boost::thread + ) target_compile_options(testHullPerformance PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(testHullPerformance PUBLIC cxx_std_17) endif() diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index d1c49e490..c66db5a8f 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -17,8 +17,14 @@ if(NOT MANIFOLD_TEST) endif() add_library( - samples src/menger_sponge.cpp src/rounded_frame.cpp src/scallop.cpp - src/tet_puzzle.cpp src/gyroid_module.cpp src/condensed_matter.cpp) + samples + src/menger_sponge.cpp + src/rounded_frame.cpp + src/scallop.cpp + src/tet_puzzle.cpp + src/gyroid_module.cpp + src/condensed_matter.cpp +) if(MANIFOLD_CROSS_SECTION) target_sources(samples PUBLIC src/bracelet.cpp src/knot.cpp) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 37cf63ae0..4f8bf5184 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,37 +15,41 @@ # For private headers include_directories("${CMAKE_CURRENT_SOURCE_DIR}") -set(MANIFOLD_SRCS - boolean3.cpp - boolean_result.cpp - constructors.cpp - csg_tree.cpp - edge_op.cpp - face_op.cpp - impl.cpp - manifold.cpp - polygon.cpp - properties.cpp - quickhull.cpp - sdf.cpp - smoothing.cpp - sort.cpp - subdivision.cpp) +set( + MANIFOLD_SRCS + boolean3.cpp + boolean_result.cpp + constructors.cpp + csg_tree.cpp + edge_op.cpp + face_op.cpp + impl.cpp + manifold.cpp + polygon.cpp + properties.cpp + quickhull.cpp + sdf.cpp + smoothing.cpp + sort.cpp + subdivision.cpp +) -set(MANIFOLD_PRIVATE_HDRS - boolean3.h - collider.h - csg_tree.h - hashtable.h - impl.h - mesh_fixes.h - quickhull.h - shared.h - sparse.h - svd.h - tri_dist.h - utils.h - vec.h) +set( + MANIFOLD_PRIVATE_HDRS + boolean3.h + collider.h + csg_tree.h + hashtable.h + impl.h + mesh_fixes.h + quickhull.h + shared.h + sparse.h + svd.h + tri_dist.h + utils.h + vec.h +) if(MANIFOLD_CROSS_SECTION) list(APPEND MANIFOLD_SRCS cross_section/cross_section.cpp) @@ -82,8 +86,10 @@ add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) set_property(TARGET manifold PROPERTY VERSION "${MANIFOLD_VERSION}") set_property(TARGET manifold PROPERTY SOVERSION ${MANIFOLD_VERSION_MAJOR}) if(MSVC) - set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS - ON) + set_target_properties( + ${PROJECT_NAME} + PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON + ) endif() target_link_libraries(manifold PUBLIC ${MANIFOLD_LIBS}) if(MANIFOLD_FLAGS) @@ -91,9 +97,11 @@ if(MANIFOLD_FLAGS) endif() target_include_directories( manifold - PUBLIC $ - $ - PRIVATE ${MANIFOLD_INCLUDE_DIRS}) + PUBLIC + $ + $ + PRIVATE ${MANIFOLD_INCLUDE_DIRS} +) if(MANIFOLD_EXCEPTIONS) target_compile_options(manifold PRIVATE -DMANIFOLD_EXCEPTIONS=1) endif() @@ -121,7 +129,8 @@ if(MANIFOLD_DOWNLOADS) GIT_REPOSITORY https://github.com/wolfpld/tracy.git GIT_TAG v0.10 GIT_SHALLOW TRUE - GIT_PROGRESS TRUE) + GIT_PROGRESS TRUE + ) FetchContent_MakeAvailable(tracy) target_link_libraries(manifold INTERFACE TracyClient) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a51d7ed57..29801942d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,22 +17,25 @@ if(NOT MANIFOLD_TEST) endif() if(NOT MANIFOLD_DOWNLOADS) message( - "Downloading is disabled, but testing requires googletest - skipping.\n") + "Downloading is disabled, but testing requires googletest - skipping.\n" + ) endif() enable_testing() -set(SOURCE_FILES - boolean_complex_test.cpp - boolean_test.cpp - hull_test.cpp - manifold_test.cpp - polygon_test.cpp - properties_test.cpp - samples_test.cpp - sdf_test.cpp - smooth_test.cpp - test_main.cpp) +set( + SOURCE_FILES + boolean_complex_test.cpp + boolean_test.cpp + hull_test.cpp + manifold_test.cpp + polygon_test.cpp + properties_test.cpp + samples_test.cpp + sdf_test.cpp + smooth_test.cpp + test_main.cpp +) if(MANIFOLD_CROSS_SECTION) list(APPEND SOURCE_FILES cross_section_test.cpp) @@ -42,16 +45,10 @@ if(MANIFOLD_CBIND AND NOT EMSCRIPTEN) list(APPEND SOURCE_FILES manifoldc_test.cpp) endif() -set(gtest_force_shared_crt - ON - CACHE BOOL "" FORCE) +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Prevent installation of GTest with your project -set(INSTALL_GTEST - OFF - CACHE BOOL "" FORCE) -set(INSTALL_GMOCK - OFF - CACHE BOOL "" FORCE) +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) +set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) include(FetchContent) FetchContent_Declare( @@ -60,7 +57,8 @@ FetchContent_Declare( GIT_TAG v1.14.0 GIT_SHALLOW TRUE GIT_PROGRESS TRUE - FIND_PACKAGE_ARGS NAMES GTest gtest) + FIND_PACKAGE_ARGS NAMES GTest gtest +) FetchContent_MakeAvailable(googletest) if(NOT TARGET GTest::gtest_main) @@ -76,7 +74,8 @@ if(MANIFOLD_FUZZ) GIT_REPOSITORY https://github.com/google/fuzztest.git # note that if commit hash is used, it cannot be a shallow clone GIT_TAG 2606e04a43e5a7730e437a849604a61f1cb0ff28 - GIT_PROGRESS TRUE) + GIT_PROGRESS TRUE + ) FetchContent_MakeAvailable(fuzztest) fuzztest_setup_fuzzing_flags() add_executable(polygon_fuzz polygon_fuzz.cpp) @@ -108,13 +107,17 @@ if(EMSCRIPTEN) manifold_test PROPERTIES LINK_FLAGS - "-s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 --bind --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons" + "-s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 --bind --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons" ) endif() if(MSVC) - set_target_properties(manifold_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/bin) - set_target_properties(manifold_test PROPERTIES LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/bin) + set_target_properties( + manifold_test + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + ) + set_target_properties( + manifold_test + PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + ) endif() From 1efb79495e09b2e1e1e42bf5f3da3c5256000cde Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 4 Oct 2024 21:37:18 +0800 Subject: [PATCH 07/10] should be public instead of interface --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4f8bf5184..99ed177ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -114,7 +114,7 @@ if(MANIFOLD_EXPORT) endif() target_compile_features(manifold PUBLIC cxx_std_17) if(MANIFOLD_PAR) - target_compile_options(manifold INTERFACE -DMANIFOLD_PAR) + target_compile_options(manifold PUBLIC -DMANIFOLD_PAR) endif() install(TARGETS manifold EXPORT manifoldTargets) From 084816690cc2db18408f98a75868570fedda3d8f Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 4 Oct 2024 22:05:17 +0800 Subject: [PATCH 08/10] make test work without download --- test/CMakeLists.txt | 62 +++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 29801942d..582024491 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,14 +15,36 @@ if(NOT MANIFOLD_TEST) return() endif() -if(NOT MANIFOLD_DOWNLOADS) - message( - "Downloading is disabled, but testing requires googletest - skipping.\n" - ) -endif() enable_testing() +find_package(gtest QUIET) +if(NOT gtest_FOUND) + if(NOT MANIFOLD_DOWNLOADS) + message( + WARNING + "Downloading is disabled, but testing requires googletest - skipping.\n" + ) + return() + endif() + + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + # Prevent installation of GTest with your project + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) + + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + FIND_PACKAGE_ARGS NAMES GTest gtest + ) + FetchContent_MakeAvailable(googletest) +endif() + set( SOURCE_FILES boolean_complex_test.cpp @@ -45,22 +67,6 @@ if(MANIFOLD_CBIND AND NOT EMSCRIPTEN) list(APPEND SOURCE_FILES manifoldc_test.cpp) endif() -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -# Prevent installation of GTest with your project -set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) -set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) - -include(FetchContent) -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - FIND_PACKAGE_ARGS NAMES GTest gtest -) -FetchContent_MakeAvailable(googletest) - if(NOT TARGET GTest::gtest_main) add_library(GTest::gtest_main ALIAS gtest_main) endif() @@ -103,11 +109,19 @@ add_test(test_all manifold_test) target_precompile_headers(manifold_test INTERFACE test.h) if(EMSCRIPTEN) + list( + APPEND + EMSCRIPTEN_LINK_FLAGS + -sASSERTIONS=1 + -sDEMANGLE_SUPPORT=1 + --bind + --preload-file + ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons + ) + list(JOIN EMSCRIPTEN_LINK_FLAGS " " EMSCRIPTEN_LINK_FLAGS) set_target_properties( manifold_test - PROPERTIES - LINK_FLAGS - "-s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1 --bind --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons" + PROPERTIES LINK_FLAGS ${EMSCRIPTEN_LINK_FLAGS} ) endif() From 544bfa7ff510de7fd07eb7d6a19b4016dee063ea Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 4 Oct 2024 22:28:29 +0800 Subject: [PATCH 09/10] simplification --- src/CMakeLists.txt | 58 +++++++++++++++++++++++++-------------------- test/CMakeLists.txt | 8 ------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 99ed177ce..d9a23ecf1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -75,8 +75,11 @@ if(MANIFOLD_PAR) list(APPEND MANIFOLD_LIBS ${TBB_LINK_LIBRARIES}) endif() endif() +if(MANIFOLD_EXPORT) + list(APPEND MANIFOLD_LIBS assimp::assimp) +endif() -#Include directories +# Include directories set(MANIFOLD_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/include) if(TBB_INCLUDE_DIRS) list(APPEND MANIFOLD_INCLUDE_DIRS ${TBB_INCLUDE_DIRS}) @@ -102,36 +105,39 @@ target_include_directories( $ PRIVATE ${MANIFOLD_INCLUDE_DIRS} ) -if(MANIFOLD_EXCEPTIONS) - target_compile_options(manifold PRIVATE -DMANIFOLD_EXCEPTIONS=1) -endif() -if(MANIFOLD_DEBUG) - target_compile_options(manifold PRIVATE -DMANIFOLD_DEBUG) -endif() -if(MANIFOLD_EXPORT) - target_link_libraries(manifold PRIVATE assimp::assimp) - target_compile_options(manifold PUBLIC -DMANIFOLD_EXPORT) -endif() + +set(OPTIONS + MANIFOLD_EXCEPTIONS + MANIFOLD_DEBUG + MANIFOLD_CROSS_SECTION + MANIFOLD_EXPORT + MANIFOLD_PAR) +foreach(OPT IN LISTS OPTIONS) + if(${${OPT}}) + target_compile_options(manifold PUBLIC -D${OPT}) + endif() +endforeach() target_compile_features(manifold PUBLIC cxx_std_17) -if(MANIFOLD_PAR) - target_compile_options(manifold PUBLIC -DMANIFOLD_PAR) -endif() install(TARGETS manifold EXPORT manifoldTargets) # Tracy Support -if(MANIFOLD_DOWNLOADS) - include(FetchContent) - if(TRACY_ENABLE) - include(FetchContent) - FetchContent_Declare( - tracy - GIT_REPOSITORY https://github.com/wolfpld/tracy.git - GIT_TAG v0.10 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE +if(TRACY_ENABLE) + if(NOT MANIFOLD_DOWNLOADS) + message( + WARNING + "Downloading is disabled, but tracy requires download - skipping.\n" ) - FetchContent_MakeAvailable(tracy) - target_link_libraries(manifold INTERFACE TracyClient) + return() endif() + include(FetchContent) + FetchContent_Declare( + tracy + GIT_REPOSITORY https://github.com/wolfpld/tracy.git + GIT_TAG v0.10 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(tracy) + target_link_libraries(manifold INTERFACE TracyClient) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 582024491..eb95d43ba 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -94,14 +94,6 @@ if(MANIFOLD_CBIND AND NOT EMSCRIPTEN) target_link_libraries(manifold_test manifoldc) endif() -if(MANIFOLD_CROSS_SECTION) - target_compile_options(manifold_test PUBLIC -DMANIFOLD_CROSS_SECTION) -endif() - -if(MANIFOLD_EXPORT) - target_compile_options(manifold_test PUBLIC -DMANIFOLD_EXPORT) -endif() - target_compile_options(manifold_test PRIVATE ${MANIFOLD_FLAGS}) target_compile_features(manifold_test PUBLIC cxx_std_17) From 8c1b4ea2ef0ad72da97d246baba46a2840bb8097 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 4 Oct 2024 22:33:01 +0800 Subject: [PATCH 10/10] format --- src/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d9a23ecf1..a8eb91328 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -106,12 +106,14 @@ target_include_directories( PRIVATE ${MANIFOLD_INCLUDE_DIRS} ) -set(OPTIONS +set( + OPTIONS MANIFOLD_EXCEPTIONS MANIFOLD_DEBUG MANIFOLD_CROSS_SECTION MANIFOLD_EXPORT - MANIFOLD_PAR) + MANIFOLD_PAR +) foreach(OPT IN LISTS OPTIONS) if(${${OPT}}) target_compile_options(manifold PUBLIC -D${OPT})