mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-12 13:00:38 +00:00
Add cmake installation target
This commit is contained in:
parent
8cc289fae4
commit
ec90c86e54
3 changed files with 138 additions and 9 deletions
115
CMakeLists.txt
115
CMakeLists.txt
|
@ -4,7 +4,7 @@ if(EXT_PLATFORM_STRING)
|
|||
return()
|
||||
endif()
|
||||
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
option(LUAU_BUILD_CLI "Build CLI" ON)
|
||||
option(LUAU_BUILD_TESTS "Build tests" ON)
|
||||
|
@ -22,6 +22,19 @@ if(LUAU_STATIC_CRT)
|
|||
endif()
|
||||
|
||||
project(Luau LANGUAGES CXX C)
|
||||
|
||||
find_package(Git QUIET)
|
||||
if(GIT_FOUND)
|
||||
# Get the version from the latest git tag
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
|
||||
OUTPUT_VARIABLE GIT_VERSION
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
set(PROJECT_VERSION "${GIT_VERSION}")
|
||||
endif()
|
||||
|
||||
add_library(Luau.Common INTERFACE)
|
||||
add_library(Luau.CLI.lib STATIC)
|
||||
add_library(Luau.Ast STATIC)
|
||||
|
@ -48,61 +61,135 @@ if(LUAU_BUILD_CLI)
|
|||
set_target_properties(Luau.Reduce.CLI PROPERTIES OUTPUT_NAME luau-reduce)
|
||||
set_target_properties(Luau.Compile.CLI PROPERTIES OUTPUT_NAME luau-compile)
|
||||
set_target_properties(Luau.Bytecode.CLI PROPERTIES OUTPUT_NAME luau-bytecode)
|
||||
|
||||
install(TARGETS Luau.Repl.CLI)
|
||||
install(TARGETS Luau.Analyze.CLI)
|
||||
install(TARGETS Luau.Ast.CLI)
|
||||
install(TARGETS Luau.Reduce.CLI)
|
||||
install(TARGETS Luau.Compile.CLI)
|
||||
install(TARGETS Luau.Bytecode.CLI)
|
||||
endif()
|
||||
|
||||
if(LUAU_BUILD_TESTS)
|
||||
add_executable(Luau.UnitTest)
|
||||
add_executable(Luau.Conformance)
|
||||
add_executable(Luau.CLI.Test)
|
||||
|
||||
# The unit tests aren't `install`ed
|
||||
endif()
|
||||
|
||||
if(LUAU_BUILD_WEB)
|
||||
add_executable(Luau.Web)
|
||||
|
||||
# The web module isn't `install`ed - emscripten builds usually have custom
|
||||
# packaging steps
|
||||
endif()
|
||||
|
||||
# Proxy target to make it possible to depend on private VM headers
|
||||
add_library(Luau.VM.Internals INTERFACE)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(Sources.cmake)
|
||||
|
||||
target_include_directories(Luau.Common INTERFACE Common/include)
|
||||
target_include_directories(Luau.Common INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Common/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
install(TARGETS Luau.Common EXPORT LuauTargets)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Common/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
|
||||
target_compile_features(Luau.CLI.lib PUBLIC cxx_std_17)
|
||||
target_link_libraries(Luau.CLI.lib PRIVATE Luau.Common)
|
||||
install(TARGETS Luau.CLI.lib EXPORT LuauTargets)
|
||||
|
||||
target_compile_features(Luau.Ast PUBLIC cxx_std_17)
|
||||
target_include_directories(Luau.Ast PUBLIC Ast/include)
|
||||
target_include_directories(Luau.Ast PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Ast/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(Luau.Ast PUBLIC Luau.Common Luau.CLI.lib)
|
||||
install(TARGETS Luau.Ast EXPORT LuauTargets)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Ast/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
|
||||
target_compile_features(Luau.Compiler PUBLIC cxx_std_17)
|
||||
target_include_directories(Luau.Compiler PUBLIC Compiler/include)
|
||||
target_include_directories(Luau.Compiler PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Compiler/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(Luau.Compiler PUBLIC Luau.Ast)
|
||||
install(TARGETS Luau.Compiler EXPORT LuauTargets)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Compiler/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
|
||||
target_compile_features(Luau.Config PUBLIC cxx_std_17)
|
||||
target_include_directories(Luau.Config PUBLIC Config/include)
|
||||
target_include_directories(Luau.Config PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Config/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(Luau.Config PUBLIC Luau.Ast)
|
||||
install(TARGETS Luau.Config EXPORT LuauTargets)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Config/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
|
||||
target_compile_features(Luau.Analysis PUBLIC cxx_std_17)
|
||||
target_include_directories(Luau.Analysis PUBLIC Analysis/include)
|
||||
target_include_directories(Luau.Analysis PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Analysis/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(Luau.Analysis PUBLIC Luau.Ast Luau.EqSat Luau.Config)
|
||||
target_link_libraries(Luau.Analysis PRIVATE Luau.Compiler Luau.VM)
|
||||
install(TARGETS Luau.Analysis EXPORT LuauTargets)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Analysis/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
|
||||
target_compile_features(Luau.EqSat PUBLIC cxx_std_17)
|
||||
target_include_directories(Luau.EqSat PUBLIC EqSat/include)
|
||||
target_link_libraries(Luau.EqSat PUBLIC Luau.Common)
|
||||
|
||||
target_compile_features(Luau.CodeGen PRIVATE cxx_std_17)
|
||||
target_include_directories(Luau.CodeGen PUBLIC CodeGen/include)
|
||||
target_include_directories(Luau.CodeGen PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/CodeGen/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(Luau.CodeGen PRIVATE Luau.VM Luau.VM.Internals) # Code generation needs VM internals
|
||||
target_link_libraries(Luau.CodeGen PUBLIC Luau.Common)
|
||||
install(TARGETS Luau.CodeGen EXPORT LuauTargets)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/CodeGen/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
|
||||
target_compile_features(Luau.VM PRIVATE cxx_std_11)
|
||||
target_include_directories(Luau.VM PUBLIC VM/include)
|
||||
target_include_directories(Luau.VM PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/VM/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(Luau.VM PUBLIC Luau.Common)
|
||||
install(TARGETS Luau.VM EXPORT LuauTargets)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/VM/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
|
||||
target_include_directories(isocline PUBLIC extern/isocline/include)
|
||||
|
||||
target_include_directories(Luau.VM.Internals INTERFACE VM/src)
|
||||
target_include_directories(Luau.VM.Internals INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/VM/src>
|
||||
# no INSTALL_INTERFACE: the `Internals` target really only exists at compile-time
|
||||
)
|
||||
install(TARGETS Luau.VM.Internals EXPORT LuauTargets)
|
||||
|
||||
set(LUAU_OPTIONS)
|
||||
|
||||
|
@ -287,3 +374,13 @@ foreach(LIB Luau.Ast Luau.Compiler Luau.Config Luau.Analysis Luau.EqSat Luau.Cod
|
|||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Installation target
|
||||
include(scripts/JoinPaths.cmake)
|
||||
join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
|
||||
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
|
||||
file(RELATIVE_PATH in_file ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/luau.pc.in)
|
||||
string(REPLACE ".in" "" pc_file ${in_file})
|
||||
configure_file(${in_file} ${CMAKE_CURRENT_BINARY_DIR}/${pc_file} @ONLY)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pc_file} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
|
|
23
scripts/JoinPaths.cmake
Normal file
23
scripts/JoinPaths.cmake
Normal file
|
@ -0,0 +1,23 @@
|
|||
# This module provides function for joining paths
|
||||
# known from most languages
|
||||
#
|
||||
# SPDX-License-Identifier: (MIT OR CC0-1.0)
|
||||
# Copyright 2020 Jan Tojnar
|
||||
# https://github.com/jtojnar/cmake-snips
|
||||
#
|
||||
# Modelled after Python’s os.path.join
|
||||
# https://docs.python.org/3.7/library/os.path.html#os.path.join
|
||||
function(join_paths joined_path first_path_segment)
|
||||
set(temp_path "${first_path_segment}")
|
||||
foreach(current_segment IN LISTS ARGN)
|
||||
if(NOT ("${current_segment}" STREQUAL ""))
|
||||
if(IS_ABSOLUTE "${current_segment}")
|
||||
set(temp_path "${current_segment}")
|
||||
else()
|
||||
set(temp_path "${temp_path}/${current_segment}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
file(TO_NATIVE_PATH "${temp_path}" temp_path)
|
||||
set(${joined_path} "${temp_path}" PARENT_SCOPE)
|
||||
endfunction()
|
9
scripts/luau.pc.in
Normal file
9
scripts/luau.pc.in
Normal file
|
@ -0,0 +1,9 @@
|
|||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
libdir=@libdir_for_pc_file@
|
||||
includedir=@includedir_for_pc_file@
|
||||
|
||||
Name: Luau
|
||||
Description: A fast, small, safe, gradually typed embeddable scripting language derived from Lua
|
||||
Version: @VERSION@
|
||||
Cflags: -I${incluedir}
|
||||
Libs: -L${libdir} -lLuau.CLI.lib -lLuau.Ast -lLuau.Compiler -lLuau.Config -lLuau.Analysis -lLuau.EqSat -lLuau.CodeGen -lLuau.VM
|
Loading…
Reference in a new issue