Skip to content

Commit

Permalink
Merge pull request Yixin-Hu#24 from jdumas/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
Yixin-Hu authored Sep 6, 2018
2 parents 252185e + d93b1ea commit 9323d69
Show file tree
Hide file tree
Showing 48 changed files with 1,915 additions and 1,636 deletions.
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.tex text
*.bib text
*.svg text
*.py text
*.vbs text
*.cpp text
*.hpp text
Makefile text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Extern
/extern/.cache
/extern/spdlog

# Build
src/ispc/energy.h
*build*/*
.idea/*
Expand Down
72 changes: 43 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ project(TetWild)
# Options
################################################################################
# tetwild
option(TETWILD_QUIET "Mute log and unnecassary checks" OFF)
option(TETWILD_WITH_ISPC "Use ISPC" OFF)
# libigl library
option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
Expand Down Expand Up @@ -44,6 +43,9 @@ endif()
set(TETWILD_EXTERNAL "${CMAKE_CURRENT_SOURCE_DIR}/extern")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# Color output
include(UseColors)

# Use folder in Visual Studio
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Expand All @@ -56,6 +58,16 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
################################################################################
# 3rd party libraries
################################################################################

# download external dependencies
include(TetWildDownloadExternal)

# spdlog
if(NOT TARGET spdlog::spdlog)
tetwild_download_spdlog()
add_subdirectory(${TETWILD_EXTERNAL}/spdlog)
endif()

# cgal
find_package(CGAL REQUIRED)

Expand All @@ -71,44 +83,45 @@ add_subdirectory(${TETWILD_EXTERNAL}/pymesh)
# CL11
add_subdirectory(${TETWILD_EXTERNAL}/CLI)

# cout
if(TETWILD_QUIET)
add_definitions(-DMUTE_COUT)
endif()

################################################################################
# TetWild
################################################################################
# Build static library for executable
add_library(libTetWild STATIC
src/tetwild/Preprocess.h
src/tetwild/Preprocess.cpp
src/tetwild/DelaunayTetrahedralization.h
src/tetwild/DelaunayTetrahedralization.cpp
src/tetwild/MeshConformer.h
src/tetwild/MeshConformer.cpp
src/tetwild/BSPSubdivision.h
src/tetwild/BSPSubdivision.cpp
src/tetwild/SimpleTetrahedralization.h
src/tetwild/SimpleTetrahedralization.cpp
src/tetwild/MeshRefinement.h
src/tetwild/MeshRefinement.cpp
src/tetwild/LocalOperations.h
src/tetwild/LocalOperations.cpp
src/tetwild/EdgeSplitter.h
src/tetwild/EdgeSplitter.cpp
src/tetwild/EdgeCollapser.h
src/tetwild/BSPSubdivision.h
src/tetwild/CGALCommon.cpp
src/tetwild/CGALCommon.h
src/tetwild/Common.cpp
src/tetwild/Common.h
src/tetwild/DelaunayTetrahedralization.cpp
src/tetwild/DelaunayTetrahedralization.h
src/tetwild/EdgeCollapser.cpp
src/tetwild/EdgeRemover.h
src/tetwild/EdgeCollapser.h
src/tetwild/EdgeRemover.cpp
src/tetwild/VertexSmoother.h
src/tetwild/VertexSmoother.cpp
src/tetwild/InoutFiltering.h
src/tetwild/EdgeRemover.h
src/tetwild/EdgeSplitter.cpp
src/tetwild/EdgeSplitter.h
src/tetwild/InoutFiltering.cpp
src/tetwild/heads.h
src/tetwild/heads.cpp
src/tetwild/tetwild.cpp
src/tetwild/InoutFiltering.h
src/tetwild/LocalOperations.cpp
src/tetwild/LocalOperations.h
src/tetwild/Logger.cpp
src/tetwild/Logger.h
src/tetwild/MeshConformer.cpp
src/tetwild/MeshConformer.h
src/tetwild/MeshRefinement.cpp
src/tetwild/MeshRefinement.h
src/tetwild/Preprocess.cpp
src/tetwild/Preprocess.h
src/tetwild/SimpleTetrahedralization.cpp
src/tetwild/SimpleTetrahedralization.h
src/tetwild/State.cpp
src/tetwild/State.h
src/tetwild/TetmeshElements.h
src/tetwild/tetwild.cpp
src/tetwild/VertexSmoother.cpp
src/tetwild/VertexSmoother.h
include/tetwild/tetwild.h
)
target_include_directories(libTetWild
Expand All @@ -123,6 +136,7 @@ target_link_libraries(libTetWild
igl::core
igl::cgal
pymesh::pymesh
spdlog::spdlog
)
set_target_properties(libTetWild PROPERTIES OUTPUT_NAME "tetwild")

Expand Down
17 changes: 17 additions & 0 deletions cmake/DownloadProject.CMakeLists.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Distributed under the OSI-approved MIT License. See accompanying
# file LICENSE or https://github.com/Crascit/DownloadProject for details.

cmake_minimum_required(VERSION 2.8.2)

project(${DL_ARGS_PROJ}-download NONE)

include(ExternalProject)
ExternalProject_Add(${DL_ARGS_PROJ}-download
${DL_ARGS_UNPARSED_ARGUMENTS}
SOURCE_DIR "${DL_ARGS_SOURCE_DIR}"
BINARY_DIR "${DL_ARGS_BINARY_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
182 changes: 182 additions & 0 deletions cmake/DownloadProject.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Distributed under the OSI-approved MIT License. See accompanying
# file LICENSE or https://github.com/Crascit/DownloadProject for details.
#
# MODULE: DownloadProject
#
# PROVIDES:
# download_project( PROJ projectName
# [PREFIX prefixDir]
# [DOWNLOAD_DIR downloadDir]
# [SOURCE_DIR srcDir]
# [BINARY_DIR binDir]
# [QUIET]
# ...
# )
#
# Provides the ability to download and unpack a tarball, zip file, git repository,
# etc. at configure time (i.e. when the cmake command is run). How the downloaded
# and unpacked contents are used is up to the caller, but the motivating case is
# to download source code which can then be included directly in the build with
# add_subdirectory() after the call to download_project(). Source and build
# directories are set up with this in mind.
#
# The PROJ argument is required. The projectName value will be used to construct
# the following variables upon exit (obviously replace projectName with its actual
# value):
#
# projectName_SOURCE_DIR
# projectName_BINARY_DIR
#
# The SOURCE_DIR and BINARY_DIR arguments are optional and would not typically
# need to be provided. They can be specified if you want the downloaded source
# and build directories to be located in a specific place. The contents of
# projectName_SOURCE_DIR and projectName_BINARY_DIR will be populated with the
# locations used whether you provide SOURCE_DIR/BINARY_DIR or not.
#
# The DOWNLOAD_DIR argument does not normally need to be set. It controls the
# location of the temporary CMake build used to perform the download.
#
# The PREFIX argument can be provided to change the base location of the default
# values of DOWNLOAD_DIR, SOURCE_DIR and BINARY_DIR. If all of those three arguments
# are provided, then PREFIX will have no effect. The default value for PREFIX is
# CMAKE_BINARY_DIR.
#
# The QUIET option can be given if you do not want to show the output associated
# with downloading the specified project.
#
# In addition to the above, any other options are passed through unmodified to
# ExternalProject_Add() to perform the actual download, patch and update steps.
# The following ExternalProject_Add() options are explicitly prohibited (they
# are reserved for use by the download_project() command):
#
# CONFIGURE_COMMAND
# BUILD_COMMAND
# INSTALL_COMMAND
# TEST_COMMAND
#
# Only those ExternalProject_Add() arguments which relate to downloading, patching
# and updating of the project sources are intended to be used. Also note that at
# least one set of download-related arguments are required.
#
# If using CMake 3.2 or later, the UPDATE_DISCONNECTED option can be used to
# prevent a check at the remote end for changes every time CMake is run
# after the first successful download. See the documentation of the ExternalProject
# module for more information. It is likely you will want to use this option if it
# is available to you. Note, however, that the ExternalProject implementation contains
# bugs which result in incorrect handling of the UPDATE_DISCONNECTED option when
# using the URL download method or when specifying a SOURCE_DIR with no download
# method. Fixes for these have been created, the last of which is scheduled for
# inclusion in CMake 3.8.0. Details can be found here:
#
# https://gitlab.kitware.com/cmake/cmake/commit/bdca68388bd57f8302d3c1d83d691034b7ffa70c
# https://gitlab.kitware.com/cmake/cmake/issues/16428
#
# If you experience build errors related to the update step, consider avoiding
# the use of UPDATE_DISCONNECTED.
#
# EXAMPLE USAGE:
#
# include(DownloadProject)
# download_project(PROJ googletest
# GIT_REPOSITORY https://github.com/google/googletest.git
# GIT_TAG master
# UPDATE_DISCONNECTED 1
# QUIET
# )
#
# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
#
#========================================================================================


set(_DownloadProjectDir "${CMAKE_CURRENT_LIST_DIR}")

include(CMakeParseArguments)

function(download_project)

set(options QUIET)
set(oneValueArgs
PROJ
PREFIX
DOWNLOAD_DIR
SOURCE_DIR
BINARY_DIR
# Prevent the following from being passed through
CONFIGURE_COMMAND
BUILD_COMMAND
INSTALL_COMMAND
TEST_COMMAND
)
set(multiValueArgs "")

cmake_parse_arguments(DL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# Hide output if requested
if (DL_ARGS_QUIET)
set(OUTPUT_QUIET "OUTPUT_QUIET")
else()
unset(OUTPUT_QUIET)
message(STATUS "Downloading/updating ${DL_ARGS_PROJ}")
endif()

# Set up where we will put our temporary CMakeLists.txt file and also
# the base point below which the default source and binary dirs will be.
# The prefix must always be an absolute path.
if (NOT DL_ARGS_PREFIX)
set(DL_ARGS_PREFIX "${CMAKE_BINARY_DIR}")
else()
get_filename_component(DL_ARGS_PREFIX "${DL_ARGS_PREFIX}" ABSOLUTE
BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if (NOT DL_ARGS_DOWNLOAD_DIR)
set(DL_ARGS_DOWNLOAD_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-download")
endif()

# Ensure the caller can know where to find the source and build directories
if (NOT DL_ARGS_SOURCE_DIR)
set(DL_ARGS_SOURCE_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-src")
endif()
if (NOT DL_ARGS_BINARY_DIR)
set(DL_ARGS_BINARY_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-build")
endif()
set(${DL_ARGS_PROJ}_SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" PARENT_SCOPE)
set(${DL_ARGS_PROJ}_BINARY_DIR "${DL_ARGS_BINARY_DIR}" PARENT_SCOPE)

# The way that CLion manages multiple configurations, it causes a copy of
# the CMakeCache.txt to be copied across due to it not expecting there to
# be a project within a project. This causes the hard-coded paths in the
# cache to be copied and builds to fail. To mitigate this, we simply
# remove the cache if it exists before we configure the new project. It
# is safe to do so because it will be re-generated. Since this is only
# executed at the configure step, it should not cause additional builds or
# downloads.
file(REMOVE "${DL_ARGS_DOWNLOAD_DIR}/CMakeCache.txt")

# Create and build a separate CMake project to carry out the download.
# If we've already previously done these steps, they will not cause
# anything to be updated, so extra rebuilds of the project won't occur.
# Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
# has this set to something not findable on the PATH.
configure_file("${_DownloadProjectDir}/DownloadProject.CMakeLists.cmake.in"
"${DL_ARGS_DOWNLOAD_DIR}/CMakeLists.txt")
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
-D "CMAKE_MAKE_PROGRAM:FILE=${CMAKE_MAKE_PROGRAM}"
.
RESULT_VARIABLE result
${OUTPUT_QUIET}
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
)
if(result)
message(FATAL_ERROR "CMake step for ${DL_ARGS_PROJ} failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
${OUTPUT_QUIET}
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
)
if(result)
message(FATAL_ERROR "Build step for ${DL_ARGS_PROJ} failed: ${result}")
endif()

endfunction()
22 changes: 22 additions & 0 deletions cmake/TetWildDownloadExternal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
################################################################################
include(DownloadProject)

# Shortcut function
function(tetwild_download_project name)
download_project(
PROJ ${name}
SOURCE_DIR ${TETWILD_EXTERNAL}/${name}
DOWNLOAD_DIR ${TETWILD_EXTERNAL}/.cache/${name}
${ARGN}
)
endfunction()

################################################################################

## spdlog
function(tetwild_download_spdlog)
tetwild_download_project(spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.1.0
)
endfunction()
Loading

0 comments on commit 9323d69

Please sign in to comment.