### Installing Project Targets Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/dependent-project/CMakeLists.txt Specifies installation rules for executables and libraries. This ensures your project can be packaged and deployed correctly. ```cmake install(TARGETS main my_lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) ``` -------------------------------- ### Install Pkg-config File Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Generates and installs the `2geom.pc` file, which is used by pkg-config to provide information about the installed library to other build systems. ```cmake configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/2geom.pc.in ${CMAKE_CURRENT_BINARY_DIR}/2geom.pc @ONLY IMMEDIATE ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/2geom.pc" destination ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT "lib2geom_dev") ``` -------------------------------- ### Basic CMake Project Setup Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/dependent-project/CMakeLists.txt Sets the minimum CMake version, project name, and C++ standard. This is a foundational setup for any CMake project. ```cmake cmake_minimum_required(VERSION 3.12) project(test_dep_2geom CXX) set(CMAKE_CXX_STANDARD 20) ``` -------------------------------- ### Build and Install lib2geom on win32 Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/README.win32.md Use these commands in the command prompt after setting up the environment. Ensure the CMake generator is set to 'MinGW Makefiles' and configure installation paths carefully. ```bash mingwenv.bat cmake -G "MinGW Makefiles" c:\path\to\2geom # be sure you have a CAPITAL '-G' there! cmake -i # especially mind to set the install dir to where you want it installed (probably the gtk folder, e.g. c:/gtk210)) mingw32-make ``` -------------------------------- ### Install 2geom Target Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/2geom/CMakeLists.txt Defines installation rules for the 2geom target, specifying runtime, library, and archive destinations and components. ```cmake install(TARGETS 2geom EXPORT 2geom_targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT "lib2geom${2GEOM_VERSION}" LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT "lib2geom${2GEOM_VERSION}" NAMELINK_COMPONENT "lib2geom_dev" ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT "lib2geom${2GEOM_VERSION}" ) ``` -------------------------------- ### Install Header Files Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Installs the public header files for lib2geom into the appropriate system include directory, versioned for compatibility. ```cmake install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/2geom" destination "${CMAKE_INSTALL_INCLUDEDIR}/2geom-${2GEOM_VERSION}" COMPONENT "lib2geom_dev") ``` -------------------------------- ### Example GNU Make Version Output Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/README.win32.md This is the expected output when checking the GNU Make version on a win32 system. ```text E:\inkscapelpe> mingw32-make --version GNU Make 3.80 Copyright (C) 2002 Free Software Foundation, Inc. ``` -------------------------------- ### Install py2geom Module Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/py2geom/CMakeLists.txt Installs the compiled py2geom shared library and its __init__.py file to the Python site-packages directory, making it available for import in Python. ```cmake INSTALL(TARGETS py2geom DESTINATION "${Python3_SITEARCH}/py2geom") INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" DESTINATION "${Python3_SITEARCH}/py2geom") ENDIF(2GEOM_BOOST_PYTHON) ``` -------------------------------- ### Installing Cython Modules to Site-Packages Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Installs the compiled Cython extension modules into the determined Python site-packages directory, making the 'cy2geom' package available to Python. ```cmake INSTALL(TARGETS _common_decl _cy_primitives _cy_rectangle _cy_affine _cy_curves _cy_path _cy_conicsection cy2geom DESTINATION "${SITEPACKAGE}/cy2geom") ``` -------------------------------- ### Configure 2geom Target Include Directories Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/2geom/CMakeLists.txt Sets include directories for the 2geom target, distinguishing between build and install interfaces. ```cmake target_include_directories(2geom SYSTEM PUBLIC $ $ ) ``` -------------------------------- ### Compile lib2geom using CMake Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/HACKING.md Use these commands to compile the lib2geom library. Ensure you have the necessary development packages installed. ```bash cmake . Make ``` -------------------------------- ### Find Points of Maximum Curvature Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt This example demonstrates a technique for finding points of maximum and minimum curvature (corners) on paths by computing the curvature, taking its derivative, and finding where it equals zero. ```C++ compute the curvature, took the derivative and found where that = 0 ``` -------------------------------- ### Install Exported Targets Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Installs CMake target files for 'lib2geom', enabling other projects to find and use it via `find_package(lib2geom)`. This includes configuration files and version information. ```cmake install(EXPORT 2geom_targets FILE 2GeomTargets.cmake NAMESPACE 2Geom:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/2Geom" COMPONENT "lib2geom_dev" ) include(CMakePackageConfigHelpers) write_basic_package_version_file("2GeomConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) install(FILES "2GeomConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/2GeomConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/2Geom" COMPONENT "lib2geom_dev" ) ``` -------------------------------- ### Setting Python Site-Packages Directory (Windows) Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Determines the Python site-packages directory on Windows by inspecting the Python library path. This is used for installation. ```cmake IF (WIN32) GET_FILENAME_COMPONENT(PYTHON_LIB_INSTALL "${PYTHON_LIBRARY}" PATH) GET_FILENAME_COMPONENT(SITEPACKAGE "${PYTHON_LIB_INSTALL}/../Lib/site-packages" ABSOLUTE) ELSE (WIN32) ``` -------------------------------- ### Generate Uninstall Target Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Configures a custom target 'uninstall' that uses a generated CMake script to remove installed files. This is useful for clean uninstallation. ```cmake # make unistall target configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall_${PROJECT_NAME} "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") ``` -------------------------------- ### Conditional 2Geom Inclusion Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/dependent-project/CMakeLists.txt Configures whether to include 2Geom as a subproject or use an installed version. Use as a subproject for development or when 2Geom is not installed system-wide. ```cmake option(2GEOM_AS_SUBPROJECT "include 2geom as subproject" OFF) if(2GEOM_AS_SUBPROJECT) message("Using 2geom as subdirectory") set(2GEOM_BUILD_SHARED ON CACHE BOOL "Build 2geom shared version") add_subdirectory("../../" 2geom) else() message("Using installed 2geom") find_package(2Geom REQUIRED) endif() ``` -------------------------------- ### Including Cython Module Processing Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Includes the necessary CMake module for processing Cython files. This is typically part of the Cython setup. ```cmake include( UseCython ) ``` -------------------------------- ### Define Sine and Cosine SBasis Functions Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt Define SBasis functions for sine and cosine. These are fundamental for creating trigonometric shapes like arcs and circles. They take start and end angles and a precision parameter k. ```cpp SBasis sin(double a0, double a1, int k); SBasis cos(double a0, double a1, int k) ``` -------------------------------- ### Build and Test Lib2geom Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/RELEASING.md Standard commands to build, test, and package the library after version updates. ```bash cmake . make make test make dist ``` -------------------------------- ### Generate Doxygen Documentation Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/README.md Command to generate API documentation using Doxygen. Run this command from the project root directory. ```bash doxygen ``` -------------------------------- ### Run 2Geom Tests and Performance Tests Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/README.md Commands to execute the test suite and performance benchmarks for the 2Geom library after building. Tests are enabled by default. ```bash make test make perf ``` -------------------------------- ### Building and Linking Custom Main Executables Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/CMakeLists.txt This loop iterates through the custom main test source files, creates an executable for each, links them with 2geom, GTest::GTest, GSL, and GLIB, and registers them as tests. ```cmake foreach(source ${2GEOM_TESTS_SRC}) add_executable(${source} ${source}.cpp) target_link_libraries(${source} 2geom GTest::GTest GSL::gsl PkgConfig::GLIB) add_test(NAME ${source} COMMAND ${source}) endforeach(source) ``` -------------------------------- ### Build 2Geom Library Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/README.md Standard CMake build process for the 2Geom library. Ensure you are in the project root directory. ```bash mkdir build && cd build cmake .. make ``` -------------------------------- ### Importing Cython Bindings Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/report.md This is how users typically import the entire set of bindings into their Python environment. ```python >>> import cy2geom ``` -------------------------------- ### Check MinGW Make Version Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/README.win32.md Verify that the correct version of GNU Make is being used. If a different make utility is found, it may cause build issues. ```bash mingw32-make --version ``` -------------------------------- ### Building and Linking GTest Executables Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/CMakeLists.txt This loop iterates through the GTest source files, creates an executable for each, links them with necessary libraries (2geom, GTest::Main, GSL, GLIB), and registers them as tests. ```cmake foreach(source ${2GEOM_GTESTS_SRC}) add_executable(${source} ${source}.cpp) target_link_libraries(${source} 2geom GTest::Main GSL::gsl PkgConfig::GLIB) add_test(NAME ${source} COMMAND ${source}) endforeach() ``` -------------------------------- ### Dependency Finding Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Finds and configures necessary external libraries and packages such as Boost, double-conversion, PkgConfig, Cython, Threads, GSL, GTK4, and GLib. ```cmake # Find dependencies find_package(Boost 1.60 CONFIG REQUIRED) find_package(double-conversion CONFIG REQUIRED) find_package(PkgConfig REQUIRED) find_package(Cython) find_package(Threads) find_package(GSL REQUIRED) pkg_check_modules(GTK IMPORTED_TARGET gtk4) pkg_check_modules(GLIB IMPORTED_TARGET REQUIRED glib-2.0) ``` -------------------------------- ### Create an Arc using Bezier Order Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt This snippet demonstrates how to create an arc centered at a specific point with a given radius. It uses Bezier order and trigonometric functions to define the arc's path. ```C++ B[0] = BezOrd(centre[0]) + 100*cos(0,1,2); ``` -------------------------------- ### Project Definition and Languages Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Defines the project name, version, and the programming languages used. C is explicitly included for CHECK_SYMBOL_EXISTS compatibility. ```cmake project(lib2geom VERSION ${2GEOM_VERSION} LANGUAGES CXX C # C is required by CHECK_SYMBOL_EXISTS ) ``` -------------------------------- ### Setting Python Site-Packages Directory (Unix-like) Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Sets a default path for the Python site-packages directory on Unix-like systems. This path can be overridden by the user. ```cmake SET(PYTHON_LIB_INSTALL "/usr/local/lib/python2.7/dist-packages" CACHE STRING "Where to install the cy2geom moduleক্ষা") SET(SITEPACKAGE ${PYTHON_LIB_INSTALL}) ENDIF(WIN32) ``` -------------------------------- ### Enable and Configure py2geom Build Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/py2geom/CMakeLists.txt Enables the py2geom Boost.Python binding via an option. It then finds required packages like Python 3 and Boost, sets up include directories, and defines the py2geom shared library. ```cmake OPTION(2GEOM_BOOST_PYTHON "Build a python binding with Boost.Python" OFF) IF(2GEOM_BOOST_PYTHON) FIND_PACKAGE(Python3 COMPONENTS Development Interpreter REQUIRED) SET(Boost_DEBUG TRUE) SET(Boost_REALPATH FALSE) FIND_PACKAGE(Boost 1.42.0 REQUIRED) FIND_PACKAGE(Boost REQUIRED COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}) IF (WIN32) SET_TARGET_PROPERTIES(py2geom PROPERTIES SUFFIX ".pyd") ELSEIF (APPLE) SET(CMAKE_MACOSX_RPATH FALSE) SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so") ENDIF(WIN32) INCLUDE_DIRECTORIES( src/ ${Python3_INCLUDE_DIRS} ${Boost_INCLUDE_DIR} ) ADD_LIBRARY(py2geom SHARED ${2GEOM_BOOST_PYTHON_SRC}) ``` -------------------------------- ### Profiling and Coverage Options Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Configures options for enabling code profiling (-pg flag) and code coverage reports using gcovr. This helps in performance analysis and testing. ```cmake option(WITH_PROFILING "Build lib2geom with profiling enabled" OFF) if(WITH_PROFILING) add_compile_options(-pg) set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pg") endif() option(WITH_COVERAGE "Enable generation of code coverage reports." OFF) if(WITH_COVERAGE) set(GCOVR_ADDITIONAL_ARGS "-s") include(CodeCoverage) set(COVERAGE_EXCLUDES "${PROJECT_SOURCE_DIR}/src/performance-tests/*" "${PROJECT_SOURCE_DIR}/src/py2geom/*" "${PROJECT_SOURCE_DIR}/src/toys/*" "${PROJECT_SOURCE_DIR}/include/toys/*") setup_target_for_coverage_gcovr_xml(NAME coverage_xml EXECUTABLE ctest --output-on-failure) setup_target_for_coverage_gcovr_html(NAME coverage_html EXECUTABLE ctest) append_coverage_compiler_flags()) endif() ``` -------------------------------- ### Build Performance Test Executables Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/performance-tests/CMakeLists.txt Iterates through the defined performance test source files, creates an executable for each, links necessary libraries, and adds them as dependencies to the 'perf' target. ```cmake IF(2GEOM_PERFORMANCE_TESTS) FOREACH(source ${2GEOM_PERFORMANCE_TESTS_SRC}) ADD_EXECUTABLE(${source} ${source}.cpp) target_link_libraries(${source} 2Geom::2geom PkgConfig::GLIB) add_dependencies(perf ${source}) add_custom_command(TARGET perf POST_BUILD COMMAND ${source}) ENDFOREACH(source) ENDIF() ``` -------------------------------- ### Run lib2geom tests Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/HACKING.md Execute the test suite for lib2geom after successful compilation. This command is specific to Debian-like platforms. ```bash make test ``` -------------------------------- ### Create an Arc with SBasis and Trigonometric Functions Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt This code snippet shows an alternative method for creating an arc using SBasis and trigonometric functions. It might be necessary due to potential inaccuracies with std::cos. ```C++ SBasis(BezOrd(centre[0])) + 100*cos(0,1,2); ``` -------------------------------- ### Define Performance Test Source Files Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/performance-tests/CMakeLists.txt Lists the source files for the performance tests. These are used to build individual test executables. ```cmake SET(2GEOM_PERFORMANCE_TESTS_SRC example-performance-test boolops-performance-test bendpath-test bezier-utils-test parse-svg-test path-operations-test ) ``` -------------------------------- ### Set C++ Standard and Extensions Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Configures the C++ standard to C++20 and disables C++ extensions to enforce a stricter standard compliance. ```cmake set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # enforces -std=c++20 instead of -std=gnu++20 ``` -------------------------------- ### Linking Libraries and Executables Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/dependent-project/CMakeLists.txt Defines and links custom libraries and executables against the 2Geom library. Ensures your project can utilize 2Geom's functionality. ```cmake add_library(my_lib SHARED my_lib.cpp) add_executable(main main.cpp) target_link_libraries(main my_lib) target_link_libraries(my_lib PUBLIC 2Geom::2geom) ``` -------------------------------- ### Adding Cython Module: _cy_affine Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Compiles the '_cy_affine.pyx' file into a Python extension module named '_cy_affine'. ```cmake cython_add_module( _cy_affine _cy_affine.pyx) ``` -------------------------------- ### Link Libraries for py2geom Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/py2geom/CMakeLists.txt Links the necessary libraries to the py2geom target. This includes the 2geom library, Boost.Python, Python libraries, and optionally Cairo libraries, depending on whether static Boost.Python is used and if PyCairo is found. ```cmake SET_TARGET_PROPERTIES(py2geom PROPERTIES PREFIX "_") IF (BUILD_BOOST_PYTHON_STATIC) TARGET_LINK_LIBRARIES(py2geom 2geom ${Python3_LIBRARIES}) ELSE (BUILD_BOOST_PYTHON_STATIC) TARGET_LINK_LIBRARIES(py2geom 2geom ${Boost_LIBRARIES} ${Python3_LIBRARIES}) ENDIF (BUILD_BOOST_PYTHON_STATIC) set_property(TARGET 2geom PROPERTY POSITION_INDEPENDENT_CODE ON) # we need -fPIC to link py2geom against 2geom IF(PYCAIRO_FOUND) TARGET_LINK_LIBRARIES(py2geom ${Cairo_LIBRARIES}) ENDIF(PYCAIRO_FOUND) ``` -------------------------------- ### Set Project Version and ABI Version Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Sets the major, minor, and patch versions for the project, and also defines the ABI version. These are used for internal tracking and compatibility checks. ```cmake set(2GEOM_MAJOR_VERSION 1) set(2GEOM_MINOR_VERSION 5) set(2GEOM_PATCH_VERSION 0) set(2GEOM_VERSION ${2GEOM_MAJOR_VERSION}.${2GEOM_MINOR_VERSION}.${2GEOM_PATCH_VERSION} CACHE INTERNAL "" FORCE) set(2GEOM_ABI_VERSION ${2GEOM_MAJOR_VERSION}.${2GEOM_MINOR_VERSION}.0) ``` -------------------------------- ### Copy Performance Test DLL on Windows Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/performance-tests/CMakeLists.txt Conditionally creates a custom target to copy the 2Geom DLL to the performance tests directory on Windows if shared libraries are enabled. Ensures the performance tests can find the shared library. ```cmake IF(WIN32 AND 2GEOM_BUILD_SHARED) ADD_CUSTOM_TARGET(copy-perf ALL COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/src/2geom/lib2geom.dll ${CMAKE_BINARY_DIR}/src/performance-tests/lib2geom.dll) ADD_DEPENDENCIES(copy-perf 2geom) ENDIF() ``` -------------------------------- ### Linking Dependencies for _cy_affine Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Links the '_cy_affine' module against the GSL libraries, GSL CBLAS, and the main 2geom library. ```cmake target_link_libraries(_cy_affine gsl gslcblas 2geom ) ``` -------------------------------- ### Boilerplate to Draw an SBasis to Cairo Canvas Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt Provides the necessary boilerplate code to draw a multidimensional sbasis object onto a cairo canvas. This involves creating a path builder and converting the sbasis to a cairo path. ```cpp void draw_cb(cairo_t *cr, multidim_sbasis<2> const &B) { Geom::PathBuilder pb; subpath_from_sbasis(pb, B, 0.1); cairo_path(cr, pb.peek()); } ``` -------------------------------- ### Adding Cython Module: _cy_path Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Compiles the '_cy_path.pyx' file into a Python extension module named '_cy_path'. ```cmake cython_add_module( _cy_path _cy_path.pyx) ``` -------------------------------- ### Conditional Definitions based on Found Packages Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Adds preprocessor definitions based on whether certain packages like GSL, PYCAIRO, or GTK were found during the configuration process. ```cmake if(TARGET GSL::gsl) add_definitions(-DHAVE_GSL) endif() if(PYCAIRO_FOUND) add_definitions(-DHAVE_PYCAIRO) endif() ``` -------------------------------- ### Enable Testing Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Enables the testing suite if the project is being built as a standalone application. This involves enabling CMake's testing infrastructure. ```cmake option(2GEOM_TESTING "Build tests" "${2GEOM_STANDALONE}") if(2GEOM_TESTING) enable_testing() add_subdirectory(tests) endif() ``` -------------------------------- ### Shared vs. Static Library Build Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Determines whether to build lib2geom and libtoy as shared or static libraries based on the '2GEOM_BUILD_SHARED' option. ```cmake option(2GEOM_BUILD_SHARED "Build lib2geom and libtoy as shared libraries." OFF) if(2GEOM_BUILD_SHARED) set(LIB_TYPE SHARED) else() set(LIB_TYPE STATIC) endif() ``` -------------------------------- ### Linking Dependencies for _cy_path Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Links the '_cy_path' module against the GSL libraries, GSL CBLAS, and the main 2geom library. ```cmake target_link_libraries(_cy_path gsl gslcblas 2geom ) ``` -------------------------------- ### Setting Library Type Based on Build Option Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Configures the library type (SHARED or STATIC) and linker flags based on the `2GEOM_CYTHON_BUILD_SHARED` option. ```cmake IF(2GEOM_CYTHON_BUILD_SHARED) SET(LIB_TYPE SHARED) SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -shared") ELSE(2GEOM_CYTHON_BUILD_SHARED) SET(LIB_TYPE STATIC) ENDIF(2GEOM_CYTHON_BUILD_SHARED) ``` -------------------------------- ### Defining Test Source Files (Custom Main) Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/CMakeLists.txt This variable lists source files for tests that provide their own main function. These might be integration tests or tests with specific entry point requirements. ```cmake SET(2GEOM_TESTS_SRC #bezier-utils-test #lin_alg_test sbasis-text-test root-find-test implicitization-test #timing-test #rtree-performance-test ) ``` -------------------------------- ### Adding Cython Module: _cy_primitives Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Compiles the '_cy_primitives.pyx' file into a Python extension module named '_cy_primitives'. ```cmake cython_add_module( _cy_primitives _cy_primitives.pyx) ``` -------------------------------- ### Create Alias Target for 2geom Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/2geom/CMakeLists.txt Creates an alias target '2Geom::2geom' that points to the '2geom' target for easier referencing. ```cmake add_library(2Geom::2geom ALIAS 2geom) ``` -------------------------------- ### Adding Cython Module: cy2geom Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Compiles the main 'cy2geom.pyx' file into the primary Python extension module named 'cy2geom'. ```cmake cython_add_module( cy2geom cy2geom.pyx) ``` -------------------------------- ### Copying DLL on Windows Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/CMakeLists.txt This custom target is defined for Windows builds when 2GEOM_BUILD_SHARED is enabled. It copies the lib2geom.dll to the tests directory if it has changed, ensuring tests can find the shared library. ```cmake if(WIN32 AND 2GEOM_BUILD_SHARED) add_custom_target(copy ALL COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/src/2geom/lib2geom.dll ${CMAKE_BINARY_DIR}/tests/lib2geom.dll) add_dependencies(copy 2geom) endif() ``` -------------------------------- ### Adding Cython Module: _cy_curves Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Compiles the '_cy_curves.pyx' file into a Python extension module named '_cy_curves'. ```cmake cython_add_module( _cy_curves _cy_curves.pyx) ``` -------------------------------- ### Define 2GEOM_BOOST_PYTHON_SRC Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/py2geom/CMakeLists.txt Defines the source files for the Boost.Python binding. This list includes various .cpp files from the 2geom library. ```cmake SET(2GEOM_BOOST_PYTHON_SRC etc.cpp point.cpp interval.cpp transforms.cpp rect.cpp line.cpp circle.cpp ellipse.cpp conic.cpp crossing.cpp sbasis.cpp bezier.cpp linear.cpp pw.cpp d2.cpp parser.cpp path.cpp ray.cpp py2geom.cpp ) ``` -------------------------------- ### Set SOVERSION for 2geom Target Properties Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/2geom/CMakeLists.txt Configures the shared object version (SOVERSION) for the 2geom target. ```cmake set_target_properties(2geom PROPERTIES SOVERSION "${2GEOM_ABI_VERSION}") ``` -------------------------------- ### Adding Cython Module: _cy_conicsection Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Compiles the '_cy_conicsection.pyx' file into a Python extension module named '_cy_conicsection'. ```cmake cython_add_module( _cy_conicsection _cy_conicsection.pyx) ``` -------------------------------- ### GPL Code Inclusion Option Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt An option to control whether GPL licensed code should be included in the build. If enabled, a preprocessor definition is added. ```cmake option(2GEOM_USE_GPL_CODE "Build lib2geom with GPL licensed Code." ON) if(2GEOM_USE_GPL_CODE) add_definitions(-DGPL_TAINT) endif() ``` -------------------------------- ### Linking Dependencies for _cy_curves Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Links the '_cy_curves' module against the GSL libraries, GSL CBLAS, and the main 2geom library. ```cmake target_link_libraries(_cy_curves gsl gslcblas 2geom ) ``` -------------------------------- ### Linking Dependencies for _cy_primitives Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Links the '_cy_primitives' module against the GSL libraries, GSL CBLAS, and the main 2geom library. Note the comment regarding potential -fPIC errors when linking static libraries. ```cmake target_link_libraries(_cy_primitives #TODO! linking to static lib2geom.a gives -fPIC error, to compile #you have to enable building dynamic library in cmake . -i gsl gslcblas 2geom ) ``` -------------------------------- ### Conditional Boost.Python Static Build Configuration Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/py2geom/CMakeLists.txt Configures build settings for Boost.Python, specifically handling static library builds on non-Windows systems. It defines the path to Boost.Python source files and adds a preprocessor definition for static linking. ```cmake IF (WIN32) SET(BUILD_BOOST_PYTHON_STATIC FALSE) ELSE (WIN32) SET(BUILD_BOOST_PYTHON_STATIC FALSE) ENDIF (WIN32) IF (BUILD_BOOST_PYTHON_STATIC) SET(BOOST_PYTHON_SRC "C:/boost_1_42_0/libs/python/src") #define BOOST_PYTHON_STATIC_LIB SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_PYTHON_STATIC_LIB") SET(2GEOM_BOOST_PYTHON_SRC ${2GEOM_BOOST_PYTHON_SRC} ${BOOST_PYTHON_SRC}/dict.cpp ${BOOST_PYTHON_SRC}/errors.cpp ${BOOST_PYTHON_SRC}/exec.cpp ${BOOST_PYTHON_SRC}/import.cpp ${BOOST_PYTHON_SRC}/list.cpp ${BOOST_PYTHON_SRC}/long.cpp ${BOOST_PYTHON_SRC}/module.cpp ${BOOST_PYTHON_SRC}/numeric.cpp ${BOOST_PYTHON_SRC}/object_operators.cpp ${BOOST_PYTHON_SRC}/object_protocol.cpp ${BOOST_PYTHON_SRC}/slice.cpp ${BOOST_PYTHON_SRC}/str.cpp ${BOOST_PYTHON_SRC}/tuple.cpp ${BOOST_PYTHON_SRC}/wrapper.cpp ${BOOST_PYTHON_SRC}/converter/arg_to_python_base.cpp ${BOOST_PYTHON_SRC}/converter/builtin_converters.cpp ${BOOST_PYTHON_SRC}/converter/from_python.cpp ${BOOST_PYTHON_SRC}/converter/registry.cpp ${BOOST_PYTHON_SRC}/converter/type_id.cpp ${BOOST_PYTHON_SRC}/object/class.cpp ${BOOST_PYTHON_SRC}/object/enum.cpp ${BOOST_PYTHON_SRC}/object/function.cpp ${BOOST_PYTHON_SRC}/object/function_doc_signature.cpp ${BOOST_PYTHON_SRC}/object/inheritance.cpp ${BOOST_PYTHON_SRC}/object/iterator.cpp ${BOOST_PYTHON_SRC}/object/life_support.cpp ${BOOST_PYTHON_SRC}/object/pickle_support.cpp ${BOOST_PYTHON_SRC}/object/stl_iterator.cpp ) ENDIF (BUILD_BOOST_PYTHON_STATIC) ``` -------------------------------- ### Adding Cython Module: _cy_rectangle Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Compiles the '_cy_rectangle.pyx' file into a Python extension module named '_cy_rectangle'. ```cmake cython_add_module( _cy_rectangle _cy_rectangle.pyx) ``` -------------------------------- ### Link Libraries for 2geom Target Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/2geom/CMakeLists.txt Specifies libraries to link against the 2geom target, categorizing them as private or public dependencies. ```cmake target_link_libraries(2geom PRIVATE GSL::gsl double-conversion::double-conversion PUBLIC Boost::headers ) ``` -------------------------------- ### Create Custom Target for Performance Tests Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/performance-tests/CMakeLists.txt Defines a custom CMake target named 'perf' to group all performance tests. This allows running all tests with a single command. ```cmake add_custom_target(perf) ``` -------------------------------- ### Linking Dependencies for _cy_rectangle Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Links the '_cy_rectangle' module against the GSL libraries, GSL CBLAS, and the main 2geom library. ```cmake target_link_libraries(_cy_rectangle gsl gslcblas 2geom ) ``` -------------------------------- ### Check for sincos Functionality Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Compiles a small C++ program to check if the 'sincos' function is available. If available, a preprocessor definition is added. ```cmake check_cxx_source_compiles("#include \nint main() { double a=0.5,b=0.5,c=0.5; sincos(a, &b, &c); return 0; }" HAVE_SINCOS) if(HAVE_SINCOS) add_definitions(-DHAVE_SINCOS) endif() ``` -------------------------------- ### Compute Derivative of a Bezier Path Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt This snippet illustrates how to compute the derivative of a Bezier path, which can be used to find the tangent to the path. This is a feature not available with simple point plotting. ```C++ derivative(B) ``` -------------------------------- ### Setting Cython Properties for C++ Compilation Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Marks specific Cython interface definition (.pxd) and implementation (.pyx) files as C++ sources. This is crucial for Cython modules that interact with C++ code. ```cmake set_source_files_properties( _common_decl.pxd _common_decl.pyx _cy_primitives.pxd _cy_primitives.pyx _cy_rectangle.pxd _cy_rectangle.pyx _cy_affine.pxd _cy_affine.pyx _cy_curves.pxd _cy_curves.pyx _cy_path.pxd _cy_path.pyx _cy_conicsection.pxd _cy_conicsection.pyx cy2geom.pyx PROPERTIES CYTHON_IS_CXX 1) ``` -------------------------------- ### Define a Linear SBasis Function using BezOrds Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt Define a linear sbasis function using BezOrds, which maps the input parameter range [0,1] to a line segment between two points. This is a common way to create lines. ```cpp B[dim] = BezOrd(handles[1][dim], handles[2][dim]); ``` -------------------------------- ### Defining Test Source Files (GTest) Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/CMakeLists.txt This variable lists the source files for tests that use the default GTest main function. These are typically standard GTest-based unit tests. ```cmake SET(2GEOM_GTESTS_SRC affine-test angle-test bezier-test choose-test circle-test convex-hull-test coord-test ellipse-test elliptical-arc-test intersection-graph-test interval-test line-test min-bbox-test nl-vector-test parallelogram-test path-test planar-graph-test point-test polynomial-test rect-test sbasis-test self-intersections-test arithmetic-interval-test line-segment-intersection-test ) ``` -------------------------------- ### Sign and Tag Release Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/RELEASING.md Commands to create a detached signature for the release tarball and tag the Git repository. ```bash gpg --armor --detach-sign --output lib2geom-${VERSION}.tar.bz2.sig lib2geom-${VERSION}.tar.bz2 git tag -s ${MAJOR}.${MINOR} git push --tags ``` -------------------------------- ### Linking Dependencies for _cy_conicsection Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Links the '_cy_conicsection' module against the GSL libraries, GSL CBLAS, and the main 2geom library. ```cmake target_link_libraries(_cy_conicsection gsl gslcblas 2geom ) ``` -------------------------------- ### Adding Cython Module: _common_decl Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Compiles the '_common_decl.pyx' file into a Python extension module named '_common_decl'. ```cmake cython_add_module( _common_decl _common_decl.pyx) ``` -------------------------------- ### Enable/Disable Performance Tests Build Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/performance-tests/CMakeLists.txt An option to control whether the performance tests are built. Defaults to ON. ```cmake OPTION(2GEOM_PERFORMANCE_TESTS "Build the performance tests" ON) ``` -------------------------------- ### Finding GTest Package Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/tests/CMakeLists.txt This snippet finds the GTest (Google Test) framework, which is required for running tests. It uses the REQUIRED MODULE option to ensure the package is available. ```cmake find_package(GTest REQUIRED MODULE) ``` -------------------------------- ### Find Roots of Curvature Derivative Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt Finds the t values corresponding to maximum or minimum curvature by calculating the roots of the derivative of the curvature function. ```C++ std::vector r = roots(derivative(curvature(B))); ``` -------------------------------- ### Adding CMake Test for Cython Affine Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Defines a CMake test named 'cython-affine' that executes the 'test-affine.py' script using the 'python2' interpreter. ```cmake add_test(cython-affine python2 test-affine.py) ``` -------------------------------- ### Finding Python Libraries Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Locates the Python development libraries required for building Python extensions. This is a standard CMake step for Python integration. ```cmake FIND_PACKAGE(PythonLibs) ``` -------------------------------- ### Iterate and Assign SBasis Functions Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt Use a loop to assign sbasis functions to different dimensions, typically for X and Y components. This is a concise way to define parallel geometric elements. ```cpp for(int im = 0; dim < 2; dim++) B[dim] = handles[1][dim]; ``` -------------------------------- ### Compiler Warning Flags Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/CMakeLists.txt Sets common compiler warning flags to enhance code quality and catch potential issues during compilation. Includes specific flags for Clang on Windows. ```cmake add_compile_options(-Wall -Wformat-security -Woverloaded-virtual -Wpointer-arith -Werror=return-type) # suppress the very annoying "#pragma ms_struct" Clang warning, caused by -mms-bitfield required for GTK if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if(WIN32) add_compile_options(-Wno-ignored-attributes) endif() add_compile_options(-Wno-unused-local-typedef) endif() ``` -------------------------------- ### Adding CMake Test for Cython Path Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Defines a CMake test named 'cython-path' that executes the 'test-path.py' script using the 'python2' interpreter. ```cmake add_test(cython-path python2 test-path.py) ``` -------------------------------- ### Draw a Defined SBasis Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt Call a drawing function to render a previously defined sbasis object onto the cairo canvas. This assumes the drawing function (e.g., draw_md_sb) and the canvas context (cr) are available. ```cpp draw_md_sb(cr, B); ``` -------------------------------- ### Define a Constant SBasis Function Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/doc/tutorial.txt Define a simple sbasis function that maps the input parameter to a constant value. This is useful for creating static points or segments. ```cpp B[dim] = handles[1][dim]; ``` -------------------------------- ### Adding CMake Test for Cython Primitives Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/cython/CMakeLists.txt Defines a CMake test named 'cython-primitives' that executes the 'test-primitives.py' script using the 'python2' interpreter. ```cmake add_test(cython-primitives python2 test-primitives.py) ``` -------------------------------- ### Conditional PyCairo Helper Inclusion Source: https://gitlab.com/inkscape/lib2geom/-/blob/master/src/py2geom/CMakeLists.txt Conditionally adds 'cairo-helpers.cpp' to the Boost.Python source list if PyCairo is found. This integrates PyCairo functionality into the Python binding. ```cmake IF(PYCAIRO_FOUND) SET(2GEOM_BOOST_PYTHON_SRC ${2GEOM_BOOST_PYTHON_SRC} cairo-helpers.cpp ) ENDIF(PYCAIRO_FOUND) ```