Skip to content

Commit

Permalink
Add basic build files for mmesh
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Apr 22, 2024
1 parent c342f95 commit 2ccad66
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
94 changes: 94 additions & 0 deletions CMake/FindMMESH.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindMMESH
--------
Find the native MMESH includes and library.
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` target ``MMESH::MMESH``, if
MMESH has been found.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
::
MMESH_INCLUDE_DIRS - where to find meshdecimation.h, etc.
MMESH_LIBRARIES - List of libraries when using mmesh.
MMESH_FOUND - True if mmesh found.
Hints
^^^^^
A user may set ``MMESH_ROOT`` to a mmesh installation root to tell this
module where to look.
#]=======================================================================]

set(_MMESH_SEARCHES)

# Search MMESH_ROOT first if it is set.
if(MMESH_ROOT)
set(_MMESH_SEARCH_ROOT PATHS ${MMESH_ROOT} NO_DEFAULT_PATH)
list(APPEND _MMESH_SEARCHES _MMESH_SEARCH_ROOT)
endif()

set(MMESH_NAMES mmesh)

# Try each search configuration.
foreach(search ${_MMESH_SEARCHES})
find_path(MMESH_INCLUDE_DIR NAMES meshdecimation.h ${${search}} PATH_SUFFIXES include include/mmesh mmesh)
endforeach()

# Allow MMESH_LIBRARY to be set manually, as the location of the openNURBS library
if(NOT MMESH_LIBRARY)
foreach(search ${_MMESH_SEARCHES})
find_library(MMESH_LIBRARY NAMES ${MMESH_NAMES} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
endforeach()
endif()

unset(MMESH_NAMES)

mark_as_advanced(MMESH_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MMESH REQUIRED_VARS MMESH_LIBRARY MMESH_INCLUDE_DIR)

if(MMESH_FOUND)
set(MMESH_INCLUDE_DIRS ${MMESH_INCLUDE_DIR})

if(NOT MMESH_LIBRARIES)
set(MMESH_LIBRARIES ${MMESH_LIBRARY})
endif()

if(NOT TARGET MMESH::MMESH)
add_library(MMESH::MMESH UNKNOWN IMPORTED)
set_target_properties(MMESH::MMESH PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MMESH_INCLUDE_DIRS}")

if(MMESH_LIBRARY_RELEASE)
set_property(TARGET MMESH::MMESH APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(MMESH::MMESH PROPERTIES
IMPORTED_LOCATION_RELEASE "${MMESH_LIBRARY_RELEASE}")
endif()

if(MMESH_LIBRARY_DEBUG)
set_property(TARGET MMESH::MMESH APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(MMESH::MMESH PROPERTIES
IMPORTED_LOCATION_DEBUG "${MMESH_LIBRARY_DEBUG}")
endif()

if(NOT MMESH_LIBRARY_RELEASE AND NOT MMESH_LIBRARY_DEBUG)
set_property(TARGET MMESH::MMESH APPEND PROPERTY
IMPORTED_LOCATION "${MMESH_LIBRARY}")
endif()
endif()
endif()
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@ add_project(pugixml GROUPS "BRLCAD;APPLESEED")
# https://github.com/assimp/assimp
add_project(assetimport GROUPS "BRLCAD")

# mmesh - mesh optimization and decimation library
# https://github.com/BRL-CAD/mmesh
add_project(mmesh GROUPS "BRLCAD")

# OpenCV - Open Source Computer Vision Library
# http://opencv.org
add_project(opencv GROUPS "BRLCAD_EXTRA")
Expand Down
50 changes: 50 additions & 0 deletions mmesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cad_enable(MMESH "librt")

bext_enable(MMESH)

# Decision made

if (ENABLE_MMESH)

git_submodule_init(mmesh src/mmcore.c)

TargetDeps(MMESH)

ExternalProject_Add(MMESH_BLD
URL "${CMAKE_CURRENT_SOURCE_DIR}/mmesh"
BUILD_ALWAYS ${EXT_BUILD_ALWAYS} ${LOG_OPTS}
#PATCH_COMMAND ${PATCH_EXECUTABLE};-E;-p1;${PATCH_OPTIONS};-i;${CMAKE_CURRENT_SOURCE_DIR}/mmesh.patch
CMAKE_ARGS
${BUILD_TYPE_SPECIFIER}
-DBIN_DIR=${BIN_DIR}
-DLIB_DIR=${LIB_DIR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_INSTALL_PREFIX=${CMAKE_BUNDLE_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR:PATH=${LIB_DIR}
-DCMAKE_INSTALL_RPATH=${CMAKE_BUNDLE_INSTALL_PREFIX}/${LIB_DIR}
LOG_CONFIGURE ${EXT_BUILD_QUIET}
LOG_BUILD ${EXT_BUILD_QUIET}
LOG_INSTALL ${EXT_BUILD_QUIET}
LOG_OUTPUT_ON_FAILURE ${EXT_BUILD_QUIET}
STEP_TARGETS install
)

TargetInstallDeps(MMESH MMESH_DEPENDS)

# Copy the license into position in CMAKE_BUNDLE_INSTALL_PREFIX
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/mmesh/LICENSE
${DOC_LICENSE_DIR}/mmesh.txt
COPYONLY
)

endif (ENABLE_MMESH)

# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

2 changes: 2 additions & 0 deletions mmesh/mmesh.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PATCH

0 comments on commit 2ccad66

Please sign in to comment.