### Installing and Running Python Linting Tools Source: https://github.com/tx-code/meshlib/blob/imos-dev/test_python/readme.md This section outlines the steps to install and use linting tools like `pre-commit`, `black`, and `isort` for Python code. These tools help maintain code formatting consistency and can be run manually or automatically during commits. ```shell pip3 install pre-commit black isort ``` ```shell black ./test_python isort ./test_python/ --profile black ``` -------------------------------- ### Install MeshLib for Python Source: https://github.com/tx-code/meshlib/blob/imos-dev/readme.md Instructions for installing the MeshLib Python package using pip, the standard package installer for Python. ```bash pip install meshlib ``` -------------------------------- ### Running MeshLib Python Tests on Linux/macOS Source: https://github.com/tx-code/meshlib/blob/imos-dev/test_python/readme.md This section provides instructions for setting up the environment and executing MeshLib's Python tests on Linux or macOS. It requires `pytest` and `numpy` to be installed and assumes MeshLib has been built. ```shell python3 -m pip install pytest numpy cd build/Debug/bin # or build/Release/bin python3 ./../../../scripts/run_python_test_script.py -d '../test_python' ``` -------------------------------- ### Configure MeshLib Examples with CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/examples/c-examples/CMakeLists.txt This snippet configures a CMake project to build a set of examples utilizing the MeshLib library. It defines the minimum CMake version, sets the project name, finds the MeshLib package, and then iterates through a list of example targets to create executables, specify include paths, and link against MeshLib's core and third-party libraries. It also handles a specific dependency for the 'Triangulation' example. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(cmake-c-examples C) find_package(MeshLib CONFIG REQUIRED) set(EXAMPLES FreeFormDeformation GlobalRegistration LaplacianDeformation MeshBoolean MeshDecimate MeshExport MeshExtrude MeshFillHole MeshICP MeshLoadSave MeshModification MeshOffset MeshFixDegeneracies MeshStitchHole NoiseDenoise Triangulation ) foreach(TARGET ${EXAMPLES}) add_executable(${TARGET} ${TARGET}.dox.c) target_include_directories(${TARGET} PUBLIC ${MESHLIB_INCLUDE_DIR} ${MESHLIB_THIRDPARTY_INCLUDE_DIR}) target_link_libraries(${TARGET} PRIVATE MeshLib::MRMeshC) target_link_directories(${TARGET} PRIVATE ${MESHLIB_THIRDPARTY_LIB_DIR}) endforeach() # Triangulation requires the math library target_link_libraries(Triangulation PRIVATE m) ``` -------------------------------- ### Configure MeshLib C++ Examples with CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/examples/cpp-examples/CMakeLists.txt This CMakeLists.txt file sets up the build system for various C++ examples utilizing the MeshLib library. It defines the C++ standard, finds necessary packages like MeshLib and TBB, iterates through a list of examples to create executables, and links them against required libraries. Specific examples like MeshFromText, MeshOffset, Triangulation, and MeshLoadSave have additional library dependencies. It also configures a main function target with logging and Emscripten-specific options. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(cpp-examples CXX) find_package(MeshLib CONFIG REQUIRED) find_package(TBB REQUIRED) set(EXAMPLES FreeFormDeformation GlobalRegistration LaplacianDeformation MeshBoolean MeshDecimate MeshExport MeshExtrude MeshFillHole MeshFromText MeshICP MeshLoadSave MeshModification MeshOffset MeshFixDegeneracies MeshStitchHole NoiseDenoise Triangulation PointsToMesh ContourTriangulation TerrainTriangulation ) foreach(TARGET ${EXAMPLES}) add_executable(${TARGET} ${TARGET}.dox.cpp) target_include_directories(${TARGET} PUBLIC ${MESHLIB_INCLUDE_DIR} ${MESHLIB_THIRDPARTY_INCLUDE_DIR}) target_link_libraries(${TARGET} PRIVATE MeshLib::MRMesh TBB::tbb) target_link_directories(${TARGET} PUBLIC ${MESHLIB_THIRDPARTY_LIB_DIR}) endforeach() # MeshFromText additionally depends on MRSymbolMesh target_link_libraries(MeshFromText PRIVATE MeshLib::MRSymbolMesh) # MeshOffset and Triangulation additionally depend on MRVoxels target_link_libraries(MeshOffset PRIVATE MeshLib::MRVoxels) target_link_libraries(Triangulation PRIVATE MeshLib::MRVoxels) # MeshLoadSave additionally depends on MRIOExtras target_link_libraries(MeshLoadSave PRIVATE MeshLib::MRIOExtras) find_package(fmt REQUIRED) find_package(spdlog REQUIRED) add_executable(MRBasedMainFunc MRBasedMainFunc.dox.cpp) target_compile_definitions(MRBasedMainFunc PRIVATE SPDLOG_FMT_EXTERNAL) target_include_directories(MRBasedMainFunc PUBLIC ${MESHLIB_INCLUDE_DIR} ${MESHLIB_THIRDPARTY_INCLUDE_DIR}) target_link_libraries(MRBasedMainFunc PRIVATE MeshLib::MRMesh MeshLib::MRViewer fmt::fmt spdlog::spdlog) target_link_directories(MRBasedMainFunc PUBLIC ${MESHLIB_THIRDPARTY_LIB_DIR}) if(EMSCRIPTEN) target_link_options(MRBasedMainFunc PRIVATE -sUSE_WEBGL2=1) target_link_options(MRBasedMainFunc PRIVATE -sUSE_GLFW=3) target_link_options(MRBasedMainFunc PRIVATE -sUSE_LIBPNG=1) target_compile_definitions(MRBasedMainFunc PRIVATE SPDLOG_WCHAR_FILENAMES) endif() ``` -------------------------------- ### Install ImGui Library, Headers, and CMake Configuration Files Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/imgui/CMakeLists.txt Defines the installation rules for the compiled ImGui library, ensuring it's placed in the specified library directories. It also installs all public headers (core, backend, freetype) into their respective include paths and exports CMake configuration files (`imguiConfig.cmake`, `imguiTargets.cmake`) to allow other projects to easily find and link against the installed ImGui library. ```CMake install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" INCLUDES DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) install( FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) install( FILES ${BACKEND_HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}/backends" ) install( FILES ${FREETYPE_HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}/misc/freetype" ) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) install( EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Define Global Installation Prefix Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRSymbolMesh/CMakeLists.txt This command sets the default installation prefix for all subsequent `install` commands to `/Library/Frameworks`. ```CMake set(CMAKE_INSTALL_PREFIX "/Library/Frameworks") ``` -------------------------------- ### Install Project Target and Libraries Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRIOExtras/CMakeLists.txt This snippet sets the default installation prefix for the project to `/Library/Frameworks` and configures the installation of the project's main target. It specifies distinct destinations for libraries, archives, and runtime components, ensuring proper deployment. ```CMake set(CMAKE_INSTALL_PREFIX "/Library/Frameworks") install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}" ) ``` -------------------------------- ### Installing CMake Project Targets Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRViewer/CMakeLists.txt This CMake command installs the main project target, specified by `${PROJECT_NAME}`, to designated directories. It separates library, archive, and runtime components into their respective installation paths, and also prepares the target for export. ```CMake install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}" ) ``` -------------------------------- ### Run Scripts for Prerequisite Installation and MRBind Build Source: https://github.com/tx-code/meshlib/blob/imos-dev/scripts/mrbind/README-generating.md Execute these platform-specific scripts to automate the installation of dependencies and the building of the MRBind tool. These can be re-run for updates. ```sh scripts/mrbind/install_deps_ scripts/mrbind/install_mrbind_ ``` -------------------------------- ### Installing Various Project Resources with CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRViewer/CMakeLists.txt This section details the installation of various project resources, including different font sets, JSON files, and an entire resource directory. These assets are placed into their respective designated installation directories, ensuring they are available post-installation. ```CMake install(FILES ${MAIN_FONTS} DESTINATION "${MR_FONTS_DIR}") install(FILES ${AWESOME_FONTS} DESTINATION "${MR_FONTS_DIR}") install(FILES ${IMGUI_FONTS} DESTINATION "${MR_FONTS_DIR}") install(FILES ${JSONS} DESTINATION "${MR_RESOURCES_DIR}") install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resource DESTINATION "${MR_RESOURCES_DIR}") ``` -------------------------------- ### Manual MRBind Setup and Build on MacOS Source: https://github.com/tx-code/meshlib/blob/imos-dev/scripts/mrbind/README-generating.md Shell commands to configure the PATH for Homebrew-installed tools (GNU Make, Clang) and CMake commands for building MRBind on MacOS. Essential for manual setup. ```sh export PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH" export PATH="/opt/homebrew/opt/llvm/bin@VERSION:$PATH" # See the correct VERSION in `clang_version.txt`. ``` ```CMake CC=clang-VERSION CXX=clang++-VERSION cmake .... # Optional CMake flag for Apple Clang (if not setting PATH): -DCMAKE_PREFIX_PATH=/opt/homebrew/opt/llvm ``` -------------------------------- ### Define Installation Rules for Libraries, Headers, and Assets Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/EditableProject/CMakeLists.txt Specifies the installation paths for the compiled shared library, header files, CMake configuration files, and project assets (UI and items JSON). This ensures that all necessary components are placed in the correct directories during the `make install` process, making the project consumable by other CMake projects. ```CMake install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}") install(FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}") install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR}) install(FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}") install(FILES ${UI_JSON} DESTINATION "${MR_RESOURCES_DIR}") install(FILES ${ITEMS_JSON} DESTINATION "${MR_RESOURCES_DIR}") install(EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake NAMESPACE MeshLib:: DESTINATION ${MR_CONFIG_DIR}) ``` -------------------------------- ### Install Library, Headers, and Configuration Files Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRCommonPlugins/CMakeLists.txt Defines installation rules for the shared library, its public headers, and CMake configuration files. It ensures the library, headers, and resource files are placed in their respective directories during installation, and exports targets for use by other CMake projects. ```CMake install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}" ) install( FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) install(FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}") install(FILES ${UI_JSON} DESTINATION "${MR_RESOURCES_DIR}") install(FILES ${ITEMS_JSON} DESTINATION "${MR_RESOURCES_DIR}") install( EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake NAMESPACE MeshLib:: DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Define Installation Rules for MRMesh Library and Headers Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRMesh/CMakeLists.txt This section specifies the installation rules for the MRMesh library. It installs all header files and the generated `config_cmake.h` to a designated include directory. It also installs the shared library itself to the main library directory and exports its targets for use by other CMake projects. ```CMake install( FILES ${HEADERS} "config_cmake.h" DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" ) install( EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake NAMESPACE MeshLib:: DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Install MRSymbolMesh Library and Runtime Components Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRSymbolMesh/CMakeLists.txt This snippet defines the installation rules for the `MRSymbolMesh` library, specifying destinations for shared libraries, archives, and runtime components based on predefined CMake variables. ```CMake install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}" ) ``` -------------------------------- ### Install CMake Configuration and Targets Files Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRIOExtras/CMakeLists.txt This section installs the project's CMake configuration file (`${PROJECT_NAME}Config.cmake`) and exports its targets into `${PROJECT_NAME}Targets.cmake`. These files are crucial for other CMake-based projects to find and correctly link against MeshLib. ```CMake install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) install( EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake NAMESPACE MeshLib:: DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Install Project Header Files Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRIOExtras/CMakeLists.txt This command installs the project's header files, represented by the `${HEADERS}` variable, to a specific include directory. This makes the project's public API headers available for other projects that depend on MeshLib. ```CMake install( FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) ``` -------------------------------- ### Running MeshLib Python Tests on Windows Source: https://github.com/tx-code/meshlib/blob/imos-dev/test_python/readme.md This section details the steps to set up the environment and run MeshLib's Python tests specifically on Windows. It uses `py -3` for Python execution and adjusts paths accordingly for the Windows file system. ```shell py -3 -m pip install pytest numpy cd source/x64/Debug # or source/x64/Release py -3 ..\..\..\scripts\run_python_test_script.py -d '..\test_python' ``` -------------------------------- ### Define Installation Rules for MRCuda Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRCuda/CMakeLists.txt This snippet defines the installation rules for the MRCuda library. It sets a default install prefix, specifies destinations for the shared library, archive, and runtime components. It also installs header files, the project's CMake configuration file, and exports targets for use by other CMake projects. ```CMake set(CMAKE_INSTALL_PREFIX "/Library/Frameworks") install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}" ) install( FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) install( EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake NAMESPACE MeshLib:: DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Start and Attach to an Existing Docker Container Source: https://github.com/tx-code/meshlib/blob/imos-dev/docker/readme.md Command to start an existing Docker container named `angry_fedora` and attach to its STDOUT/STDERR (`-a`) and STDIN (`-i`), allowing interaction with the running process. ```Shell $ docker container start -ai angry_fedora ``` -------------------------------- ### Installing Project Headers with CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRViewer/CMakeLists.txt This snippet installs all header files defined in the `${HEADERS}` variable to a project-specific subdirectory within the main include directory. This makes the headers available for other projects that link against this library. ```CMake install( FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) ``` -------------------------------- ### Configure MeshLib Installation Directories by Platform Source: https://github.com/tx-code/meshlib/blob/imos-dev/CMakeLists.txt This comprehensive CMake snippet defines the installation directory structure for MeshLib based on the build environment. It handles three main scenarios: VCPKG usage, generic non-Apple systems (using GNUInstallDirs), and macOS-specific paths, including special handling for framework installations. ```CMake IF(MESHLIB_USE_VCPKG) # use OS-agnostic directory structure for vcpkg set(MR_BIN_DIR bin) set(MR_INCLUDE_DIR include/MeshLib) set(MR_MAIN_LIB_DIR lib/${MESHLIB_PROJECT_NAME}) set(MR_PY_LIB_DIR lib/${MESHLIB_PROJECT_NAME}/meshlib) set(MR_CONFIG_DIR lib/cmake/MeshLib) set(MR_RESOURCES_DIR share/${MESHLIB_PROJECT_NAME}) set(MR_FONTS_DIR share/${MESHLIB_PROJECT_NAME}/fonts) # set rpath manually for both executables and shared libraries # related issue: https://gitlab.kitware.com/cmake/cmake/-/issues/23727 list(APPEND CMAKE_INSTALL_RPATH "$ORIGIN" "$ORIGIN/.." "$ORIGIN/../lib" "$ORIGIN/../lib/${MESHLIB_PROJECT_NAME}") ``` ```CMake ELSEIF(NOT APPLE) include(GNUInstallDirs) set(MR_BIN_DIR "${CMAKE_INSTALL_BINDIR}") set(MR_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/MeshLib") set(MR_MAIN_LIB_DIR "${CMAKE_INSTALL_LIBDIR}/${MESHLIB_PROJECT_NAME}") set(MR_PY_LIB_DIR "${CMAKE_INSTALL_LIBDIR}/${MESHLIB_PROJECT_NAME}/meshlib") set(MR_CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/MeshLib") set(MR_RESOURCES_DIR "${CMAKE_INSTALL_DATADIR}/${MESHLIB_PROJECT_NAME}") set(MR_FONTS_DIR "${CMAKE_INSTALL_DATADIR}/${MESHLIB_PROJECT_NAME}/fonts") ``` ```CMake ELSE() # TODO: correct directory structure for macOS # TODO: https://cmake.org/cmake/help/latest/prop_tgt/RESOURCE.html IF(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(MR_ROOT "./Library/Frameworks/MeshLib.framework/Versions/${MESHLIB_VERSION}") set(MR_BIN_DIR "${MR_ROOT}/bin") set(MR_INCLUDE_DIR "${MR_ROOT}/include") set(MR_MAIN_LIB_DIR "${MR_ROOT}/lib") set(MR_PY_LIB_DIR "${MR_ROOT}/lib/meshlib") set(MR_RESOURCES_DIR "${MR_ROOT}/Resources") set(MR_FONTS_DIR "${MR_ROOT}/Resources/fonts") set(MR_CONFIG_DIR "${MR_ROOT}/Resources/cmake") ELSE() set(MESHLIB_MACOS_INSTALL_PATH "./usr/local" CACHE PATH "") set(MR_ROOT ${MESHLIB_MACOS_INSTALL_PATH}) set(MR_BIN_DIR "${MR_ROOT}/bin") set(MR_INCLUDE_DIR "${MR_ROOT}/include/MeshLib") set(MR_MAIN_LIB_DIR "${MR_ROOT}/lib/MeshLib") set(MR_PY_LIB_DIR "${MR_ROOT}/lib/MeshLib/meshlib") set(MR_RESOURCES_DIR "${MR_ROOT}/etc/MeshLib") set(MR_FONTS_DIR "${MR_ROOT}/share/fonts") set(MR_CONFIG_DIR "${MR_ROOT}/lib/MeshLib") ENDIF() ENDIF() ``` -------------------------------- ### Initialize CMake Project and Suppress Compiler Warnings Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/imgui/CMakeLists.txt Sets the minimum required CMake version, defines the project name 'imgui' with CXX language support, and modifies compiler flags to suppress common warnings for both MSVC and GCC/Clang compilers, ensuring a cleaner build output. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) project(imgui LANGUAGES CXX) # Don't emit warnings. IF(MSVC) string(REPLACE "/W4" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ELSE() string(REPLACE "-Wall" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "-Wextra" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "-Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "-pedantic-errors" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ENDIF() ``` -------------------------------- ### Define Installation Rules for Library and Configuration Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MREmbeddedPython/CMakeLists.txt Sets the default installation prefix and defines rules for installing the shared library, its configuration file (`${PROJECT_NAME}Config.cmake`), and export targets (`${PROJECT_NAME}Targets.cmake`). This allows the library to be easily integrated into other projects after installation. ```CMake set(CMAKE_INSTALL_PREFIX "/Library/Frameworks") install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}" ) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) install( EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake NAMESPACE MeshLib:: DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Configure Precompiled Headers and Installation Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRPython/CMakeLists.txt Enables precompiled headers for the project if the `MR_PCH` variable is set, reusing headers from `MRPch`. It then defines installation rules, setting the default install prefix and specifying destinations for the compiled library, archives, runtime components, and CMake configuration files (`Config.cmake`, `Targets.cmake`). ```CMake IF(MR_PCH) target_precompile_headers(${PROJECT_NAME} REUSE_FROM MRPch) ENDIF() set(CMAKE_INSTALL_PREFIX "/Library/Frameworks") install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}" ) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) install( EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake NAMESPACE MeshLib:: DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Collect ImGui Source and Header Files for Build Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/imgui/CMakeLists.txt Defines the root directory for ImGui and uses `file(GLOB)` to recursively collect all necessary C++ source files (`.cpp`) and header files (`.h`) from the ImGui core, backend implementations (GLFW, OpenGL3), and miscellaneous utilities (cpp, freetype). These files are then prepared for inclusion in the library compilation. ```CMake set(IMGUI_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../thirdparty/imgui") file(GLOB SOURCES "*.cpp" "${IMGUI_ROOT}/*.cpp" "${IMGUI_ROOT}/backends/imgui_impl_glfw.cpp" "${IMGUI_ROOT}/backends/imgui_impl_opengl3.cpp" "${IMGUI_ROOT}/misc/cpp/*.cpp" "${IMGUI_ROOT}/misc/freetype/*.cpp" ) file(GLOB HEADERS "*.h" "${IMGUI_ROOT}/*.h" ) file(GLOB BACKEND_HEADERS "${IMGUI_ROOT}/backends/imgui_impl_glfw.h" "${IMGUI_ROOT}/backends/imgui_impl_opengl3.h" "${IMGUI_ROOT}/backends/imgui_impl_opengl3_loader.h" ) file(GLOB FREETYPE_HEADERS "${IMGUI_ROOT}/misc/freetype/*.h" ) ``` -------------------------------- ### Configure Basic CMake Project Settings Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRTest/CMakeLists.txt This snippet initializes the CMake project, sets the minimum required CMake version, defines the C++ standard, gathers source files, and adds the main executable. It's the foundational setup for any CMake-based C++ project. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD ${MR_CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(MRTest CXX) file(GLOB SOURCES "*.cpp") add_executable(${PROJECT_NAME} ${SOURCES}) ``` -------------------------------- ### Install MRSymbolMesh CMake Configuration File Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRSymbolMesh/CMakeLists.txt This snippet installs the project's CMake configuration file (`MRSymbolMeshConfig.cmake`) into the designated CMake configuration directory, allowing other projects to find and use `MRSymbolMesh`. ```CMake install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Installing CMake Project Configuration File Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRViewer/CMakeLists.txt This command installs the project's CMake configuration file (`${PROJECT_NAME}Config.cmake`) to a designated configuration directory. This file is crucial for other CMake projects to find and use this project's targets and properties. ```CMake install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Add ImGui Library and Configure Compile Definitions Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/imgui/CMakeLists.txt Creates a shared library named 'imgui' using the previously collected source and header files. It then configures public include directories and defines several preprocessor macros, such as `IMGUI_DISABLE_OBSOLETE_FUNCTIONS`, `IMGUI_ENABLE_FREETYPE`, and `IMGUI_USER_CONFIG`, to customize ImGui's behavior during compilation. ```CMake add_library(imgui SHARED ${SOURCES} ${HEADERS} ${BACKEND_HEADERS} ${FREETYPE_HEADERS}) target_include_directories(${PROJECT_NAME} PUBLIC $ ) target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS) target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_ENABLE_FREETYPE) target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_USER_CONFIG=\"imgui/MRCustomImGuiConfig.h\") ``` -------------------------------- ### Initialize Dependency and Include/Library Directory Variables Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRIOExtras/CMakeLists.txt This section initializes empty CMake lists for `MRIOEXTRAS_DEPENDENCIES`, `MRIOEXTRAS_INCLUDE_DIRS`, and `MRIOEXTRAS_LIBRARY_DIRS`. These variables will be conditionally populated later in the CMake script based on which optional features are enabled, ensuring a clean starting state. ```CMake set(MRIOEXTRAS_DEPENDENCIES "") set(MRIOEXTRAS_INCLUDE_DIRS "") set(MRIOEXTRAS_LIBRARY_DIRS "") ``` -------------------------------- ### Specify MRBind Installation Path Source: https://github.com/tx-code/meshlib/blob/imos-dev/scripts/mrbind/README-generating.md How to inform the binding generation process about a non-default MRBind source directory ('MRBIND_SOURCE') or the specific path to the MRBind executable ('MRBIND_EXE'). This is necessary if MRBind is not installed in the default 'MeshLib/mrbind' location. ```Makefile MRBIND_SOURCE=/path/to/mrbind make -f scripts/mrbind/generate.mk ``` ```Makefile MRBIND_EXE=/path/to/mrbind/build/mrbind make -f scripts/mrbind/generate.mk ``` -------------------------------- ### Examples of Common Flags for MeshLib Binding Generation Source: https://github.com/tx-code/meshlib/blob/imos-dev/scripts/mrbind/README-generating.md Demonstrates how to use common flags to control verbosity, optimization, rebuild behavior, parallelism, and Python version selection during MeshLib binding generation. These flags are typically appended to the 'make' command. ```Makefile make -f scripts/mrbind/generate.mk --trace ``` ```Makefile make -f scripts/mrbind/generate.mk MODE=none ``` ```Makefile make -f scripts/mrbind/generate.mk -B ``` ```Makefile make -f scripts/mrbind/generate.mk NUM_FRAGMENTS=64 -j8 ``` ```Makefile make -f scripts/mrbind/generate.mk PYTHON_PKGCONF_NAME=python3-embed ``` -------------------------------- ### Manual MRBind Build Configuration on Ubuntu Source: https://github.com/tx-code/meshlib/blob/imos-dev/scripts/mrbind/README-generating.md Commands for configuring CMake to build MRBind on Ubuntu, specifying the Clang version and compiler paths. This is for manual setup when not using the provided scripts. ```CMake # Optional CMake flag to specify Clang directory: -DClang_DIR=/usr/lib/cmake/clang-VERSION # Use specific Clang for building with CMake: CC=clang-VERSION CXX=clang++-VERSION cmake .... ``` -------------------------------- ### Install Public Header Files Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRSymbolMesh/CMakeLists.txt This command installs all discovered header files into a project-specific subdirectory within the global include directory, making them available for other projects. ```CMake install( FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) ``` -------------------------------- ### Basic CMake Project Setup for MRMesh Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRMesh/CMakeLists.txt This snippet initializes the CMake project, sets the minimum required CMake version, and configures C++ standard requirements. It defines the project name as 'MRMesh' and specifies C++ as the primary language. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD ${MR_CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(MRMesh CXX) ``` -------------------------------- ### Configure CPack for Installer Generation Source: https://github.com/tx-code/meshlib/blob/imos-dev/CMakeLists.txt This snippet configures CPack for generating installers, specifically setting the generator to 'DRAGNDROP'. This is activated only when the current CMakeLists.txt is the top-level source directory, ensuring CPack is run for the main project build. ```CMake IF(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(CPACK_GENERATOR "DRAGNDROP") include(CPack) ENDIF() ``` -------------------------------- ### Configure MeshViewer Project with CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRViewerApp/CMakeLists.txt This CMake configuration sets up the MeshViewer project. It defines the C++ standard, creates an executable, handles resource copying (PNGs and WebAssembly files for Emscripten), and conditionally links libraries based on whether the target is Emscripten or a native platform (Apple/other). It also includes installation rules and precompiled header configuration. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD ${MR_CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(MeshViewer CXX) # We make this a `MACOSX_BUNDLE` even though we don't package it, solely to unify # the `MR_LOCAL_RESOURCES=1` search path between this and our other apps that actually need to be bundles. add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE MRViewerApp.cpp) file(GLOB PNGS "*.png") file(COPY ${PNGS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) IF(MR_EMSCRIPTEN) file(GLOB LOCAL_WASM_FILES "../../wasm/*.*") file(COPY ${LOCAL_WASM_FILES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) target_link_libraries(${PROJECT_NAME} PRIVATE zip gtest -Wl,--whole-archive MRCommonPlugins MRMesh MRIOExtras MRViewer -Wl,--no-whole-archive ) ELSE() # NOT MR_EMSCRIPTEN IF(APPLE) target_compile_definitions(${PROJECT_NAME} PRIVATE _GNU_SOURCE) #for Boost.Stacktrace ENDIF() target_link_libraries(${PROJECT_NAME} PRIVATE MRViewer MRMesh ) ENDIF() # MR_EMSCRIPTEN install(TARGETS ${PROJECT_NAME} DESTINATION "${MR_BIN_DIR}") install(FILES ${LIB_LIST} DESTINATION "${MR_RESOURCES_DIR}") install(FILES ${PNGS} DESTINATION "${MR_RESOURCES_DIR}") IF(MR_PCH) TARGET_PRECOMPILE_HEADERS(${PROJECT_NAME} REUSE_FROM MRPch) ENDIF() ``` -------------------------------- ### Configure and Build MRVoxels Project with CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRVoxels/CMakeLists.txt This snippet provides the complete CMake configuration for the 'MRVoxels' project. It sets the minimum CMake version, C++ standard, and project name. It includes options to disable DICOM and TIFF support, gathers source and header files, and defines a shared library. The configuration dynamically links dependencies based on the target platform (Emscripten, Apple, Windows/VCPKG, or generic Linux) and sets up installation rules for the compiled library, headers, and CMake package configuration files. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD ${MR_CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(MRVoxels CXX) option(MRVOXELS_NO_DICOM "Disable DICOM format support" OFF) option(MRVOXELS_NO_TIFF "Disable TIFF format support" OFF) IF(MR_EMSCRIPTEN) set(MRVOXELS_NO_TIFF ON) ENDIF() file(GLOB SOURCES "*.cpp") file(GLOB HEADERS "*.h") add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config_cmake.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config_cmake.h) set(MRVOXELS_OPTIONAL_DEPENDENCIES "") IF(NOT MRVOXELS_NO_DICOM) find_package(GDCM CONFIG REQUIRED) list(APPEND MRVOXELS_OPTIONAL_DEPENDENCIES gdcmIOD gdcmDICT gdcmDSED gdcmMEXD gdcmMSFF) ENDIF() IF(NOT MRVOXELS_NO_TIFF) IF(WIN32 OR MESHLIB_USE_VCPKG) find_package(TIFF REQUIRED) list(APPEND MRVOXELS_OPTIONAL_DEPENDENCIES TIFF::TIFF) ELSE() list(APPEND MRVOXELS_OPTIONAL_DEPENDENCIES tiff) ENDIF() ENDIF() IF(MR_EMSCRIPTEN) target_link_libraries(${PROJECT_NAME} PRIVATE MRMesh openvdb jsoncpp spdlog tbb ${MRVOXELS_OPTIONAL_DEPENDENCIES} ) ELSEIF(APPLE) target_link_libraries(${PROJECT_NAME} PRIVATE MRMesh OpenVDB PkgConfig::jsoncpp fmt spdlog tbb ${MRVOXELS_OPTIONAL_DEPENDENCIES} ) ELSEIF(WIN32 OR MESHLIB_USE_VCPKG) find_package(OpenVDB REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE MRMesh OpenVDB::openvdb fmt::fmt spdlog::spdlog JsonCpp::JsonCpp TBB::tbb ${MRVOXELS_OPTIONAL_DEPENDENCIES} ) ELSE() target_link_libraries(${PROJECT_NAME} PRIVATE MRMesh openvdb fmt::fmt spdlog::spdlog JsonCpp::JsonCpp tbb ${MRVOXELS_OPTIONAL_DEPENDENCIES} ) ENDIF() IF(MR_PCH) target_precompile_headers(${PROJECT_NAME} REUSE_FROM MRPch) ENDIF() set(CMAKE_INSTALL_PREFIX "/Library/Frameworks") install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION "${MR_MAIN_LIB_DIR}" ARCHIVE DESTINATION "${MR_MAIN_LIB_DIR}" RUNTIME DESTINATION "${MR_BIN_DIR}" ) install( FILES ${HEADERS} DESTINATION "${MR_INCLUDE_DIR}/${PROJECT_NAME}" ) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) install( EXPORT ${PROJECT_NAME} FILE ${PROJECT_NAME}Targets.cmake NAMESPACE MeshLib:: DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Configure CMake Package Configuration for MRMesh Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRMesh/CMakeLists.txt This snippet sets up the CMake package configuration files for MRMesh, allowing other projects to easily find and use the installed library. It uses `CMakePackageConfigHelpers` to generate a `MRMeshConfig.cmake` file from a template and installs it to the specified configuration directory. ```CMake include(CMakePackageConfigHelpers) configure_package_config_file( ${PROJECT_NAME}Config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake INSTALL_DESTINATION ${MR_CONFIG_DIR} ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Integrate glad Library in CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/thirdparty/CMakeLists.txt This snippet attempts to find the `glad` library. If `glad` is not found, it enables its installation and reproducible build options, then adds `glad` as a subdirectory. ```CMake find_package(glad) IF(NOT glad_FOUND) set(GLAD_INSTALL ON CACHE BOOL "") set(GLAD_REPRODUCIBLE ON CACHE BOOL "") add_subdirectory(./glad) ENDIF() ``` -------------------------------- ### Conditionally Link Dependencies for Emscripten or Desktop Builds Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/imgui/CMakeLists.txt Manages platform-specific linking for ImGui. If `MR_EMSCRIPTEN` is true, it adds a compile definition for OpenGL ES3 and enables FreeType for Emscripten. Otherwise, it finds and links against `freetype` and `glfw3` packages, ensuring the correct dependencies are met for desktop builds, including handling `PkgConfig` for older CMake versions. ```CMake IF(MR_EMSCRIPTEN) add_compile_definitions(IMGUI_IMPL_OPENGL_ES3) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_FREETYPE=1") ELSE() find_package(freetype) IF(NOT freetype_FOUND) find_package(PkgConfig REQUIRED) pkg_check_modules(Freetype REQUIRED IMPORTED_TARGET freetype2) IF(CMAKE_VERSION VERSION_LESS 3.18) set_target_properties(PkgConfig::Freetype PROPERTIES IMPORTED_GLOBAL TRUE) ENDIF() add_library(Freetype::Freetype ALIAS PkgConfig::Freetype) ENDIF() find_package(glfw3 CONFIG REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE glfw Freetype::Freetype ${CMAKE_DL_LIBS} ) ENDIF() ``` -------------------------------- ### CMake Build Configuration for meshconv Executable Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/meshconv/CMakeLists.txt This CMake script defines the build rules for the `meshconv` C++ application. It ensures C++17 compliance (via `MR_CXX_STANDARD`), locates the Boost `program_options` component, and creates an executable from `meshconv.cpp`. Library linking is handled conditionally: `MRMesh`, `MRIOExtras`, `fmt`, `spdlog`, `Boost::program_options`, and `TBB` are linked, with specific names for Windows/VCPKG vs. other platforms. The compiled executable is then installed to `MR_BIN_DIR`. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD ${MR_CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(meshconv CXX) find_package(Boost COMPONENTS program_options REQUIRED) add_executable(${PROJECT_NAME} meshconv.cpp) IF(WIN32 OR MESHLIB_USE_VCPKG) target_link_libraries(${PROJECT_NAME} PRIVATE MRMesh MRIOExtras fmt::fmt spdlog::spdlog Boost::program_options TBB::tbb ) ELSE() target_link_libraries(${PROJECT_NAME} PRIVATE MRMesh MRIOExtras fmt spdlog Boost::program_options tbb ) ENDIF() install(TARGETS ${PROJECT_NAME} DESTINATION "${MR_BIN_DIR}") IF(MR_PCH) TARGET_PRECOMPILE_HEADERS(${PROJECT_NAME} REUSE_FROM MRPch) ENDIF() ``` -------------------------------- ### Configure MRViewer and Related Components Source: https://github.com/tx-code/meshlib/blob/imos-dev/CMakeLists.txt This section manages the build of the MRViewer application and its dependencies. It includes conditional logic for Emscripten (web assembly) builds, GLFW for desktop, ImGui, common plugins, and the main viewer application, ensuring correct setup for different platforms. ```CMake IF(MESHLIB_BUILD_MRVIEWER) IF(NOT MR_EMSCRIPTEN) find_package(glfw3 CONFIG REQUIRED) ENDIF() IF(MR_EMSCRIPTEN) include(EmscriptenHelpers) mr_emscripten_pack_directory("${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets" "/") IF(NOT MR_DISABLE_EMSCRIPTEN_ASYNCIFY) mr_emscripten_set_async_func_list("${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/wasm_async_func_list.txt") ENDIF() ENDIF() add_subdirectory(${PROJECT_SOURCE_DIR}/imgui ./imgui) add_subdirectory(${PROJECT_SOURCE_DIR}/MRViewer ./MRViewer) IF(NOT BUILD_IMOS) add_subdirectory(${PROJECT_SOURCE_DIR}/MRCommonPlugins ./MRCommonPlugins) ENDIF() IF(MESHLIB_BUILD_MESHVIEWER AND NOT BUILD_IMOS) add_subdirectory(${PROJECT_SOURCE_DIR}/MRViewerApp ./MRViewerApp) ENDIF() ENDIF() ``` -------------------------------- ### Configure and Add libzip for Emscripten Builds in CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/thirdparty/CMakeLists.txt For Emscripten builds, this snippet configures libzip by disabling tools, regress, and examples, adds the `-s USE_ZLIB=1` flag to C compiler flags, sets `LIBZIP_DO_INSTALL` to ON, and includes libzip as a subdirectory. ```CMake IF(MR_EMSCRIPTEN) set(BUILD_TOOLS OFF CACHE BOOL "") set(BUILD_REGRESS OFF CACHE BOOL "") set(BUILD_EXAMPLES OFF CACHE BOOL "") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_ZLIB=1") set(LIBZIP_DO_INSTALL ON) add_subdirectory(./libzip) ENDIF() ``` -------------------------------- ### Configure C++ Project with MeshLib and TBB using CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/examples/cpp-samples/CMakeLists.txt This CMake script sets up a C++ project, defines the C++ standard, locates required external libraries (MeshLib and TBB), and then iterates through a list of sample applications to create and configure their respective executables, including linking necessary libraries and setting include paths. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(cpp-samples CXX) find_package(MeshLib CONFIG REQUIRED) find_package(TBB REQUIRED) set(SAMPLES GlobalRegistration LaplacianDeformation ) foreach(TARGET ${SAMPLES}) add_executable(${TARGET} ${TARGET}.cpp) target_include_directories(${TARGET} PUBLIC ${MESHLIB_INCLUDE_DIR} ${MESHLIB_THIRDPARTY_INCLUDE_DIR}) target_link_libraries(${TARGET} PRIVATE MeshLib::MRMesh TBB::tbb) target_link_directories(${TARGET} PUBLIC ${MESHLIB_THIRDPARTY_LIB_DIR}) endforeach() ``` -------------------------------- ### Generate and Install CMake Package Configuration Source: https://github.com/tx-code/meshlib/blob/imos-dev/CMakeLists.txt This snippet handles the generation and installation of CMake package configuration files for MRMesh. It uses `CMakePackageConfigHelpers` to create `meshlib-config.cmake` and `meshlib-config-version.cmake`, enabling other projects to easily find and use the installed MRMesh library. ```CMake include(CMakePackageConfigHelpers) configure_package_config_file(meshlib-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/meshlib-config.cmake INSTALL_DESTINATION ${MR_CONFIG_DIR} PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR MR_INCLUDE_DIR MR_MAIN_LIB_DIR ) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/meshlib-config-version.cmake VERSION ${MESHLIB_VERSION} COMPATIBILITY ExactVersion ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/meshlib-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/meshlib-config-version.cmake DESTINATION ${MR_CONFIG_DIR} ) ``` -------------------------------- ### Initialize CMake Project and Set Standards Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRViewer/CMakeLists.txt Sets the minimum required CMake version, defines the C++ standard, and declares the project name 'MRViewer' as a C++ project. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD ${MR_CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(MRViewer CXX) ``` -------------------------------- ### Copying Runtime Resources with CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRViewer/CMakeLists.txt This snippet demonstrates how to copy various font and resource files to the build's runtime output directory using CMake's `file(COPY)` command. This ensures that necessary assets are available alongside the executable, especially for runtime dependencies. ```CMake file(COPY ${AWESOME_FONTS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) file(COPY ${IMGUI_FONTS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) file(COPY "resource" DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) ``` -------------------------------- ### Initialize CMake Project and Set Output Directories Source: https://github.com/tx-code/meshlib/blob/imos-dev/CMakeLists.txt This snippet initializes the CMake project, sets the minimum required version, includes essential modules like DefaultOptions and ConfigureVcpkg, and defines the output directories for archives, libraries, and executables to be located in 'build/bin'. It also sets the project name and adds a compile definition. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules") include(DefaultOptions) include(ConfigureVcpkg) project(MeshLib CXX) set(MESHLIB_PROJECT_NAME "MeshLib" CACHE STRING "Project name") add_compile_definitions(MR_PROJECT_NAME=\"${MESHLIB_PROJECT_NAME}\") include(CompilerOptions) # all binaries will be located in ./build/Release/bin set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) ``` -------------------------------- ### Integrate and Install mbedTLS for Emscripten Builds in CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/thirdparty/CMakeLists.txt This section configures and integrates mbedTLS for Emscripten, disabling programs and testing, adding it as a subdirectory, and installing its include directory. It also appends the current source directory to `CMAKE_MODULE_PATH` for custom module finding. ```CMake IF(MR_EMSCRIPTEN) set(ENABLE_PROGRAMS OFF CACHE BOOL "") set(ENABLE_TESTING OFF CACHE BOOL "") add_subdirectory(./mbedtls) install(DIRECTORY mbedtls/include/mbedtls DESTINATION ${MESHLIB_THIRDPARTY_INCLUDE_DIR}) # Use custom FindMbedTLS.cmake to override the one included in ziplib, that does not work list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) ENDIF() ``` -------------------------------- ### Initialize CMake Project and Discover Sources Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRCommonPlugins/CMakeLists.txt Sets the minimum CMake version, C++ standard, and defines the project. It then recursively discovers all .cpp source files and .h header files within the project directory. ```CMake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(CMAKE_CXX_STANDARD ${MR_CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(MRCommonPlugins CXX) file(GLOB_RECURSE SOURCES "*.cpp") file(GLOB_RECURSE HEADERS "*.h") ``` -------------------------------- ### Integrate Parallel Hashmap (PHMAP) in CMake Source: https://github.com/tx-code/meshlib/blob/imos-dev/thirdparty/CMakeLists.txt This snippet enables the installation option for the Parallel Hashmap library and then adds it as a subdirectory to the build system. ```CMake option(PHMAP_INSTALL "" ON) add_subdirectory(./parallel-hashmap) ``` -------------------------------- ### Link Libraries for Generic Linux/Unix Build Source: https://github.com/tx-code/meshlib/blob/imos-dev/source/MRViewer/CMakeLists.txt Finds GDCM and links core MeshLib components and common third-party libraries like GTest, cpr, ImGui, glad, glfw, hidapi, JsonCpp, spdlog, fmt, tbb, and clip for non-Windows, non-Apple, non-Emscripten platforms. ```CMake ELSE() # None of: MR_EMSCRIPTEN, APPLE, WIN32, vcpkg find_package(GDCM CONFIG REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE MRMesh MRIOExtras MRSymbolMesh gtest cpr imgui glad glfw hidapi-hidraw JsonCpp::JsonCpp spdlog fmt tbb clip ${CMAKE_DL_LIBS} ${MRVIEWER_OPTIONAL_DEPENDENCIES} ) ENDIF() # APPLE ``` -------------------------------- ### Delete All Docker Containers Source: https://github.com/tx-code/meshlib/blob/imos-dev/docker/readme.md Command to force-remove (`-f`) all Docker containers. It uses command substitution (`$(docker ps -a -q)`) to get the IDs of all containers. ```Shell $ docker rm -f $(docker ps -a -q) ```