diff --git a/.gitignore b/.gitignore index 8044c4cf0..236e1dd0f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,8 @@ external/embree/bin external/embree/doc/html/* external/embree/doc/latex/* external/gmp +external/cgal +external/cork external/mpfr external/boost external/.cache diff --git a/CMakeLists.txt b/CMakeLists.txt index 31a124144..6078b3523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,16 @@ cmake_minimum_required(VERSION 3.1) +project(libigl) + +# These ensure that lib*.a are placed in the directory where `cmake +# ../optional/` was issued. +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + +### conditionally compile certain modules depending on libraries found on the system +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) + +### Adding libIGL: choose the path to your local copy libIGL +include(libigl) + -include(${CMAKE_CURRENT_LIST_DIR}/optional/CMakeLists.txt) diff --git a/cmake/LibiglDownloadExternal.cmake b/cmake/LibiglDownloadExternal.cmake index e03d9fef3..1317c2aa4 100644 --- a/cmake/LibiglDownloadExternal.cmake +++ b/cmake/LibiglDownloadExternal.cmake @@ -12,6 +12,18 @@ function(igl_download_project name) ) endfunction() + +# Shortcut function +function(igl_download_data folder name) + download_project( + PROJ ${name} + SOURCE_DIR ${folder}/data + DOWNLOAD_DIR ${folder}/.cache/data + QUIET + ${ARGN} + ) +endfunction() + ################################################################################ ## CGAL @@ -107,3 +119,45 @@ function(igl_download_triangle) ) endfunction() + +## Google test +function(igl_download_googletest) + igl_download_project(googletest + GIT_REPOSITORY https://github.com/google/googletest + GIT_TAG v1.8.1 + ) +endfunction() + + + +################################################################################ + + +## Test data +function(igl_download_test_data) + set(IGL_TEST_DATA ${LIBIGL_EXTERNAL}/../tests/data) + + download_project( + PROJ test_data + SOURCE_DIR ${IGL_TEST_DATA} + DOWNLOAD_DIR ${LIBIGL_EXTERNAL}/.cache/test_data + QUIET + GIT_REPOSITORY https://github.com/libigl/libigl-tests-data + GIT_TAG bdb158c9695d5932bb6fc1cde078d8210bb13436 + ) +endfunction() + + +## Tutorial data +function(igl_download_tutorial_data) + set(IGL_TUTORIAL_DATA ${LIBIGL_EXTERNAL}/../tutorial/data) + download_project( + PROJ tutorial_data + SOURCE_DIR ${IGL_TUTORIAL_DATA} + DOWNLOAD_DIR ${LIBIGL_EXTERNAL}/.cache/tutorial_data + QUIET + GIT_REPOSITORY https://github.com/libigl/libigl-tutorial-data + GIT_TAG 5c6a1ea809c043d71e5595775709c15325a7158c + ) +endfunction() + diff --git a/optional/CMakeLists.txt b/optional/CMakeLists.txt deleted file mode 100644 index dee14414c..000000000 --- a/optional/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(libigl) - -set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../shared/cmake") -# These ensure that lib*.a are placed in the directory where `cmake -# ../optional/` was issued. -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) - -### conditionally compile certain modules depending on libraries found on the system -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../shared/cmake) -find_package(CGAL QUIET COMPONENTS Core) -find_package(MATLAB QUIET) -find_package(MOSEK) - -### libIGL options: choose between header only and compiled static library -option(LIBIGL_USE_STATIC_LIBRARY "Use LibIGL as static library" ON) - -### Adding libIGL: choose the path to your local copy libIGL -include(libigl) - diff --git a/optional/index.html b/optional/index.html deleted file mode 100644 index 51b7168e1..000000000 --- a/optional/index.html +++ /dev/null @@ -1,373 +0,0 @@ - - -
- --- -Warning: compiling libigl as a static library is considerably more difficult -than using it as a header-only library (see ../README.md instead). Do -it only if you are experienced with C++, cmake and make, and you want to -improve your compilation times.
-
Libigl is developed most often on Mac OS X, though has current users in Linux -and Windows.
- -Libigl may also be compiled to a static library. This is advantageous when -building a project with libigl, since when used as an header-only library can -slow down compile times.
- -To build the entire libigl library producing at least libigl/lib/libigl.a and
-possible other (automatically detected) extras, e.g. libigl/lib/libiglcgal.a
-from this current directory: issue:
mkdir -p ../lib
-cd ../lib
-cmake -DCMAKE_BUILD_TYPE=Release ../optional
-make
-
-
-You should expect to see a few linker warnings of the form:
- -/opt/local/bin/ranlib: file: libigl.a(*.cpp.o) has no symbols
-
-
-These are (admittedly unpopular) functions that have never been used by us -statically so we haven’t explicit instantiations (yet).
- -Finally there are a number of external libraries that we include in
-./external/ because they are either difficult to obtain or they have been
-patched for easier use with libigl. Please see the respective readmes in those
-directories or build the tutorial using cmake, which will recursively build all
-dependencies.
To build the embree library and executables on Mac OS X issue:
- -cd external/embree
-mkdir build
-cd build
-cmake ..
-# Or using a different compiler
-#cmake .. -DCMAKE_C_COMPILER=/opt/local/bin/gcc -DCMAKE_CXX_COMPILER=/opt/local/bin/g++
-make
-# Could also install embree to your root, but libigl examples don't expect
-# this
-#sudo make install
-
-
-This library extra contains functions for computing Bounded Biharmonic Weights, can
-be used with and without the mosek extra via the IGL_NO_MOSEK
-macro.
This library extra contains functions for computing mesh-mesh booleans, -depending on CGAL and optionally Cork.
- -This library extra utilizes CGAL’s efficient and exact intersection and -proximity queries.
- -This library extra utilizes embree’s efficient ray tracing queries.
- -This library extra provides support for reading and writing .mat workspace
-files, interfacing with Matlab at run time and compiling mex functions.
This library extra utilizes mosek’s efficient interior-point solver for -quadratic programs.
- -This library extra uses libpng and YImage to read and write .png files.
This library extra provides a simplified wrapper to the tetgen 3d tetrahedral -meshing library.
- -This library extra provides a simplified wrapper to the triangle 2d triangle -meshing library.
- -This library extra utilizes glfw and glew to open an opengl context and launch -a simple mesh viewer.
- -This library extra utilizes tinyxml2 to read and write serialized classes -containing Eigen matrices and other standard simple data-structures.
- -Further documentation for developers is listed in -style_guidelines.html.
- -See LICENSE.txt
Zip this directory without .git litter and binaries using:
- -git archive -prefix=libigl/ -o libigl.zip master
-
-
-Special care must be taken by the developers of each function and -class in the libigl library that uses C++ templates. If this function -is intended to be compiled into the statically linked libigl library -then function is only compiled for each explicitly instantiated -declaration. These should be added at the bottom of the corresponding -.cpp file surrounded by a
- -#ifdef IGL_STATIC_LIBRARY
-
-
-Of course, a developer may not know ahead of time which -instantiations should be explicitly included in the igl static lib. -One way to find out is to add one explicit instantiation for each -call in one’s own project. This only ever needs to be done once for -each template.
- -The process is somewhat mechanical using a linker with reasonable error -output.
- -Supposed for example we have compiled the igl static lib, including the
-cat.h and cat.cpp functions, without any explicit instantiation. Say
-using the makefile in the libigl directory:
cd $LIBIGL
-make
-
-
-Now if we try to compile a project and link against it we may get -an error like:
- -Undefined symbols for architecture x86_64:
-"Eigen::Matrix<int, -1, -1, 0, -1, -1> igl::cat<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(int, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&)", referenced from:
-uniform_sample(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, int, double, Eigen::Matrix<double, -1, -1, 0, -1, -1>&)in Skinning.o
-"Eigen::SparseMatrix<double, 0, int> igl::cat<Eigen::SparseMatrix<double, 0, int> >(int, Eigen::SparseMatrix<double, 0, int> const&, Eigen::SparseMatrix<double, 0, int> const&)", referenced from:
-covariance_scatter_matrix(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, ArapEnergy, Eigen::SparseMatrix<double, 0, int>&)in arap_dof.o
-arap_rhs(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, ArapEnergy, Eigen::SparseMatrix<double, 0, int>&)in arap_dof.o
-
-
-This looks like a mess, but luckily we don’t really need to read it -all. Just copy the first part in quotes
- -Eigen::Matrix<int, -1, -1, 0, -1, -1> igl::cat<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(int, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&)
-
-
-, then append it
-to the list of explicit template instantiations at the end of
-cat.cpp after the word
-template and followed by a semi-colon.
-Like this:
#ifdef IGL_STATIC_LIBRARY
-// Explicit template instantiation
-template Eigen::Matrix<int, -1, -1, 0, -1, -1> igl::cat<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(int, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&);
-#endif
-
-
-Then you must recompile the IGL static library.
- -cd $LIBIGL
-make
-
-
-And try to compile your project again, potentially repeating this -process until no more symbols are undefined.
- -It may be useful to check that you code compiles with
-no errors first using the headers-only version to be sure that all errors are from missing template
-instantiations.
If you’re using make then the following command will -reveal each missing symbol on its own line:
- -make 2>&1 | grep "referenced from" | sed -e "s/, referenced from.*//"
-
-
-Alternatively you can use the autoexplicit.sh function
-which (for well organized .h/.cpp pairs in libigl) automatically
-create explicit instantiations from your compiler’s error messages.
-Repeat this process until convergence:
cd /to/your/project
-make 2>$LIBIGL/make.err
-cd $LIBIGL
-cat make.err | ./autoexplicit.sh
-make clean
-make
-
-
-Calling the script:
- -scripts/compress.sh igl.h igl.cpp
-
-
-will create a single header igl.h and a single cpp file igl.cpp.
Alternatively, you can also compress everything into a single header file:
- -scripts/compress.sh igl.h
-
-
-Hard to debug/edit: The compressed files are -automatically generated. They’re huge and should not be edited. Thus -debugging and editing are near impossible.
Compounded dependencies:
-An immediate disadvantage of this
-seems to be that even to use a single function (e.g.
-cotmatrix), compiling and linking against
-igl.cpp will require linking to all of libigl’s
-dependencies (OpenGL, GLUT,
-AntTweakBar, BLAS). However, because all
-dependencies other than Eigen should be encapsulated between
-#ifndef guards (e.g. #ifndef IGL_NO_OPENGL, it
-is possible to ignore certain functions that have such dependencies.
Long compile:
-Compiling igl.cpp takes a long time and isn’t easily parallelized (no make
--j12 equivalent).
Here’s a tiny test example using igl.h and igl.cpp. Save the following in test.cpp:
#include <igl.h>
-#include <Eigen/Core>
-
-int main(int argc, char * argv[])
-{
-Eigen::MatrixXd V;
-Eigen::MatrixXi F;
-return (argc>=2 && igl::read_triangle_mesh(argv[1],V,F)?0:1);
-}
-
-
-Then compile igl.cpp with:
g++ -o igl.o -c igl.cpp -I/opt/local/include/eigen3 -DIGL_NO_OPENGL -DIGL_NO_ANTTWEAKBAR
-
-
-Notice that we’re using -DIGL_NO_OPENGL -DIGL_NO_ANTTWEAKBAR to disable any libigl dependencies on OpenGL and AntTweakBar.
Now compile test.cpp with:
g++ -g -I/opt/local/include/eigen3/ -I/usr/local/igl/libigl/ -L/usr/local/igl/libigl/ -ligl -DIGL_NO_OPENGL -DIGL_NO_ANTTWEAKBAR -o test
-
-
-Try running it with:
- -./test path/to/mesh.obj
-
-
-The following bash one-liner will find all source files that contain the string OpenGL but don’t contain and IGL_NO_OPENGL guard:
grep OpenGL `grep -L IGL_NO_OPENGL include/igl/*`
-
-
-IGL_NO_OPENGL)
-
-IGL_OPENGL_4)IGL_NO_ANTTWEAKBAR) Last tested 1.16 (see
-libigl/external/AntTweakBar)