Skip to content

Commit

Permalink
Merge pull request #24 from sympiler/alecjacobson/matlab
Browse files Browse the repository at this point in the history
update libigl. fix matlab build.
  • Loading branch information
cheshmi authored Jan 6, 2023
2 parents cc490b6 + df2f032 commit c052f6f
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 495 deletions.
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ option(NASOQ_BUILD_TESTS "Build NASOQ Tests" ${NASOQ_IS_TOPLEVEL})
option(NASOQ_BUILD_DOCS "Build NASOQ Documentation" ${NASOQ_IS_TOPLEVEL})
option(NASOQ_WITH_EIGEN "Build NASOQ Eigen interface" ON)
option(NASOQ_USE_CLAPACK "Use CLAPACK as the LAPACK implementaiton" OFF)
option(NASOQ_USE_OPENMP "Use OpenMP" ON)
option(NASOQ_WITH_MATLAB "Build NASOQ Matlab interface" OFF)

set(NASOQ_BLAS_BACKEND "MKL" CACHE STRING "BLAS implementation for NASOQ to use")
set_property(CACHE NASOQ_BLAS_BACKEND PROPERTY STRINGS MKL OpenBLAS)
Expand Down Expand Up @@ -65,6 +67,7 @@ if(NASOQ_WITH_EIGEN)
include(eigen)
endif()


if(NASOQ_USE_BLAS_MKL)
include(mkl)
elseif(NASOQ_USE_BLAS_OpenBLAS)
Expand Down Expand Up @@ -92,7 +95,9 @@ include(metis)

#-----------------------------------[ nasoq ]----------------------------------#

find_package(OpenMP)
if(NASOQ_USE_OPENMP)
find_package(OpenMP)
endif()


set(NASOQ_INTERNAL_INCLUDE_DIRS
Expand Down Expand Up @@ -188,6 +193,16 @@ endif()

add_library(nasoq::nasoq ALIAS nasoq)

if(NASOQ_WITH_MATLAB)
if(NASOQ_USE_BLAS_MKL)
message(WARNING "NASOQ_WITH_MATLAB=ON but NASOQ_USE_BLAS_MKL=ON. This is likely to fail")
endif()
if(NASOQ_USE_OPENMP)
message(WARNING "NASOQ_WITH_MATLAB=ON but NASOQ_USE_OPENMP=ON. This is likely to fail")
endif()
add_subdirectory(matlab)
endif()

#------------------------------------[ exes ]----------------------------------#

if(NASOQ_BUILD_CLI)
Expand Down
66 changes: 10 additions & 56 deletions matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,84 +38,38 @@ endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set(GPTOOLBOX_MEX_ROOT "${PROJECT_SOURCE_DIR}")
set(GPTOOLBOX_MEX_EXTERNAL "${GPTOOLBOX_MEX_ROOT}/external")
include(gptoolbox_download_project)

# libigl
option(LIBIGL_WITH_MATLAB "Use Matlab" ON)
option(MATLAB_PROXY "Download Matlab Proxy for compilation only" OFF)

# Find matlab
if(MATLAB_PROXY)
set(Matlab_ROOT_DIR "${GPTOOLBOX_MEX_ROOT}/external/matlab")
gptoolbox_download_matlab()
endif()

#find_package(Matlab REQUIRED COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY)

# Download and find libigl
gptoolbox_download_libigl()
find_package(LIBIGL REQUIRED)
option(LIBIGL_RESTRICTED_MATLAB "Use Matlab" ON)
include(libigl)

set( CMAKE_SHARED_LIBRARY_SUFFIX ".${Matlab_MEX_EXTENSION}" ) # set suffix to .mexa64
set( CMAKE_SHARED_LIBRARY_PREFIX ) # remove the "lib" prefix
set( CMAKE_SHARED_LIBRARY_CXX_FLAGS ) # remove the -fPIC option. mex does not accept the "-fPIC" option
set( CMAKE_POSITION_INDEPENDENT_CODE ON)
set( CMAKE_INSTALL_RPATH "\$ORIGIN" )

# TODO: remove MKL dependency using OpenBLAS submodule
find_package(MKL REQUIRED)

if(UNIX )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 ")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMKL ")

# Adding hints for suitesparse
set(SUITESPARSE_INCLUDE_DIR_HINTS ${SUITESPARSE_INCLUDE_DIR_HINTS} ${SUITE_ROOT_PATH}/include)
set(SUITESPARSE_LIBRARY_DIR_HINTS ${SUITESPARSE_LIBRARY_DIR_HINTS} ${SUITE_ROOT_PATH}/lib)
set(BLA_STATIC TRUE)
find_package(SuiteSparse OPTIONAL_COMPONENTS)

#TODO needs a fix
set( INCLUDE_INSTALL_DIR ${METIS_ROOT_PATH}/include)
set( LIB_INSTALL_DIR ${METIS_ROOT_PATH}/libmetis)
find_package(METIS REQUIRED)
set(METIS_LIBRARY "")
set(METIS_INCLUDE_DIR "")

set(NASOQ "${CMAKE_CURRENT_SOURCE_DIR}/../")
set(NASOQ_DIRS
"${NASOQ}/symbolic/"
"${NASOQ}/common/"
"${NASOQ}/ldl/"
"${NASOQ}/matrixMatrix/"
"${NASOQ}/matrixVector/"
"${NASOQ}/linear_solver/"
"${NASOQ}/gmres/"
"${NASOQ}/QP/"
"${NASOQ}/triangularSolve/")

function(compile_each I_MEX_SOURCES I_LIBS )
foreach(MEX_SOURCE ${I_MEX_SOURCES})
message(STATUS "MEX_SOURCE: ${MEX_SOURCE}")
get_filename_component(MEX_OUTPUT ${MEX_SOURCE} NAME_WE)
add_library(${MEX_OUTPUT} SHARED ${MEX_SOURCE})
set(MEX_TARGET "${MEX_OUTPUT}-target")
add_library(${MEX_TARGET} SHARED ${MEX_SOURCE})
set_target_properties( ${MEX_TARGET} PROPERTIES OUTPUT_NAME ${MEX_OUTPUT})
# Not sure if this should be (WIN32) or (MSVC OR MSYS OR MINGW)
# https://stackoverflow.com/a/40152725/148668
if(WIN32)
# https://stackoverflow.com/a/11095194/148668
set_target_properties(${MEX_OUTPUT} PROPERTIES LINK_FLAGS "/export:mexFunction")
endif()
target_link_libraries(${MEX_OUTPUT} ${I_LIBS} ${METIS_LIBRARIES}
${SUITESPARSE_LIBRARIES} ${MKL_LIBRARIES})
target_include_directories(${MEX_OUTPUT} PUBLIC ${Matlab_INCLUDE_DIRS}
${NASOQ_DIRS} ${METIS_INCLUDE_DIR} ${METIS_INCLUDES} ${MKL_INCLUDE_DIR}
${SUITESPARSE_INCLUDE_DIRS})
list(APPEND MEX_OUTPUTS ${MEX_OUTPUT})
if(APPLE)
include(OSXFixDylibReferences)
OSX_FIX_DYLIB_REFERENCES(${MEX_OUTPUT} ${MKL_LIBRARIES})
set_target_properties(${MEX_TARGET} PROPERTIES LINK_FLAGS "/export:mexFunction")
endif()
target_link_libraries(${MEX_TARGET} ${I_LIBS})
target_include_directories(${MEX_TARGET} PUBLIC ${Matlab_INCLUDE_DIRS})
list(APPEND MEX_TARGETS ${MEX_TARGET})
endforeach()
endfunction()

Expand All @@ -127,5 +81,5 @@ add_definitions("-DMEX")
compile_each("\
nasoq.cpp;\
"
"${CORE_LIBS};igl::core;igl::matlab")
"nasoq::nasoq;igl::core;igl_restricted::matlab")

18 changes: 0 additions & 18 deletions matlab/cmake/DownloadProject.CMakeLists.cmake.in

This file was deleted.

182 changes: 0 additions & 182 deletions matlab/cmake/DownloadProject.cmake

This file was deleted.

34 changes: 0 additions & 34 deletions matlab/cmake/FindLIBIGL.cmake

This file was deleted.

Loading

0 comments on commit c052f6f

Please sign in to comment.