LibvtermCMakeLists.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. cmake_minimum_required(VERSION 2.8.12)
  2. project(libvterm LANGUAGES C)
  3. include(GNUInstallDirs)
  4. find_package(Perl)
  5. if(MSVC)
  6. add_compile_options(/W3)
  7. add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
  8. else()
  9. add_compile_options(-Wall -std=c99)
  10. endif()
  11. # Generate includes from tables
  12. file(GLOB TBL_FILES ${CMAKE_SOURCE_DIR}/src/encoding/*.tbl)
  13. set(TBL_FILES_HEADERS)
  14. foreach(file ${TBL_FILES})
  15. get_filename_component(basename ${file} NAME_WE)
  16. set(tname encoding/${basename}.inc)
  17. add_custom_command(OUTPUT
  18. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/encoding/
  19. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/tbl2inc_c.cmake ${file} ${CMAKE_BINARY_DIR}/${tname}
  20. COMMENT "Generating ${tname}"
  21. OUTPUT ${CMAKE_BINARY_DIR}/${tname}
  22. )
  23. list(APPEND TBL_FILES_HEADERS ${tname})
  24. # Only used for verifying that the output of tbl2inc_c.cmake is correct
  25. set(tname encoding-test/${basename}.inc)
  26. add_custom_command(OUTPUT
  27. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/encoding-test/
  28. COMMAND ${PERL_EXECUTABLE} -CSD ${CMAKE_SOURCE_DIR}/tbl2inc_c.pl ${file} > ${CMAKE_BINARY_DIR}/${tname}
  29. COMMENT "Generating ${tname}"
  30. OUTPUT ${CMAKE_BINARY_DIR}/${tname}
  31. )
  32. endforeach()
  33. include_directories(${CMAKE_SOURCE_DIR}/include)
  34. include_directories(${CMAKE_BINARY_DIR})
  35. file(GLOB VTERM_SOURCES ${CMAKE_SOURCE_DIR}/src/*.c)
  36. add_library(vterm ${VTERM_SOURCES} ${TBL_FILES_HEADERS})
  37. install(TARGETS vterm ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  38. add_library(vterm-shared SHARED ${VTERM_SOURCES} ${TBL_FILES_HEADERS})
  39. set_target_properties(vterm-shared PROPERTIES
  40. OUTPUT_NAME vterm
  41. SOVERSION 0)
  42. install(TARGETS vterm-shared
  43. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  44. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  45. install(FILES include/vterm.h include/vterm_keycodes.h
  46. DESTINATION include)
  47. if(NOT WIN32)
  48. file(GLOB BIN_SOURCES ${CMAKE_SOURCE_DIR}/bin/*.c)
  49. foreach(EXE_C ${BIN_SOURCES})
  50. get_filename_component(target_name ${EXE_C} NAME_WE)
  51. add_executable(${target_name} ${EXE_C})
  52. target_link_libraries(${target_name} vterm)
  53. install(TARGETS ${target_name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  54. endforeach()
  55. endif()
  56. # Tests
  57. add_executable(harness EXCLUDE_FROM_ALL t/harness.c)
  58. target_link_libraries(harness vterm)
  59. set_target_properties(harness PROPERTIES
  60. # run-test.pl expects to find the harness in t/.libs/
  61. RUNTIME_OUTPUT_DIRECTORY t/.libs)
  62. if(Perl_FOUND)
  63. file(GLOB TESTFILES ${CMAKE_SOURCE_DIR}/t/*.test)
  64. add_custom_target(check)
  65. foreach(testfile ${TESTFILES})
  66. get_filename_component(target_name ${testfile} NAME_WE)
  67. add_custom_target(${target_name}
  68. COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/t/run-test.pl ${testfile}
  69. COMMENT "**${target_name} **"
  70. DEPENDS harness)
  71. add_dependencies(check ${target_name})
  72. endforeach()
  73. foreach(header_path ${TBL_FILES_HEADERS})
  74. get_filename_component(header_name ${header_path} NAME)
  75. set(perl_header_path ${CMAKE_BINARY_DIR}/encoding-test/${header_name})
  76. add_custom_target(test-${header_name}
  77. COMMAND ${CMAKE_COMMAND} -E compare_files
  78. ${header_path} ${perl_header_path}
  79. DEPENDS ${header_path} ${perl_header_path})
  80. endforeach()
  81. endif()