release 0.1.13
[liba.git] / lua / CMakeLists.txt
blobc4e5da929085115811ad8ea1717e005f3729a69c
1 set(OBJECTS $<TARGET_OBJECTS:a>)
3 if(LIBA_WITH_LUA)
4   include(${CMAKE_CURRENT_LIST_DIR}/lua.cmake)
5   add_subdirectory(${LUA_SOURCE_DIR} ${LUA_BINARY_DIR})
6   option(LUA_ISOCLINE "Enable/Disable isocline in Lua" 1)
8   if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/isocline/src/isocline.c AND LUA_ISOCLINE)
9     file(RELATIVE_PATH LUA_READLINE_C ${LUA_SOURCE_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/isocline.c)
10     target_compile_definitions(lua PRIVATE LUA_READLINE_C="${LUA_READLINE_C}")
11   endif()
13   set(LUA_LIBRARIES lualib)
14   set(LUA_EXECUTABLE ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:lua>)
15   string(REGEX MATCHALL "[0-9]+" VERSION "${LUA_VERSION}.0.0")
16   list(GET VERSION 0 LUA_VERSION_MAJOR)
17   list(GET VERSION 1 LUA_VERSION_MINOR)
19   if(LIBA_SANITIZE)
20     target_compile_sanitize(PUBLIC liblua lualib lua.o)
21     target_link_sanitize(PUBLIC liblua lualib lua luac)
22     set(OBJECTS $<TARGET_OBJECTS:asan>)
23   endif()
24 endif()
26 if(LIBA_CXX)
27   file_scaner(SOURCES RECURSE src EXT c h cc hh cpp hpp)
28 else()
29   file_scaner(SOURCES RECURSE src EXT c h)
30 endif()
32 set(CMAKE_SHARED_MODULE_PREFIX "")
33 add_library(alua MODULE ${OBJECTS} ${SOURCES})
34 set_target_properties(alua PROPERTIES DEFINE_SYMBOL A_EXPORTS OUTPUT_NAME ${PROJECT_NAME})
35 target_link_libraries(alua PRIVATE ${LUA_LIBRARIES})
36 add_library_properties(alua PRIVATE alib)
37 set_library_options(alua)
39 if("${LIBA_INSTALL}" MATCHES "^[Ll]ua$")
40   install(TARGETS alua
41     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
42     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
43     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
44   )
45 else()
46   install(TARGETS alua
47     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
48     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
49     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
50   )
51 endif()
53 if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
54   file(GLOB_RECURSE SOURCES test/*.lua)
56   function(find_format)
57     find_package(StyLua)
59     if(STYLUA_FOUND)
60       add_stylua(afmt.lua VERBOSE ${ARGN})
61       add_dependencies(afmt afmt.lua)
62       return()
63     endif()
65     find_package(LuaFormat)
67     if(LUA_FORMAT_FOUND)
68       add_lua_format(afmt.lua VERBOSE ${ARGN})
69       add_dependencies(afmt afmt.lua)
70       return()
71     endif()
72   endfunction()
74   find_format(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ${SOURCES})
75 endif()
77 option(LIBA_LDOC "Enable/Disable ffi ldoc" 0)
79 if(LIBA_LDOC)
80   find_package(LDoc)
81 endif()
83 if(LIBA_LDOC AND LDOC_FOUND)
84   file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LDoc
85     CONTENT "project = '${PROJECT_NAME}'
86 description = '${PROJECT_DESCRIPTION}'
87 format = 'markdown'
89   create_ldoc(adoc.lua CONFIG ${CMAKE_CURRENT_BINARY_DIR}/LDoc
90     OPTIONS --not_luadoc ${CMAKE_CURRENT_SOURCE_DIR}/src
91   )
92   add_dependencies(adoc adoc.lua)
93 endif()
95 if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/test/CMakeLists.txt AND LUA_EXECUTABLE)
96   get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
98   if(NOT CMAKE_VERSION VERSION_LESS 3.0)
99     set(WORKING_DIRECTORY $<TARGET_FILE_DIR:alua>)
100   elseif(IS_MULTI_CONFIG)
101     set(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
102   else()
103     set(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
104   endif()
106   add_subdirectory(test)
107 endif()