CMakeLists.txt (3052B)
1 cmake_minimum_required(VERSION 3.11) 2 include(ExternalProject) 3 4 project(emacs-libvterm C) 5 6 if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD") 7 set(LIBVTERM_BUILD_COMMAND "gmake") 8 else() 9 set(LIBVTERM_BUILD_COMMAND "make") 10 endif() 11 12 add_library(vterm-module MODULE vterm-module.c utf8.c elisp.c) 13 set_target_properties(vterm-module PROPERTIES 14 C_STANDARD 99 15 C_VISIBILITY_PRESET "hidden" 16 POSITION_INDEPENDENT_CODE ON 17 PREFIX "" 18 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR} 19 ) 20 21 # Set RelWithDebInfo as default build type 22 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 23 message(STATUS "No build type selected, defaulting to RelWithDebInfo") 24 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type (default RelWithDebInfo)" FORCE) 25 endif() 26 27 # Look for the header file. 28 option(USE_SYSTEM_LIBVTERM "Use system libvterm instead of the vendored version." ON) 29 30 # Try to find the libvterm in system. 31 if (USE_SYSTEM_LIBVTERM) 32 # try to find the vterm.h header file. 33 find_path(LIBVTERM_INCLUDE_DIR 34 NAMES vterm.h 35 ) 36 37 # vterm.h is found. 38 if (LIBVTERM_INCLUDE_DIR) 39 message(STATUS "System libvterm detected") 40 execute_process(COMMAND grep -c "VTermStringFragment" "${LIBVTERM_INCLUDE_DIR}/vterm.h" OUTPUT_VARIABLE VTermStringFragmentExists) 41 if (${VTermStringFragmentExists} EQUAL "0") 42 # add_compile_definitions(VTermStringFragmentNotExists) 43 add_definitions(-DVTermStringFragmentNotExists) 44 endif() 45 else() 46 message(STATUS "System libvterm not found: libvterm will be downloaded and compiled as part of the build process") 47 endif() 48 endif() 49 50 if (LIBVTERM_INCLUDE_DIR) 51 find_library(LIBVTERM_LIBRARY NAMES 52 vterm 53 libvterm 54 ) 55 56 if(NOT LIBVTERM_LIBRARY) 57 message(FATAL_ERROR "libvterm not found") 58 endif() 59 else() 60 find_program(LIBTOOL NAMES libtool glibtool) 61 if(NOT LIBTOOL) 62 message(FATAL_ERROR "libtool not found. Please install libtool") 63 endif() 64 65 ExternalProject_add(libvterm 66 GIT_REPOSITORY https://github.com/neovim/libvterm.git 67 GIT_TAG 54c03b21f763fa775a4c0643a9d8326342873179 68 CONFIGURE_COMMAND "" 69 BUILD_COMMAND ${LIBVTERM_BUILD_COMMAND} "CFLAGS='-fPIC'" 70 BUILD_IN_SOURCE ON 71 INSTALL_COMMAND "") 72 73 ExternalProject_Get_property(libvterm SOURCE_DIR) 74 75 set(LIBVTERM_INCLUDE_DIR ${SOURCE_DIR}/include) 76 set(LIBVTERM_LIBRARY ${SOURCE_DIR}/.libs/libvterm.a) 77 78 add_dependencies(vterm-module libvterm) 79 80 # Workaround for https://gitlab.kitware.com/cmake/cmake/issues/15052 81 file(MAKE_DIRECTORY ${LIBVTERM_INCLUDE_DIR}) 82 endif() 83 84 add_library(vterm STATIC IMPORTED) 85 set_target_properties(vterm PROPERTIES IMPORTED_LOCATION ${LIBVTERM_LIBRARY}) 86 target_include_directories(vterm INTERFACE ${LIBVTERM_INCLUDE_DIR}) 87 88 # Link with libvterm 89 target_link_libraries(vterm-module PUBLIC vterm) 90 91 # Custom run command for testing 92 add_custom_target(run 93 COMMAND emacs -Q -L ${CMAKE_SOURCE_DIR} -L ${CMAKE_BINARY_DIR} --eval "\\(require \\'vterm\\)" --eval "\\(vterm\\)" 94 DEPENDS vterm-module 95 )