aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 21d855155c1316237399691eeefb1e6c15a66a0d (plain)
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
68
69
cmake_minimum_required(VERSION 3.0.2)

include(ExternalProject)

project(emacs-libvterm C)

add_library(vterm-module SHARED vterm-module.c utf8.c elisp.c)
set_property(TARGET vterm-module PROPERTY POSITION_INDEPENDENT_CODE ON)
set_target_properties(vterm-module PROPERTIES PREFIX "")
set_target_properties(vterm-module PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})

# Link with libvterm
target_link_libraries(vterm-module vterm)

# Link with libutil
target_link_libraries(vterm-module util)

# Link with pthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(vterm-module Threads::Threads)

# We need the right emacs-module header
set(EMACS_SOURCE "" CACHE PATH "Path to emacs source.")

if (NOT EMACS_SOURCE)
  execute_process(COMMAND emacs --batch --eval "(message \"%s.%s\" emacs-major-version emacs-minor-version)"
    ERROR_VARIABLE EMACS_VERSION
    RESULT_VARIABLE RESULT
    ERROR_STRIP_TRAILING_WHITESPACE)
  if (NOT ${RESULT} EQUAL 0)
    message(WARNING "Could not detect emacs version. Building module for emacs version 25.3.")
    set(EMACS_VERSION 25.3)
  endif()

  if (${EMACS_VERSION} VERSION_LESS 25)
    message(FATAL_ERROR "Modules are only supported since emacs version 25.")
  endif()

  if (${EMACS_VERSION} VERSION_LESS 26)
    ExternalProject_Add(emacs
      URL               "https://ftpmirror.gnu.org/gnu/emacs/emacs-${EMACS_VERSION}.tar.gz"
      CONFIGURE_COMMAND ""
      BUILD_COMMAND     ""
      INSTALL_COMMAND   ""
      )
  else()
    ExternalProject_Add(emacs
      GIT_REPOSITORY    "git://git.sv.gnu.org/emacs.git"
      CONFIGURE_COMMAND "./autogen.sh" COMMAND "./configure"
      BUILD_COMMAND     ""
      BUILD_IN_SOURCE   "YES"
      INSTALL_COMMAND   ""
      )
  endif()
  add_dependencies(vterm-module emacs)

  ExternalProject_Get_Property(emacs SOURCE_DIR)
  include_directories(${SOURCE_DIR}/src)
else ()
  include_directories(${EMACS_SOURCE}/src)
endif()

# Custom run command for testing
add_custom_target(run
  COMMAND emacs -Q -L ${CMAKE_SOURCE_DIR} --eval "\\(require \\'vterm\\)"
  DEPENDS vterm-module
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  )