Skip to content

Commit

Permalink
Add cmake support
Browse files Browse the repository at this point in the history
Adds modern CMake support, allowing SheenBidi to be used as a subproject
from a CMake project (e.g. via `FetchContent`).
  • Loading branch information
glebm committed Nov 6, 2024
1 parent ff3738a commit bfb659a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
89 changes: 89 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
cmake_minimum_required(VERSION 3.16)

project(sheenbidi VERSION 2.8 LANGUAGES C CXX)

option(ENABLE_INSTALL "Enable install targets" ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # for clang-tidy
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)

set(_public_headers
Headers/SBAlgorithm.h
Headers/SBBase.h
Headers/SBBidiType.h
Headers/SBCodepoint.h
Headers/SBCodepointSequence.h
Headers/SBGeneralCategory.h
Headers/SBLine.h
Headers/SBMirrorLocator.h
Headers/SBParagraph.h
Headers/SBRun.h
Headers/SBScript.h
Headers/SBScriptLocator.h
Headers/SheenBidi.h
)
add_library(
sheenbidi
Source/SheenBidi.c
)
target_include_directories(sheenbidi PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Headers>
$<INSTALL_INTERFACE:include/SheenBidi>
)
target_include_directories(sheenbidi PRIVATE Source)
set_target_properties(sheenbidi PROPERTIES PUBLIC_HEADER "${_public_headers}")
target_compile_definitions(sheenbidi PRIVATE SB_CONFIG_UNITY)
add_library(SheenBidi::sheenbidi ALIAS sheenbidi)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_link_libraries(sheenbidi PUBLIC "-static-libgcc -static-libstdc++")
endif()

if(ENABLE_INSTALL)
install(
TARGETS sheenbidi
EXPORT SheenBidiTargets
PUBLIC_HEADER
CONFIGURATIONS Release
DESTINATION include/SheenBidi
)

if(NOT DEFINED LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR lib)
endif()
set(ConfigPackageLocation "${LIB_INSTALL_DIR}/cmake/SheenBidi")

include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/SheenBidi.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/SheenBidi/SheenBidiConfig.cmake"
INSTALL_DESTINATION ${ConfigPackageLocation})
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/SheenBidi/SheenBidiConfigVersion.cmake"
VERSION ${SheenBidi_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(EXPORT SheenBidiTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/SheenBidi/SheenBidiTargets.cmake"
NAMESPACE SheenBidi::
)

install(EXPORT SheenBidiTargets
FILE
SheenBidiTargets.cmake
NAMESPACE
SheenBidi::
DESTINATION
${ConfigPackageLocation}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/SheenBidi/SheenBidiConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/SheenBidi/SheenBidiConfigVersion.cmake"
DESTINATION
${ConfigPackageLocation}
)
endif()
5 changes: 5 additions & 0 deletions cmake/SheenBidi.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

check_required_components(SheenBidi)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

0 comments on commit bfb659a

Please sign in to comment.