### Include Project Subdirectories Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet includes the src, examples, and doc subdirectories into the CMake build system. This organizes the project structure and ensures that the code, examples, and documentation are processed during the build. ```CMake add_subdirectory(src) add_subdirectory(examples) add_subdirectory(doc) ``` -------------------------------- ### Install Project License File Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet configures the installation of the project's LICENSE file. It ensures that the license is included with the runtime components and placed in the standard documentation directory (CMAKE_INSTALL_DOCDIR) during installation. ```CMake install(FILES LICENSE COMPONENT runtime DESTINATION ${CMAKE_INSTALL_DOCDIR}) ``` -------------------------------- ### Define RVO2 Library Installation Rules Source: https://github.com/snape/rvo2/blob/main/src/CMakeLists.txt This section specifies how the RVO2 library, its headers, and associated CMake export files should be installed on the system. It defines different installation components (development, runtime) and their respective destinations, ensuring proper deployment and discoverability for both development and runtime environments. It also includes experimental package info for newer CMake versions. ```CMake install(TARGETS ${RVO_LIBRARY} EXPORT ${PROJECT_NAME}Targets ARCHIVE COMPONENT development DESTINATION ${RVO_LIBRARY_DIR} FILE_SET HEADERS COMPONENT development DESTINATION ${RVO_INCLUDE_DIR} LIBRARY COMPONENT runtime DESTINATION ${RVO_LIBRARY_DIR} NAMELINK_COMPONENT development RUNTIME COMPONENT runtime DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${RVO_INCLUDE_DIR}) install(EXPORT ${PROJECT_NAME}Targets COMPONENT development DESTINATION ${RVO_DIR} NAMESPACE ${PROJECT_NAME}::) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.31 AND ENABLE_CMAKE_EXPERIMENTAL_FEATURES) set(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO b80be207-778e-46ba-8080-b23bba22639e) install(PACKAGE_INFO ${RVO_LIBRARY} EXPORT ${PROJECT_NAME}Targets COMPONENT development DESTINATION ${RVO_CPS_DIR} VERSION ${PROJECT_VERSION} COMPAT_VERSION ${PROJECT_VERSION_MAJOR} VERSION_SCHEMA simple) endif() ``` -------------------------------- ### Configure Doxygen for RVO2 Library Documentation Generation Source: https://github.com/snape/rvo2/blob/main/doc/CMakeLists.txt This CMake snippet configures Doxygen to generate HTML documentation for the RVO2 library. It sets project details, specifies source and example file patterns, customizes HTML output with header/footer/stylesheet, and defines the output format for DOT images. It then adds the Doxygen documentation target and installs the generated HTML files. ```CMake if(BUILD_DOCUMENTATION AND Doxygen_FOUND) set(DOXYGEN_PROJECT_NAME "${RVO_NAME}") set(DOXYGEN_PROJECT_NUMBER ${PROJECT_VERSION}) set(DOXYGEN_PROJECT_BRIEF "${PROJECT_DESCRIPTION}") set(DOXYGEN_STRIP_FROM_PATH "${PROJECT_BINARY_DIR}/src" "${PROJECT_SOURCE_DIR}/src") set(DOXYGEN_BUILTIN_STL_SUPPORT YES) set(DOXYGEN_EXTRACT_ALL YES) set(DOXYGEN_FILE_PATTERNS "*.h") set(DOXYGEN_EXAMPLE_PATH "${PROJECT_SOURCE_DIR}/examples") set(DOXYGEN_EXAMPLE_PATTERNS "*.cc") set(DOXYGEN_HTML_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/header.html") set(DOXYGEN_HTML_FOOTER "${CMAKE_CURRENT_SOURCE_DIR}/footer.html") set(DOXYGEN_HTML_EXTRA_STYLESHEET "${CMAKE_CURRENT_SOURCE_DIR}/stylesheet.css") set(DOXYGEN_SEARCHENGINE NO) set(DOXYGEN_DOT_IMAGE_FORMAT svg) set(DOXYGEN_INTERACTIVE_SVG YES) doxygen_add_docs(documentation "${PROJECT_BINARY_DIR}/src/Export.h" "${PROJECT_SOURCE_DIR}/src/Line.h" "${PROJECT_SOURCE_DIR}/src/RVO.h" "${PROJECT_SOURCE_DIR}/src/RVOSimulator.h" "${PROJECT_SOURCE_DIR}/src/Vector2.h" ALL USE_STAMP_FILE) install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html" COMPONENT documentation DESTINATION ${CMAKE_INSTALL_DOCDIR}) endif() ``` -------------------------------- ### Configure Common Build Options for RVO2 Test Examples in CMake Source: https://github.com/snape/rvo2/blob/main/examples/CMakeLists.txt This CMake snippet defines global options and compile definitions applicable to all RVO2 test examples. It controls features like outputting time/positions, seeding the random number generator, and enabling interprocedural optimization. This configuration is active when BUILD_TESTING is enabled. ```CMake option(OUTPUT_TIME_AND_POSITIONS "Output time and positions" ON) if(OUTPUT_TIME_AND_POSITIONS) set(RVO_EXAMPLES_COMPILE_DEFINITIONS RVO_OUTPUT_TIME_AND_POSITIONS=1) else() set(RVO_EXAMPLES_COMPILE_DEFINITIONS RVO_OUTPUT_TIME_AND_POSITIONS=0) endif() option(SEED_RANDOM_NUMBER_GENERATOR "Seed random number generator" ON) if(SEED_RANDOM_NUMBER_GENERATOR) list(APPEND RVO_EXAMPLES_COMPILE_DEFINITIONS RVO_SEED_RANDOM_NUMBER_GENERATOR=1) else() list(APPEND RVO_EXAMPLES_COMPILE_DEFINITIONS RVO_SEED_RANDOM_NUMBER_GENERATOR=0) endif() if(ENABLE_INTERPROCEDURAL_OPTIMIZATION AND RVO_INTERPROCEDURAL_OPTIMIZATION_SUPPORTED) set(RVO_EXAMPLES_INTERPROCEDURAL_OPTIMIZATION ON) else() set(RVO_EXAMPLES_INTERPROCEDURAL_OPTIMIZATION OFF) endif() ``` -------------------------------- ### Build and Test Configuration for RVO2 Roadmap Example in CMake Source: https://github.com/snape/rvo2/blob/main/examples/CMakeLists.txt This CMake code adds the 'Roadmap' executable, applies common compile definitions, links necessary libraries (RVO2 and OpenMP if available), sets interprocedural optimization, and registers it as a CTest with specific labels and timeout. This configuration is active when BUILD_TESTING is enabled. ```CMake add_executable(Roadmap Roadmap.cc) target_compile_definitions(Roadmap PRIVATE ${RVO_EXAMPLES_COMPILE_DEFINITIONS}) target_link_libraries(Roadmap PRIVATE ${RVO_LIBRARY}) if(ENABLE_OPENMP AND OpenMP_FOUND) target_link_libraries(Roadmap PRIVATE OpenMP::OpenMP_CXX) endif() set_target_properties(Roadmap PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${RVO_EXAMPLES_INTERPROCEDURAL_OPTIMIZATION}) add_test(NAME Roadmap COMMAND Roadmap) set_tests_properties(Roadmap PROPERTIES LABELS medium TIMEOUT 60) ``` -------------------------------- ### Build and Test Configuration for RVO2 Circle Example in CMake Source: https://github.com/snape/rvo2/blob/main/examples/CMakeLists.txt This CMake code adds the 'Circle' executable, applies common compile definitions, links necessary libraries (RVO2 and OpenMP if available), sets interprocedural optimization, and registers it as a CTest with specific labels and timeout. This configuration is active when BUILD_TESTING is enabled. ```CMake add_executable(Circle Circle.cc) target_compile_definitions(Circle PRIVATE ${RVO_EXAMPLES_COMPILE_DEFINITIONS}) target_link_libraries(Circle PRIVATE ${RVO_LIBRARY}) if(ENABLE_OPENMP AND OpenMP_FOUND) target_link_libraries(Circle PRIVATE OpenMP::OpenMP_CXX) endif() set_target_properties(Circle PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${RVO_EXAMPLES_INTERPROCEDURAL_OPTIMIZATION}) add_test(NAME Circle COMMAND Circle) set_tests_properties(Circle PROPERTIES LABELS medium TIMEOUT 60) ``` -------------------------------- ### Build and Test Configuration for RVO2 Blocks Example in CMake Source: https://github.com/snape/rvo2/blob/main/examples/CMakeLists.txt This CMake code adds the 'Blocks' executable, applies common compile definitions, links necessary libraries (RVO2 and OpenMP if available), sets interprocedural optimization, and registers it as a CTest with specific labels and timeout. This configuration is active when BUILD_TESTING is enabled. ```CMake add_executable(Blocks Blocks.cc) target_compile_definitions(Blocks PRIVATE ${RVO_EXAMPLES_COMPILE_DEFINITIONS}) target_link_libraries(Blocks PRIVATE ${RVO_LIBRARY}) if(ENABLE_OPENMP AND OpenMP_FOUND) target_link_libraries(Blocks PRIVATE OpenMP::OpenMP_CXX) endif() set_target_properties(Blocks PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${RVO_EXAMPLES_INTERPROCEDURAL_OPTIMIZATION}) add_test(NAME Blocks COMMAND Blocks) set_tests_properties(Blocks PROPERTIES LABELS medium TIMEOUT 60) ``` -------------------------------- ### Set Installation Paths and Library Naming Conventions Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet utilizes GNUInstallDirs to define standard installation directories for CMake packages, include files, and libraries. It then sets specific paths for RVO2's CMake, CPS, include, and library directories, along with the internal name for the RVO library. ```CMake include(GNUInstallDirs) set(RVO_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) set(RVO_CPS_DIR ${CMAKE_INSTALL_LIBDIR}/cps/${PROJECT_NAME}) set(RVO_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) set(RVO_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}) set(RVO_LIBRARY RVO) set(RVO_NAME "RVO2 Library") ``` -------------------------------- ### Integrate PkgConfig Support Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet integrates PkgConfig support for the project. If PkgConfig is found, it configures and installs a .pc file, enabling other build systems to discover and link against this project using PkgConfig. ```CMake find_package(PkgConfig MODULE) if(PkgConfig_FOUND) configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" COMPONENT development DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() ``` -------------------------------- ### List Python dependencies for RVO2 library Source: https://github.com/snape/rvo2/blob/main/requirements.txt Specifies the Python packages required to build and run the RVO2 library. These packages are typically installed using pip from the requirements.txt file. ```Python cffconvert cmakelang cpplint reuse ``` -------------------------------- ### Configure CPack Packaging Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet includes system libraries and configures CPack variables for creating distributable packages. It sets the package name, contact, vendor, and version, preparing the project for packaging and distribution. ```CMake include(InstallRequiredSystemLibraries) set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) set(CPACK_PACKAGE_CONTACT "Jamie Snape") set(CPACK_PACKAGE_VENDOR "University of North Carolina at Chapel Hill") set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) ``` -------------------------------- ### Enable Documentation and OpenMP Support Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet provides options to build Doxygen documentation for the project, checking for Doxygen's availability. It also includes an option to enable OpenMP support, which allows for parallel execution and can significantly improve performance on multi-core systems if OpenMP is found. ```CMake option(BUILD_DOCUMENTATION "Build documentation" OFF) if(BUILD_DOCUMENTATION) find_package(Doxygen 1.9.1 MODULE OPTIONAL_COMPONENTS dot) endif() option(ENABLE_OPENMP "Enable OpenMP if available" OFF) if(ENABLE_OPENMP) find_package(OpenMP MODULE) endif() ``` -------------------------------- ### Configure Interprocedural Optimization (IPO) Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This section allows enabling interprocedural optimization (IPO), a compiler optimization that can improve performance by analyzing code across different compilation units. It checks for IPO support using `CheckIPOSupported` and provides status messages indicating whether IPO is supported on the current system. ```CMake option(ENABLE_INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural optimization if supported" OFF) if(ENABLE_INTERPROCEDURAL_OPTIMIZATION) include(CheckIPOSupported) check_ipo_supported(RESULT RVO_INTERPROCEDURAL_OPTIMIZATION_SUPPORTED LANGUAGES CXX) if(RVO_INTERPROCEDURAL_OPTIMIZATION_SUPPORTED) message(STATUS "Interprocedural optimization is supported") else() message(STATUS "Interprocedural optimization is NOT supported") endif() else() set(RVO_INTERPROCEDURAL_OPTIMIZATION_SUPPORTED) endif() ``` -------------------------------- ### Define RVO2 Project and Set Default Build Type Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet defines the RVO2 project, specifying its version, description, homepage URL, and the primary language (CXX). It also configures the default build type to 'Release' if not explicitly set, providing options for various build configurations like Debug, RelWithDebInfo, and MinSizeRel. ```CMake cmake_minimum_required(VERSION 3.26) project(RVO VERSION 2.0.3 DESCRIPTION "Optimal Reciprocal Collision Avoidance" HOMEPAGE_URL https://gamma.cs.unc.edu/RVO2/ LANGUAGES CXX) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) # cmake-lint: disable=C0301 set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build; options are Debug Release RelWithDebInfo MinSizeRel" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel) endif() ``` -------------------------------- ### Configure CPack for Multi-Platform Packaging Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This CMake snippet configures CPack to generate various types of software packages (e.g., Debian, RPM, FreeBSD). It sets package metadata like version, description, and license, defines files to ignore during source packaging, and specifies OS-specific options such as compression type, dependencies, and homepage URL. ```CMake set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_STRIP_FILES ON) set(CPACK_SOURCE_IGNORE_FILES _build/ \\.git/ \\.gitattributes \\.github/ \\.gitignore bazel- Brewfile) set(CPACK_SOURCE_STRIP_FILES ON) set(CPACK_DEBIAN_COMPRESSION_TYPE zstd) set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/triggers") set(CPACK_DEBIAN_PACKAGE_DEPENDS) set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${PROJECT_HOMEPAGE_URL}) set(CPACK_DEBIAN_PACKAGE_SECTION contrib/libdevel) set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) set(CPACK_FREEBSD_PACKAGE_DEPS) set(CPACK_FREEBSD_PACKAGE_LICENSE APACHE20) set(CPACK_FREEBSD_PACKAGE_WWW ${PROJECT_HOMEPAGE_URL}) set(CPACK_RPM_FILE_NAME RPM-DEFAULT) set(CPACK_RPM_PACKAGE_AUTOREQPROV ON) set(CPACK_RPM_PACKAGE_LICENSE "ASL 2.0") set(CPACK_RPM_PACKAGE_REQUIRES) set(CPACK_RPM_PACKAGE_URL ${PROJECT_HOMEPAGE_URL}) include(CPack) ``` -------------------------------- ### Define RVO2 Library Target and Generate Export Header Source: https://github.com/snape/rvo2/blob/main/src/CMakeLists.txt This snippet initializes the RVO2 library target and uses the `GenerateExportHeader` module to create a header file (`Export.h`). This generated header is essential for properly exporting symbols from the library, enabling its use across different platforms and build configurations. ```CMake add_library(${RVO_LIBRARY}) include(GenerateExportHeader) generate_export_header(${RVO_LIBRARY} EXPORT_FILE_NAME Export.h) ``` -------------------------------- ### Enable Experimental Features and Configure Shared Library Build Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This section introduces an option to enable experimental CMake features. It also includes CTest for testing integration. Furthermore, it determines whether to build libraries as shared or static, defaulting to static on Windows and shared on other operating systems. ```CMake option(ENABLE_CMAKE_EXPERIMENTAL_FEATURES "Enable CMake experimental features" OFF) include(CTest) if(WIN32) set(BUILD_SHARED_LIBS OFF) else() option(BUILD_SHARED_LIBS "Build all libraries as shared" ON) endif() ``` -------------------------------- ### Export RVO2 Library Targets for External CMake Projects Source: https://github.com/snape/rvo2/blob/main/src/CMakeLists.txt This command exports the RVO2 library target, making it discoverable and linkable by other CMake projects. It generates a CMake file (`${PROJECT_NAME}Targets.cmake`) in the binary directory, which defines the library's properties and location for seamless integration into external build systems. ```CMake export(TARGETS ${RVO_LIBRARY} NAMESPACE ${PROJECT_NAME}:: FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") ``` -------------------------------- ### Specify RVO2 Library Source Files Source: https://github.com/snape/rvo2/blob/main/src/CMakeLists.txt This section defines all source files and headers that comprise the RVO2 library. It categorizes files into public headers and private implementation files, specifying their base directories to ensure all necessary components are included in the build. ```CMake target_sources(${RVO_LIBRARY} PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" FILES "${CMAKE_CURRENT_BINARY_DIR}/Export.h" Line.h RVO.h RVOSimulator.h Vector2.h PRIVATE Agent.cc Agent.h Export.cc KdTree.cc KdTree.h Line.cc Obstacle.cc Obstacle.h RVOSimulator.cc Vector2.cc) ``` -------------------------------- ### Apply Hardening Compiler and Linker Flags for MSVC Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet configures security hardening flags specifically for Microsoft Visual C++ (MSVC) compilers. It checks for support of flags like /GS (buffer security check), /guard:cf (Control Flow Guard), /DYNAMICBASE, and /NXCOMPAT, applying them if available to enhance the security of the compiled binaries against various attacks. ```CMake include(CheckCXXCompilerFlag) include(CheckLinkerFlag) option(ENABLE_HARDENING "Enable hardening compiler and linker flags if supported" OFF) if(ENABLE_HARDENING) if(MSVC) check_cxx_compiler_flag(/GS RVO_COMPILER_SUPPORTS_GS) check_cxx_compiler_flag(/guard:cf RVO_COMPILER_SUPPORTS_GUARD_CF) if(RVO_COMPILER_SUPPORTS_GS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS") endif() check_linker_flag(CXX /DYNAMICBASE RVO_LINKER_SUPPORTS_DYNAMICBASE) check_linker_flag(CXX /GUARD:CF RVO_LINKER_SUPPORTS_GUARD_CF) check_linker_flag(CXX /NXCOMPAT RVO_LINKER_SUPPORTS_NXCOMPAT) if(RVO_COMPILER_SUPPORTS_GUARD_CF AND RVO_LINKER_SUPPORTS_DYNAMICBASE AND RVO_LINKER_SUPPORTS_GUARD_CF) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /guard:cf") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DYNAMICBASE /GUARD:CF") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DYNAMICBASE /GUARD:CF") endif() if(RVO_LINKER_SUPPORTS_NXCOMPAT) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NXCOMPAT") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NXCOMPAT") endif() ``` -------------------------------- ### Enable Warnings as Errors Option Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet defines a CMake option WARNINGS_AS_ERRORS that, when enabled, configures the compiler to treat all warnings as errors. It applies /WX for MSVC and -Werror for other compilers, enforcing stricter code quality standards. ```CMake option(WARNINGS_AS_ERRORS "Turn compiler warnings into errors" OFF) if(WARNINGS_AS_ERRORS) if(MSVC) check_cxx_compiler_flag(/WX RVO_COMPILER_SUPPORTS_WX) if(RVO_COMPILER_SUPPORTS_WX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") endif() else() check_cxx_compiler_flag(-Werror RVO_COMPILER_SUPPORTS_WERROR) if(RVO_COMPILER_SUPPORTS_WERROR) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") endif() endif() endif() ``` -------------------------------- ### Configure Compiler Warning Flags Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This section configures C++ compiler warning levels. It checks for and applies /W4 for MSVC compilers and -Wall, -Wformat-security, -Werror=format-security, and -Wno-unused for GCC/Clang-like compilers, enhancing code quality and identifying potential issues. ```CMake if(MSVC) check_cxx_compiler_flag(/W4 RVO_COMPILER_SUPPORTS_W4) if(RVO_COMPILER_SUPPORTS_W4) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") endif() else() check_cxx_compiler_flag(-Wall RVO_COMPILER_SUPPORTS_WALL) check_cxx_compiler_flag(-Wformat-security RVO_COMPILER_SUPPORTS_WFORMAT_SECURITY) check_cxx_compiler_flag(-Werror=format-security RVO_COMPILER_SUPPORTS_WERROR_FORMAT_SECURITY) check_cxx_compiler_flag(-Wno-unused RVO_COMPILER_SUPPORTS_WNO_UNUSED) if(RVO_COMPILER_SUPPORTS_WALL) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") endif() if(RVO_COMPILER_SUPPORTS_WFORMAT_SECURITY) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-security") endif() if(RVO_COMPILER_SUPPORTS_WERROR_FORMAT_SECURITY) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security") endif() if(RVO_COMPILER_SUPPORTS_WNO_UNUSED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused") endif() endif() ``` -------------------------------- ### Configure Linker --as-needed Flag Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt For non-MSVC compilers, this snippet checks for and applies the --as-needed linker flag. This flag ensures that shared libraries are only linked if they are actually used by the target, optimizing the linking process and reducing unnecessary dependencies. ```CMake if(NOT MSVC) check_linker_flag(CXX -Wl,--as-needed RVO_LINKER_SUPPORTS__AS_NEEDED) if(RVO_LINKER_SUPPORTS__AS_NEEDED) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed") endif() endif() ``` -------------------------------- ### Configure RVO2 Library Build Properties and Conditional Flags Source: https://github.com/snape/rvo2/blob/main/src/CMakeLists.txt This snippet sets various build properties for the RVO2 library, including C++ symbol visibility, library versioning, and conditional compilation flags. It enables interprocedural optimization if supported, adds Windows-specific definitions (NOMINMAX), and links OpenMP if available, optimizing the build for different environments. ```CMake set_target_properties(${RVO_LIBRARY} PROPERTIES CXX_VISIBILITY_PRESET hidden SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION} VISIBILITY_INLINES_HIDDEN ON) if(ENABLE_INTERPROCEDURAL_OPTIMIZATION AND RVO_INTERPROCEDURAL_OPTIMIZATION_SUPPORTED) set_target_properties(${RVO_LIBRARY} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) endif() if(WIN32) target_compile_definitions(${RVO_LIBRARY} PUBLIC NOMINMAX) endif() if(ENABLE_OPENMP AND OpenMP_FOUND) target_link_libraries(${RVO_LIBRARY} PRIVATE OpenMP::OpenMP_CXX) endif() ``` -------------------------------- ### Configure Linux/Unix Linker Hardening Flags Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet checks for and applies various linker hardening flags (e.g., -z,defs, -z,noexecheap, -Bsymbolic-functions, -fsanitize=safe-stack) to improve security and stability of executables and shared libraries on non-MSVC platforms. It uses check_linker_flag to determine compiler support before setting CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS. ```CMake check_linker_flag(CXX -Wl,-z,defs RVO_LINKER_SUPPORTS_Z_DEFS) check_linker_flag(CXX -Wl,-z,noexecheap RVO_LINKER_SUPPORTS_Z_NOEXECHEAP) check_linker_flag(CXX -Wl,-z,noexecstack RVO_LINKER_SUPPORTS_Z_NOEXECSTACK) check_linker_flag(CXX -Wl,-z,now RVO_LINKER_SUPPORTS_Z_NOW) check_linker_flag(CXX -Wl,-z,relro RVO_LINKER_SUPPORTS_Z_RELRO) if(RVO_LINKER_SUPPORTS_BSYMBOLIC_FUNCTIONS) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bsymbolic-functions") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions") endif() if(RVO_COMPILER_SUPPORTS_FSANITIZE_SAFE_STACK AND RVO_LINKER_SUPPORTS_FSANITIZE_SAFE_STACK) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=safe-stack") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=safe-stack") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=safe-stack") endif() if(RVO_LINKER_SUPPORTS_Z_DEFS) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,defs") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") endif() if(RVO_LINKER_SUPPORTS_Z_NOEXECHEAP) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecheap") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecheap") endif() if(RVO_LINKER_SUPPORTS_Z_NOEXECSTACK) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") endif() if(RVO_LINKER_SUPPORTS_Z_NOW) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,now") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,now") endif() if(RVO_LINKER_SUPPORTS_Z_RELRO) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro") endif() ``` -------------------------------- ### Configure CMake Package Export Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet sets up the CMake package configuration files for export. It uses CMakePackageConfigHelpers to generate PROJECT_NAMEConfig.cmake and PROJECT_NAMEConfigVersion.cmake, allowing other CMake projects to easily find and use this project. ```CMake include(CMakePackageConfigHelpers) configure_package_config_file( ${PROJECT_NAME}Config.cmake.in ${PROJECT_NAME}Config.cmake INSTALL_DESTINATION ${RVO_DIR} PATH_VARS RVO_INCLUDE_DIR RVO_LIBRARY_DIR) write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY SameMajorVersion) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" COMPONENT development DESTINATION ${RVO_DIR}) ``` -------------------------------- ### Apply Hardening Compiler Flags for GCC/Clang Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This snippet configures security hardening flags for non-MSVC compilers, typically GCC or Clang. It checks for support of various flags such as -D_FORTIFY_SOURCE (runtime buffer overflow detection), -fcf-protection (Control-Flow Enforcement Technology), -fno-common, and different stack protector options, applying them to improve the security and robustness of the compiled code. ```CMake else() check_cxx_compiler_flag(-D_FORTIFY_SOURCE=2 RVO_COMPILER_SUPPORTS_D_FORTIFY_SOURCE_2) check_cxx_compiler_flag(-fcf-protection RVO_COMPILER_SUPPORTS_FCF_PROTECTION) check_cxx_compiler_flag(-fno-common RVO_COMPILER_SUPPORTS_FNO_COMMON) check_cxx_compiler_flag(-fsanitize=safe-stack RVO_COMPILER_SUPPORTS_FSANITIZE_SAFE_STACK) check_cxx_compiler_flag(-fstack-clash-protection RVO_COMPILER_SUPPORTS_FSTACK_CLASH_PROTECTION) check_cxx_compiler_flag(-fstack-protector-strong RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR_STRONG) if(RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR_STRONG) set(RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR) else() check_cxx_compiler_flag(-fstack-protector RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR) endif() if(RVO_COMPILER_SUPPORTS_D_FORTIFY_SOURCE_2) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2") endif() if(RVO_COMPILER_SUPPORTS_FCF_PROTECTION) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection") endif() if(RVO_COMPILER_SUPPORTS_FNO_COMMON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common") endif() if(RVO_COMPILER_SUPPORTS_FSTACK_CLASH_PROTECTION) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-clash-protection") endif() if(RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR_STRONG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong") elseif(RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") endif() check_linker_flag(CXX -Wl,-Bsymbolic-functions RVO_LINKER_SUPPORTS_BSYMBOLIC_FUNCTIONS) check_linker_flag(CXX -fsanitize=safe-stack RVO_LINKER_SUPPORTS_FSANITIZE_SAFE_STACK) ``` -------------------------------- ### Configure C++ Standard and Position Independent Code Source: https://github.com/snape/rvo2/blob/main/CMakeLists.txt This section explicitly sets the C++ standard for the project to C++98, ensuring compatibility. It also disables C++ extensions and the requirement for the standard, while enabling position-independent code (PIC) for the build, which is crucial for shared libraries. ```CMake set(CMAKE_CXX_STANDARD 98) set(CMAKE_CXX_STANDARD_REQUIRED OFF) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.