Support highlight for string
[liba.git] / lua / CMakeLists.txt
blob8b5a378eed77c50a76d773a9c23ebe7743bdb0fa
1 set(OBJECTS $<TARGET_OBJECTS:a>)
3 if(WIN32)
4   set(CMAKE_SHARED_MODULE_PREFIX lib)
5 endif()
7 if(LIBA_WITH_LUA)
8   include(${CMAKE_CURRENT_LIST_DIR}/lua.cmake)
9   option(LUA_ISOCLINE "Enable/Disable isocline in Lua" 1)
11   if(LUA_ISOCLINE)
12     file(RELATIVE_PATH LUA_READLINE_C ${LUA_ARCHIVE_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/isocline.c)
13     target_compile_definitions(lua PRIVATE LUA_READLINE_C="${LUA_READLINE_C}")
14   endif()
16   set(LUA_LIBRARIES lualib)
17   set(LUA_EXECUTABLE ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:lua>)
18   string(REGEX REPLACE "^([0-9]).*" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION}")
19   string(REGEX REPLACE "^[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_MINOR "${LUA_VERSION}")
21   if(LIBA_SANITIZE)
22     target_compile_sanitize(PUBLIC liblua lualib lua.o)
23     target_link_sanitize(PUBLIC liblua lualib)
24     set(OBJECTS $<TARGET_OBJECTS:asan>)
25   endif()
26 endif()
28 if(LIBA_CXX)
29   file_scaner(SOURCES RECURSE src EXT c h cc hh cpp hpp)
30 else()
31   file_scaner(SOURCES RECURSE src EXT c h)
32 endif()
34 add_library(alua MODULE ${OBJECTS} ${SOURCES})
35 set_target_properties(alua PROPERTIES DEFINE_SYMBOL A_EXPORTS OUTPUT_NAME a)
36 target_link_libraries(alua PRIVATE ${LUA_LIBRARIES})
37 add_library_properties(alua PRIVATE alib)
38 set_library_options(alua)
40 if(LIBA_INSTALL MATCHES "[Ll]ua")
41   install(TARGETS alua
42     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
43     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
44     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
45   )
46 else()
47   install(TARGETS alua
48     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
49     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
50     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
51   )
52 endif()
54 if(PROJECT_IS_TOP_LEVEL)
55   file(GLOB_RECURSE SOURCES test/*.lua)
57   function(find_format)
58     find_package(StyLua)
60     if(STYLUA_FOUND)
61       add_stylua(astylua VERBOSE ${ARGN})
62       add_dependencies(afmt astylua)
63       return()
64     endif()
66     find_package(LuaFormat)
68     if(LUA_FORMAT_FOUND)
69       add_lua_format(aluaformat VERBOSE ${ARGN})
70       add_dependencies(afmt aluaformat)
71       return()
72     endif()
73   endfunction()
75   find_format(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ${SOURCES})
76 endif()
78 option(LIBA_LDOC "Enable/Disable ffi ldoc" 0)
80 if(LIBA_LDOC)
81   find_package(LDoc)
82 endif()
84 if(LIBA_LDOC AND LDOC_FOUND)
85   file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LDoc
86     CONTENT "project = '${PROJECT_NAME}'
87 description = '${PROJECT_DESCRIPTION}'
88 format = 'markdown'
90   create_ldoc(aldoc CONFIG ${CMAKE_CURRENT_BINARY_DIR}/LDoc
91     OPTIONS --not_luadoc ${CMAKE_CURRENT_SOURCE_DIR}/src
92   )
93   add_dependencies(adoc aldoc)
94 endif()
96 if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/test/CMakeLists.txt AND LUA_EXECUTABLE)
97   get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
99   if(NOT CMAKE_VERSION VERSION_LESS 3.0)
100     set(WORKING_DIRECTORY $<TARGET_FILE_DIR:alua>)
101   elseif(IS_MULTI_CONFIG)
102     set(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
103   else()
104     set(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
105   endif()
107   add_subdirectory(test)
108 endif()