-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
67 lines (60 loc) · 2.4 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright 2022-2024 Mitchell. See LICENSE.
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED true)
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET 11 CACHE STRING "")
endif()
set(src ${CMAKE_SOURCE_DIR})
# Dependencies.
include(FetchContent)
set(FETCHCONTENT_QUIET OFF)
set(diff_match_patch_zip 7f95b37e554453262e2bcda830724fc362614103.zip)
FetchContent_Declare(diff_match_patch
URL https://github.com/leutloff/diff-match-patch-cpp-stl/archive/${diff_match_patch_zip})
FetchContent_MakeAvailable(diff_match_patch)
set(lua_tgz lua-5.4.4.tar.gz)
set(lua_url file://${CMAKE_BINARY_DIR}/_deps/${lua_tgz})
if(NOT EXISTS ${CMAKE_BINARY_DIR}/_deps/${lua_tgz})
set(lua_url https://www.lua.org/ftp/${lua_tgz})
endif()
FetchContent_Declare(lua URL ${lua_url})
FetchContent_MakeAvailable(lua)
# Build.
project(diff LANGUAGES CXX C)
if(WIN32)
# On Windows, DLLs cannot do dynamic lookup. They need symbols to link to at build time.
# Rather than fetching a Textadept build and creating separate DLLs linked to textadept.lib and
# textadept-curses.lib, just embed a minimal copy of Lua in a single DLL.
file(GLOB lua_src ${lua_SOURCE_DIR}/src/*.c)
list(FILTER lua_src EXCLUDE REGEX "(lua|luac|[^x]lib|linit)\.c$") # of *lib.c, keep only lauxlib.c
endif()
add_library(diff SHARED diff.cxx ${lua_src})
target_include_directories(diff PRIVATE ${diff_match_patch_SOURCE_DIR} ${lua_SOURCE_DIR}/src)
if(WIN32)
target_compile_definitions(diff PRIVATE LUA_BUILD_AS_DLL LUA_LIB)
elseif(APPLE)
target_link_options(diff PRIVATE -undefined dynamic_lookup)
endif()
# Install.
install(TARGETS diff DESTINATION ${src})
if(NOT (WIN32 OR APPLE))
install(CODE "file(RENAME ${src}/libdiff.so ${src}/diff.so)")
elseif(APPLE)
install(CODE "file(RENAME ${src}/libdiff.dylib ${src}/diffosx.so)")
endif()
if(NOT (WIN32 OR APPLE))
include(GNUInstallDirs)
set(module_dir ${CMAKE_INSTALL_FULL_DATADIR}/textadept/modules/file_diff)
install(CODE "file(MAKE_DIRECTORY ${module_dir})")
install(FILES init.lua diff.so DESTINATION ${module_dir})
endif()
# Documentation.
get_filename_component(ta_dir ${src}/../../ ABSOLUTE)
add_custom_target(docs DEPENDS README.md)
add_custom_command(OUTPUT ${src}/README.md
COMMAND ldoc --filter markdowndoc.ldoc ${src}/init.lua > ${src}/README.md
COMMAND sed -i -e "1,+4d" -e "6c# File Diff" -e "7d" -e "s/^##/#/;" ${src}/README.md
DEPENDS init.lua
WORKING_DIRECTORY ${ta_dir}/scripts
VERBATIM)