Skip to content

Commit

Permalink
build and documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
scholarsmate committed Oct 2, 2023
1 parent ea12ca9 commit e6eb5a5
Show file tree
Hide file tree
Showing 52 changed files with 534 additions and 743 deletions.
195 changes: 36 additions & 159 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,222 +30,99 @@ endif ()

message(STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION} (shared libs: ${BUILD_SHARED_LIBS})")

# Make sure windows shared library exports symbols for Scala FFI bindings
# Common configurations
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# Get verbose output from the makefile (useful for debugging the build)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")

# Use C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
list(APPEND CMAKE_MODULE_PATH "cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# GCC needs to pass the -lstdc++fs flag to link C++17 filesystem implementation.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT MINGW)
set(FILESYSTEM_LIB stdc++fs)
endif ()

#######################################################################################################################
# DEPENDENCIES
#######################################################################################################################
if(BUILD_TESTS)
# Dependencies
if (BUILD_TESTS)
include(FetchContent)
# Fetch the Catch2 unit testing framework, build it, and make it available to the project
FetchContent_Declare(
Catch2
GIT_SHALLOW TRUE
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0)
message(STATUS "Fetching, building, and making Catch2 available to the project")
GIT_TAG v3.4.0)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH "${Catch2_SOURCE_DIR}/extras")
endif()

#######################################################################################################################
# CORE LIBRARY
#######################################################################################################################
# Define the library source files
set(OMEGA_EDIT_SOURCE_FILES
"src/include/omega_edit.h"
"src/include/omega_edit/config.h"
"src/include/omega_edit/export.h"
"src/include/omega_edit/fwd_defs.h"
"src/include/omega_edit/byte.h"
"src/include/omega_edit/scoped_ptr.hpp"
"src/include/omega_edit/stl_string_adaptor.hpp" "src/lib/stl_string_adapter.cpp"
"src/include/omega_edit/change.h" "src/lib/change.cpp" "src/lib/impl_/change_def.hpp"
"src/include/omega_edit/character_counts.h" "src/lib/character_counts.c" "src/lib/impl_/character_counts_def.h"
"src/include/omega_edit/check.h" "src/lib/check.cpp"
"src/include/omega_edit/edit.h" "src/lib/edit.cpp"
"src/include/omega_edit/search.h" "src/lib/search.cpp" "src/lib/impl_/search_context_def.h"
"src/include/omega_edit/segment.h" "src/lib/segment.cpp" "src/lib/impl_/segment_def.hpp"
"src/include/omega_edit/version.h" "src/lib/version.c"
"src/include/omega_edit/visit.h" "src/lib/visit.cpp"
"src/include/omega_edit/session.h" "src/lib/session.cpp" "src/lib/impl_/session_def.hpp"
"src/include/omega_edit/viewport.h" "src/lib/viewport.cpp" "src/lib/impl_/viewport_def.hpp"
"src/include/omega_edit/license.h" "src/lib/license.c"
"src/include/omega_edit/utility.h" "src/lib/utility.c"
"src/include/omega_edit/encode.h" "src/lib/encode.c"
"src/include/omega_edit/filesystem.h" "src/lib/filesystem.cpp"
"src/lib/impl_/macros.h" "src/lib/impl_/internal_fwd_defs.hpp"
"src/lib/impl_/internal_fun.hpp" "src/lib/impl_/internal_fun.cpp"
"src/lib/impl_/find.h" "src/lib/impl_/find.cpp"
"src/lib/impl_/data_def.hpp" "src/lib/impl_/model_def.hpp" "src/lib/impl_/model_segment_def.hpp")

# Don't add RPATH so we can manipulate the library search path using the environment at runtime
set(CMAKE_MACOSX_RPATH OFF)
endif ()

# Create the library
# Core library configuration
file(GLOB_RECURSE OMEGA_EDIT_SOURCE_FILES "src/include/*.h" "src/include/*.hpp" "src/lib/*.c" "src/lib/*.cpp")
add_library(omega_edit ${OMEGA_EDIT_SOURCE_FILES})
add_library(omega_edit::omega_edit ALIAS omega_edit)
set_target_properties(omega_edit PROPERTIES VERSION ${omega_edit_VERSION} SOVERSION ${omega_edit_VERSION_MAJOR})
set_target_properties(omega_edit PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
target_include_directories(omega_edit PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/include>")
target_compile_definitions(omega_edit PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:OMEGA_EDIT_STATIC_DEFINE>")
target_link_libraries(omega_edit PRIVATE ${FILESYSTEM_LIB})

## Include the install rules if the user wants them (included by default when top-level)
# Packaging rules
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level)
option(omega_edit_INCLUDE_PACKAGING "Include packaging rules for OmegaEdit" "${is_top_level}")
if (omega_edit_INCLUDE_PACKAGING)
message(STATUS "Including packaging")
add_subdirectory(packaging)
endif ()

# Parse version information
# Version definitions
string(TOUPPER "${PROJECT_NAME}" PREFIX)

# Send version information into libomega_edit through macro definitions
foreach (level MAJOR MINOR PATCH)
target_compile_definitions(omega_edit PRIVATE "${PREFIX}_VERSION_${level}=${${PROJECT_NAME}_VERSION_${level}}")
endforeach ()

#######################################################################################################################
# EXAMPLES
#######################################################################################################################
# Examples
if (BUILD_EXAMPLES)
add_executable(add_bom "src/examples/add_bom.cpp")
target_link_libraries(add_bom PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(count_characters "src/examples/count_characters.c")
target_link_libraries(count_characters PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(detect_bom "src/examples/detect_bom.c")
target_link_libraries(detect_bom PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(replace "src/examples/replace.cpp")
target_link_libraries(replace PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(rotate "src/examples/rotate.cpp")
target_link_libraries(rotate PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(slice "src/examples/slice.cpp")
target_link_libraries(slice PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(peek "src/examples/peek.cpp")
target_link_libraries(peek PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(search "src/examples/search.cpp")
target_link_libraries(search PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(simple "src/examples/simple.cpp")
target_link_libraries(simple PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(simple_c "src/examples/simple_c.c")
target_link_libraries(simple_c PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(replay "src/examples/replay.cpp")
target_link_libraries(replay PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(transform "src/examples/transform.c")
target_link_libraries(transform PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(profile "src/examples/profile.c")
target_link_libraries(profile PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_executable(play "src/examples/play.cpp")
target_link_libraries(play PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})
add_custom_command(TARGET play POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/examples/data" "$<TARGET_FILE_DIR:play>/data/examples" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
file(GLOB_RECURSE EXAMPLES_SRC "src/examples/*.c" "src/examples/*.cpp")
foreach (example_src ${EXAMPLES_SRC})
get_filename_component(example_name ${example_src} NAME_WE)
add_executable(${example_name} ${example_src})
target_link_libraries(${example_name} PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})
endforeach ()
endif ()

#######################################################################################################################
# TESTING
#######################################################################################################################
# Tests
if (BUILD_TESTS)
enable_testing()

if (MSVC)
set(CTEST_CONFIGURATION_TYPE "${JOB_BUILD_CONFIGURATION}")
endif ()

add_executable(omega_test "src/tests/omega_test.cpp" "src/tests/test_util.h")
target_link_libraries(omega_test PRIVATE omega_edit::omega_edit Catch2::Catch2WithMain ${FILESYSTEM_LIB})
add_custom_command(TARGET omega_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/tests/data" "$<TARGET_FILE_DIR:omega_test>/data" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

add_executable(generate_file "src/tests/generate_file.cpp" "src/tests/test_util.h")
target_link_libraries(generate_file PRIVATE omega_edit::omega_edit ${FILESYSTEM_LIB})

add_custom_command(TARGET omega_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/tests/data" "$<TARGET_FILE_DIR:omega_test>/data")
include(CTest)
include(Catch)
catch_discover_tests(omega_test WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

find_program(VALGRIND "valgrind")
if (VALGRIND)
add_custom_target(valgrind
COMMAND ${VALGRIND} --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt $<TARGET_FILE:omega_test>
COMMENT "Running tests under valgrind"
DEPENDS omega_test)
endif()
add_custom_target(valgrind COMMAND ${VALGRIND} --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt $<TARGET_FILE:omega_test> COMMENT "Running tests under valgrind" DEPENDS omega_test)
endif ()
endif ()

#######################################################################################################################
# DOCUMENTATION
#######################################################################################################################
# Documentation
if (BUILD_DOCS)
# Generate API documentation using Doxygen
find_package(Doxygen COMPONENTS dot)
find_package(Doxygen)
if (DOXYGEN_FOUND)
message(STATUS "API documentation generation enabled")
set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_GENERATE_MAN YES)
set(DOXYGEN_GENERATE_XML YES)
set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
set(DOXYGEN_EXTRACT_ALL YES)
set(DOXYGEN_INDEX_DIR "${CMAKE_CURRENT_BINARY_DIR}/docs/xml")
set(DOXYGEN_INDEX_FILE "${DOXYGEN_INDEX_DIR}/index.xml")
set(DOXYGEN_OUTPUT_DIRECTORY docs)
doxygen_add_docs(docs "src/include" ALL COMMENT "Generate doxygen docs")
# Add the cmake folder so the FindSphinx module is found
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
find_package(Sphinx REQUIRED)
set(DOXYGEN_INDEX_DIR "${CMAKE_CURRENT_BINARY_DIR}/docs/xml")
doxygen_add_docs(docs "src/include" ALL)
find_package(Sphinx)
if (SPHINX_FOUND)
# Generate user documentation using Sphinx
message(STATUS "User documentation generation enabled")
set(SPHINX_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/sphinx")
set(SPHINX_BUILD "${CMAKE_CURRENT_BINARY_DIR}/docs/sphinx")
set(SPHINX_INDEX_FILE "${SPHINX_BUILD}/index.html")
add_custom_command(OUTPUT "${SPHINX_INDEX_FILE}"
COMMAND "${SPHINX_EXECUTABLE}"
ARGS -b html
# Tell Breathe where to find the Doxygen output
add_custom_target(
sphinx ALL
COMMAND "${SPHINX_EXECUTABLE}" -b html
-Dbreathe_projects.omega_edit="${DOXYGEN_INDEX_DIR}"
"${SPHINX_SOURCE}" "${SPHINX_BUILD}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS
# Other docs files you want to track should go here (or in some variable)
"${SPHINX_SOURCE}/index.rst"
MAIN_DEPENDENCY "${SPHINX_SOURCE}/conf.py"
COMMENT "Generating documentation with Sphinx")
# Nice named target so we can run the job easily
add_custom_target(sphinx ALL DEPENDS "${SPHINX_INDEX_FILE}")
COMMENT "Generating documentation with Sphinx"
)
add_dependencies(sphinx docs)
include(GNUInstallDirs)
install(DIRECTORY "${SPHINX_BUILD}" DESTINATION "${CMAKE_INSTALL_DOCDIR}")
else (SPHINX_FOUND)
message(STATUS "Sphinx need to be installed to generate user documentation")
endif (SPHINX_FOUND)
else (DOXYGEN_FOUND)
message(STATUS "Doxygen need to be installed to generate API documentation")
endif (DOXYGEN_FOUND)
endif (BUILD_DOCS)
endif ()
endif ()
endif ()
45 changes: 23 additions & 22 deletions core/packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,50 @@
# Unless required by applicable law or agreed to in writing, software is distributed under the License is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing permissions and limitations under the License.
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

include("GNUInstallDirs")
include("CMakePackageConfigHelpers")

if (NOT DEFINED omega_edit_INSTALL_CMAKEDIR)
set(omega_edit_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/omega_edit" CACHE STRING "Path to omega_edit CMake files")
endif ()
set(omega_edit_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/omega_edit" CACHE STRING "Path to omega_edit CMake files")
endif()

install(TARGETS omega_edit EXPORT omega_edit_Targets RUNTIME COMPONENT omega_edit_Runtime LIBRARY COMPONENT omega_edit_Runtime NAMELINK_COMPONENT omega_edit_Development ARCHIVE COMPONENT omega_edit_Development INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(DIRECTORY "${omega_edit_SOURCE_DIR}/src/include/" TYPE INCLUDE COMPONENT omega_edit_Development)

if (BUILD_SHARED_LIBS)
set(type shared)
else ()
set(type static)
endif ()
set(type "shared")
else()
set(type "static")
endif()

install(EXPORT omega_edit_Targets DESTINATION "${omega_edit_INSTALL_CMAKEDIR}" NAMESPACE omega_edit:: FILE "omega_edit-${type}-targets.cmake" COMPONENT omega_edit_Development)
write_basic_package_version_file(omega_editConfigVersion.cmake COMPATIBILITY SameMajorVersion)
install(EXPORT omega_edit_Targets DESTINATION "${omega_edit_INSTALL_CMAKEDIR}" NAMESPACE "omega_edit::" FILE "omega_edit-${type}-targets.cmake" COMPONENT omega_edit_Development)
write_basic_package_version_file("omega_editConfigVersion.cmake" COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/omega_editConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/omega_editConfigVersion.cmake" DESTINATION "${omega_edit_INSTALL_CMAKEDIR}" COMPONENT omega_edit_Development)

# see: https://www.scivision.dev/cmake-cpack-basic/
set(_fmt TGZ)
if(WIN32)
set(_fmt ZIP)
set(_fmt "TGZ")
if (WIN32)
set(_fmt "ZIP")
endif()
set(CPACK_GENERATOR ${_fmt})
set(CPACK_SOURCE_GENERATOR ${_fmt})
set(CPACK_GENERATOR "${_fmt}")
set(CPACK_SOURCE_GENERATOR "${_fmt}")
set(CPACK_PACKAGE_VENDOR "Concurrent Technologies Corporation")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/../LICENSE.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/../README.md")
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/package")
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR})
string(TOLOWER ${CMAKE_SYSTEM_NAME} _sys)
string(TOLOWER ${PROJECT_NAME} _project_lower)
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}")
string(TOLOWER "${CMAKE_SYSTEM_NAME}" _sys)
string(TOLOWER "${PROJECT_NAME}" _project_lower)
set(CPACK_PACKAGE_FILE_NAME "${_project_lower}-${_sys}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${_project_lower}-${PROJECT_VERSION}")

# not .gitignore as its regex syntax is distinct
file(READ ${CMAKE_CURRENT_LIST_DIR}/.cpack_ignore _cpack_ignore)
string(REGEX REPLACE "\n" ";" _cpack_ignore ${_cpack_ignore})
file(READ "${CMAKE_CURRENT_LIST_DIR}/.cpack_ignore" _cpack_ignore)
string(REGEX REPLACE "\n" ";" _cpack_ignore "${_cpack_ignore}")
set(CPACK_SOURCE_IGNORE_FILES "${_cpack_ignore}")

install(FILES ${CPACK_RESOURCE_FILE_README} ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION "${CMAKE_INSTALL_DOCDIR}")
install(FILES "${CPACK_RESOURCE_FILE_README}" "${CPACK_RESOURCE_FILE_LICENSE}" DESTINATION "${CMAKE_INSTALL_DOCDIR}")

include(CPack)
include("CPack")
7 changes: 4 additions & 3 deletions core/packaging/omega_editConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Unless required by applicable law or agreed to in writing, software is distributed under the License is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing permissions and limitations under the License.

cmake_minimum_required(VERSION 3.13)

set(omega_edit_known_comps static shared)
Expand All @@ -18,15 +19,15 @@ foreach (omega_edit_comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
set(omega_edit_comp_${omega_edit_comp} YES)
else ()
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"omega_edit does not recognize component `${omega_edit_comp}`.")
"omega_edit does not recognize component `${omega_edit_comp}`.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return()
endif ()
endforeach ()

if (omega_edit_comp_static AND omega_edit_comp_shared)
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"omega_edit `static` and `shared` components are mutually exclusive.")
"omega_edit `static` and `shared` components are mutually exclusive.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return()
endif ()
Expand All @@ -37,7 +38,7 @@ set(omega_edit_shared_targets "${CMAKE_CURRENT_LIST_DIR}/omega_edit-shared-targe
macro(omega_edit_load_targets type)
if (NOT EXISTS "${omega_edit_${type}_targets}")
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"omega_edit `${type}` libraries were requested but not found.")
"omega_edit `${type}` libraries were requested but not found.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return()
endif ()
Expand Down
Binary file added core/sphinx/_static/OmegaEditLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e6eb5a5

Please sign in to comment.