Skip to content

Commit

Permalink
build: update build system to install scripts at home dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattaa committed Dec 12, 2024
1 parent bb9f4b1 commit 226a11d
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.18)

project(lsr LANGUAGES C)

option(HOMEBREW_INSTALLATION "Is this a Homebrew installation" OFF)
option(ENABLE_SANITIZER "Enable AddressSanitizer for debug builds" ON)

if(ENABLE_SANITIZER)
Expand All @@ -13,21 +14,10 @@ endif()
set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG ${SANITIZER_FLAGS} -Wall -Wextra -pedantic")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")

set(USER_HOME "$ENV{HOME}")

find_package(Lua 5.1 REQUIRED)

if (NOT LUA_FOUND)
if(NOT LUA_FOUND)
message(FATAL_ERROR "Lua5.1 libraries not found")
else()
message(STATUS "Lua include directory: ${LUA_INCLUDE_DIR}")
message(STATUS "Lua libraries: ${LUA_LIBRARIES}")
endif()

if(NOT LUA_INCLUDE_DIR)
message(FATAL_ERROR "Lua headers not found")
else()
message(STATUS "Lua include directory: ${LUA_INCLUDE_DIR}")
endif()

include_directories("${LUA_INCLUDE_DIR}")
Expand All @@ -36,6 +26,7 @@ file(GLOB_RECURSE SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")

set(USER_HOME "$ENV{HOME}")
set(LUA_SCRIPTS_INSTALL_PATH "${USER_HOME}/.lsr")
set(DEFAULT_SCRIPT_PATH "${LUA_SCRIPTS_INSTALL_PATH}/lsr.lua")

Expand All @@ -45,29 +36,15 @@ target_compile_definitions(lsr PRIVATE DEFAULT_SCRIPT_PATH="${DEFAULT_SCRIPT_PAT
target_include_directories(lsr PRIVATE ${LUA_INCLUDE_DIR})
target_link_libraries(lsr PRIVATE ${LUA_LIBRARIES})

add_custom_target(format COMMAND clang-format -i ${SRCS})

file(GLOB LUA_SCRIPTS "${CMAKE_CURRENT_SOURCE_DIR}/lua/*.lua")
file(MAKE_DIRECTORY "${LUA_SCRIPTS_INSTALL_PATH}")
add_custom_command(TARGET lsr POST_BUILD
COMMENT "Copying Lua scripts to ${LUA_SCRIPTS_INSTALL_PATH}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${LUA_SCRIPTS_INSTALL_PATH}"
COMMAND ${CMAKE_COMMAND} -E copy ${LUA_SCRIPTS} "${LUA_SCRIPTS_INSTALL_PATH}"
)

install(TARGETS lsr DESTINATION bin)

if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake

COMMAND ${CMAKE_COMMAND} -E remove_directory "${LUA_SCRIPTS_INSTALL_PATH}"
COMMENT "Removing Lua scripts from ${LUA_INSTALL_PATH}"
if (NOT HOMEBREW_INSTALLATION)
add_custom_command(TARGET lsr POST_BUILD
COMMENT "Copying Lua scripts to ${LUA_SCRIPTS_INSTALL_PATH}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${LUA_SCRIPTS_INSTALL_PATH}"
COMMAND ${CMAKE_COMMAND} -E copy ${LUA_SCRIPTS} "${LUA_SCRIPTS_INSTALL_PATH}"
)
endif()

install(TARGETS lsr DESTINATION bin)

0 comments on commit 226a11d

Please sign in to comment.