77 lines
2.9 KiB
CMake
77 lines
2.9 KiB
CMake
include(CMakeDependentOption)
|
|
cmake_minimum_required(VERSION 3.0.2)
|
|
project(rexbacklight)
|
|
|
|
#setup common defines for C files
|
|
set(rexbacklight_VERSION_MAJOR 1)
|
|
set(rexbacklight_VERSION_MINOR 3)
|
|
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
|
|
|
#set project include directory
|
|
include_directories("${INCLUDE_PATH}")
|
|
|
|
#setup cmake options
|
|
option(BUILD_REXLEDCTL "Build led control program" ON)
|
|
option(BUILD_REXBACKLIGHT "Build backlight control program" ON)
|
|
option(ENABLE_RESTORE_FILE "Enable backlight restoration from generated save file" ON)
|
|
option(XBACKLIGHT_COMPAT "Use xbacklight style options (eg -get -inc -dec)" OFF)
|
|
CMAKE_DEPENDENT_OPTION(INSTALL_UDEV_LED_RULE "Install the udev rule to allow users of video group to control led devices" ON
|
|
"BUILD_REXLEDCTL" OFF)
|
|
CMAKE_DEPENDENT_OPTION(INSTALL_UDEV_BACKLIGHT_RULE "Install the udev rule to allow users of video group to control backlight devices" ON
|
|
"BUILD_REXBACKLIGHT" OFF)
|
|
set(UDEV_DIR "/etc/udev/rules.d" CACHE STRING "Set the output directory for udev rules")
|
|
mark_as_advanced(UDEV_DIR)
|
|
|
|
if(XBACKLIGHT_COMPAT)
|
|
add_definitions(-DXBACKLIGHT_COMPAT_OPTIONS)
|
|
endif()
|
|
|
|
#locate rjp library requirements
|
|
if(ENABLE_RESTORE_FILE)
|
|
find_library(RJP_LIB rjp)
|
|
find_path(RJP_HEADER_DIR rjp.h)
|
|
#temporary library (no actual library generated)
|
|
add_library(common_srcs OBJECT src/cmd.c src/common.c src/restore.c)
|
|
set(enable_RESTORE_FILE "#define ENABLE_RESTORE_FILE")
|
|
else()
|
|
add_library(common_srcs OBJECT src/cmd.c src/common.c)
|
|
set(enable_RESTORE_FILE "")
|
|
endif()
|
|
|
|
configure_file(
|
|
"${INCLUDE_PATH}/config.h.in"
|
|
"${INCLUDE_PATH}/config.h"
|
|
)
|
|
|
|
if(BUILD_REXLEDCTL)
|
|
add_executable (rexledctl src/rexbacklight.c)
|
|
add_dependencies(rexledctl common_srcs) #force common_srcs to be built first
|
|
target_compile_definitions(rexledctl PRIVATE REXLEDCTL) #define REXLEDCTL in C files
|
|
if(ENABLE_RESTORE_FILE)
|
|
target_link_libraries(rexledctl PRIVATE "${RJP_LIB}") #link with rjp
|
|
target_include_directories(rexledctl PUBLIC "${RJP_HEADER_DIR}") #include rjp.h directory
|
|
endif()
|
|
target_link_libraries(rexledctl PRIVATE $<TARGET_OBJECTS:common_srcs>) #link with the common_srcs "library"
|
|
install(TARGETS rexledctl RUNTIME DESTINATION bin)
|
|
if(INSTALL_UDEV_LED_RULE)
|
|
install(FILES ${CMAKE_SOURCE_DIR}/rules/91-leds.rules DESTINATION ${UDEV_DIR})
|
|
endif()
|
|
endif()
|
|
if(BUILD_REXBACKLIGHT)
|
|
add_executable (rexbacklight src/rexbacklight.c)
|
|
add_dependencies(rexledctl common_srcs)
|
|
target_compile_definitions(rexbacklight PRIVATE REXBACKLIGHT)
|
|
if(ENABLE_RESTORE_FILE)
|
|
target_link_libraries(rexbacklight PRIVATE "${RJP_LIB}")
|
|
target_include_directories(rexbacklight PUBLIC "${RJP_HEADER_DIR}")
|
|
endif()
|
|
target_link_libraries(rexbacklight PRIVATE $<TARGET_OBJECTS:common_srcs>)
|
|
install(TARGETS rexbacklight RUNTIME DESTINATION bin)
|
|
if(INSTALL_UDEV_BACKLIGHT_RULE)
|
|
install(FILES ${CMAKE_SOURCE_DIR}/rules/91-backlight.rules DESTINATION ${UDEV_DIR})
|
|
endif()
|
|
endif()
|
|
|
|
#uninstall target
|
|
add_custom_target(uninstall cat install_manifest.txt | xargs rm)
|