CMakeLists.txt (3602B)
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 execute_process(COMMAND grep -c "VTermSelectionMask" "${LIBVTERM_INCLUDE_DIR}/vterm.h" OUTPUT_VARIABLE VTermSelectionMaskExists) 46 if (${VTermSelectionMaskExists} EQUAL "0") 47 # add_compile_definitions(VTermStringFragmentNotExists) 48 add_definitions(-DVTermSelectionMaskNotExists) 49 endif() 50 execute_process(COMMAND grep -c "sb_clear" "${LIBVTERM_INCLUDE_DIR}/vterm.h" OUTPUT_VARIABLE VTermSBClearExists) 51 if (${VTermSBClearExists} EQUAL "0") 52 add_definitions(-DVTermSBClearNotExists) 53 endif() 54 else() 55 message(STATUS "System libvterm not found: libvterm will be downloaded and compiled as part of the build process") 56 endif() 57 endif() 58 59 if (LIBVTERM_INCLUDE_DIR) 60 find_library(LIBVTERM_LIBRARY NAMES 61 vterm 62 libvterm 63 ) 64 65 if(NOT LIBVTERM_LIBRARY) 66 message(FATAL_ERROR "libvterm not found") 67 endif() 68 else() 69 find_program(LIBTOOL NAMES libtool glibtool) 70 if(NOT LIBTOOL) 71 message(FATAL_ERROR "libtool not found. Please install libtool") 72 endif() 73 74 ExternalProject_add(libvterm 75 GIT_REPOSITORY https://github.com/Sbozzolo/libvterm-mirror.git 76 GIT_TAG 64f1775952dbe001e989f2ab679563b54f2fca55 77 CONFIGURE_COMMAND "" 78 BUILD_COMMAND ${LIBVTERM_BUILD_COMMAND} "CFLAGS='-fPIC'" "LDFLAGS='-static'" 79 BUILD_IN_SOURCE ON 80 INSTALL_COMMAND "") 81 82 ExternalProject_Get_property(libvterm SOURCE_DIR) 83 84 set(LIBVTERM_INCLUDE_DIR ${SOURCE_DIR}/include) 85 set(LIBVTERM_LIBRARY ${SOURCE_DIR}/.libs/libvterm.a) 86 87 add_dependencies(vterm-module libvterm) 88 89 # Workaround for https://gitlab.kitware.com/cmake/cmake/issues/15052 90 file(MAKE_DIRECTORY ${LIBVTERM_INCLUDE_DIR}) 91 endif() 92 93 add_library(vterm STATIC IMPORTED) 94 set_target_properties(vterm PROPERTIES IMPORTED_LOCATION ${LIBVTERM_LIBRARY}) 95 target_include_directories(vterm INTERFACE ${LIBVTERM_INCLUDE_DIR}) 96 97 # Link with libvterm 98 target_link_libraries(vterm-module PUBLIC vterm) 99 100 # Custom run command for testing 101 add_custom_target(run 102 COMMAND emacs -Q -L ${CMAKE_SOURCE_DIR} -L ${CMAKE_BINARY_DIR} --eval "\\(require \\'vterm\\)" --eval "\\(vterm\\)" 103 DEPENDS vterm-module 104 )