From 3503cce0db83dd7579d71c375f829f49e696e86b Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Tue, 22 Jul 2025 04:45:23 -0400 Subject: [PATCH] CMake: Check for libDl, conditionally check for libXCB --- CMakeLists.txt | 23 ++++++++++++----------- commonLibs/CMakeLists.txt | 5 +---- commonLibs/xcbXorg/CMakeLists.txt | 28 +++++++++++++++++----------- hcore/CMakeLists.txt | 7 +------ hcore/deviceManager/CMakeLists.txt | 8 +++----- hcore/marionette/CMakeLists.txt | 2 +- hcore/senseApis/CMakeLists.txt | 4 +--- senseApis/CMakeLists.txt | 1 + senseApis/xcbWindow/CMakeLists.txt | 22 ++++++++++++++++++++++ wilzorApis/CMakeLists.txt | 1 + wilzorApis/xcbMouse/CMakeLists.txt | 22 ++++++++++++++++++++++ 11 files changed, 82 insertions(+), 41 deletions(-) create mode 100644 senseApis/CMakeLists.txt create mode 100644 senseApis/xcbWindow/CMakeLists.txt create mode 100644 wilzorApis/CMakeLists.txt create mode 100644 wilzorApis/xcbMouse/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index b296b3f..f40d7cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.16) project(harikoff VERSION 0.00.002 LANGUAGES CXX) +include(CMakeDependentOption) + # Set C++ standard set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -33,23 +35,23 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR}/include ) -# Find dependencies +# Find core dependencies find_package(Boost 1.69.0 REQUIRED COMPONENTS system) find_package(PkgConfig REQUIRED) - -# Flex/Bison setup find_package(FLEX REQUIRED) find_package(BISON REQUIRED) -# XCB (optional, controlled by feature flags) -option(ENABLE_XCB "Enable XCB/Xorg support" ON) -if(ENABLE_XCB) - pkg_check_modules(XCB REQUIRED xcb) +# Need dlopen() and dlsym() +find_library(DL_LIBRARY NAMES dl ldl) +if(NOT DL_LIBRARY) + message(FATAL_ERROR "Dynamic linking library (libdl/libldl) not found") endif() -# Add subdirectories +# Add core components add_subdirectory(hcore) add_subdirectory(commonLibs) +add_subdirectory(senseApis) +add_subdirectory(wilzorApis) # Main executable add_executable(harikoff main.cpp) @@ -58,8 +60,7 @@ target_link_libraries(harikoff deviceManager senseApis ${Boost_LIBRARIES} - dl + ${DL_LIBRARY} ) -# Install rules -install(TARGETS harikoff DESTINATION bin) \ No newline at end of file +install(TARGETS harikoff DESTINATION bin) diff --git a/commonLibs/CMakeLists.txt b/commonLibs/CMakeLists.txt index 9eb94c8..c25c92a 100644 --- a/commonLibs/CMakeLists.txt +++ b/commonLibs/CMakeLists.txt @@ -1,4 +1 @@ -# Conditional compilation based on feature flags -if(ENABLE_XCB) - add_subdirectory(xcbXorg) -endif() \ No newline at end of file +add_subdirectory(xcbXorg) diff --git a/commonLibs/xcbXorg/CMakeLists.txt b/commonLibs/xcbXorg/CMakeLists.txt index df5be98..c751d59 100644 --- a/commonLibs/xcbXorg/CMakeLists.txt +++ b/commonLibs/xcbXorg/CMakeLists.txt @@ -1,14 +1,20 @@ -add_library(xcbXorg SHARED - xcbXorg.cpp -) +option(ENABLE_LIB_xcbXorg "Enable XCB/Xorg Connection Manager backend lib" ON) -target_include_directories(xcbXorg PUBLIC - ${XCB_INCLUDE_DIRS} -) +if(ENABLE_LIB_xcbXorg) + pkg_check_modules(XCB REQUIRED xcb) + if(NOT XCB_FOUND) + message(FATAL_ERROR "XCB library not found. XCB/Xorg requires the XCB dev headers and shlib.") + endif() -target_link_libraries(xcbXorg - ${XCB_LIBRARIES} -) + add_library(xcbXorg SHARED + xcbXorg.cpp + ) -# Install rules -install(TARGETS xcbXorg DESTINATION lib) \ No newline at end of file + # Set config define for header generation + add_compile_definitions(CONFIG_LIB_XCBXORG_ENABLED) + target_include_directories(xcbXorg PUBLIC ${XCB_INCLUDE_DIRS}) + target_link_libraries(xcbXorg ${XCB_LIBRARIES}) + + # Install rules + install(TARGETS xcbXorg DESTINATION lib) +endif() diff --git a/hcore/CMakeLists.txt b/hcore/CMakeLists.txt index 7ba6305..bf91a3f 100644 --- a/hcore/CMakeLists.txt +++ b/hcore/CMakeLists.txt @@ -9,11 +9,6 @@ target_include_directories(hcore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ) -# Device manager (with Flex/Bison) add_subdirectory(deviceManager) - -# Sense APIs add_subdirectory(senseApis) - -# Marionette -add_subdirectory(marionette) \ No newline at end of file +add_subdirectory(marionette) diff --git a/hcore/deviceManager/CMakeLists.txt b/hcore/deviceManager/CMakeLists.txt index c0cc2ef..82cb036 100644 --- a/hcore/deviceManager/CMakeLists.txt +++ b/hcore/deviceManager/CMakeLists.txt @@ -6,15 +6,15 @@ set(YACC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/deviceSpecp.hh) # Generate Flex/Bison files using custom commands add_custom_command( OUTPUT ${LEX_OUTPUT} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/deviceSpecl.ll ${YACC_HEADER} COMMAND ${FLEX_EXECUTABLE} --header-file=${CMAKE_CURRENT_BINARY_DIR}/deviceSpecl.hh -o ${LEX_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/deviceSpecl.ll - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/deviceSpecl.ll COMMENT "Generating deviceSpecl.cc from deviceSpecl.ll" ) add_custom_command( OUTPUT ${YACC_OUTPUT} ${YACC_HEADER} - COMMAND ${BISON_EXECUTABLE} -p deviceSpecp --header=${YACC_HEADER} -o ${YACC_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/deviceSpecp.yy DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/deviceSpecp.yy + COMMAND ${BISON_EXECUTABLE} -p deviceSpecp --header=${YACC_HEADER} -o ${YACC_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/deviceSpecp.yy COMMENT "Generating deviceSpecp.cc and deviceSpecp.hh from deviceSpecp.yy" ) @@ -26,6 +26,4 @@ add_library(deviceManager STATIC ${YACC_OUTPUT} ) -target_include_directories(deviceManager PUBLIC - ${CMAKE_CURRENT_BINARY_DIR} -) \ No newline at end of file +target_include_directories(deviceManager PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/hcore/marionette/CMakeLists.txt b/hcore/marionette/CMakeLists.txt index 471737d..bc3d743 100644 --- a/hcore/marionette/CMakeLists.txt +++ b/hcore/marionette/CMakeLists.txt @@ -4,4 +4,4 @@ add_library(marionette STATIC target_include_directories(marionette PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include -) \ No newline at end of file +) diff --git a/hcore/senseApis/CMakeLists.txt b/hcore/senseApis/CMakeLists.txt index 334508b..178787d 100644 --- a/hcore/senseApis/CMakeLists.txt +++ b/hcore/senseApis/CMakeLists.txt @@ -2,6 +2,4 @@ add_library(senseApis STATIC senseApiManager.cpp ) -target_include_directories(senseApis PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include -) \ No newline at end of file +target_include_directories(senseApis PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/senseApis/CMakeLists.txt b/senseApis/CMakeLists.txt new file mode 100644 index 0000000..24a54a5 --- /dev/null +++ b/senseApis/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(xcbWindow) diff --git a/senseApis/xcbWindow/CMakeLists.txt b/senseApis/xcbWindow/CMakeLists.txt new file mode 100644 index 0000000..62bf661 --- /dev/null +++ b/senseApis/xcbWindow/CMakeLists.txt @@ -0,0 +1,22 @@ +# XCB/Xorg Window Attaching SenseAPI backend +cmake_dependent_option(ENABLE_SENSEAPI_xcbWindow + "Enable XCB/Xorg Window Attaching SenseAPI backend" OFF + "ENABLE_LIB_xcbXorg" OFF) + +if(ENABLE_SENSEAPI_xcbWindow) + # For now, just create a placeholder library + add_library(senseApiXcbWindow STATIC + # xcbWindow.cpp would go here + ) + + target_link_libraries(senseApiXcbWindow + xcbXorg + ) + + target_include_directories(senseApiXcbWindow PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ) + + # Set config define for header generation + add_compile_definitions(CONFIG_SENSEAPI_XCBWINDOW_ENABLED) +endif() diff --git a/wilzorApis/CMakeLists.txt b/wilzorApis/CMakeLists.txt new file mode 100644 index 0000000..4524f39 --- /dev/null +++ b/wilzorApis/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(xcbMouse) diff --git a/wilzorApis/xcbMouse/CMakeLists.txt b/wilzorApis/xcbMouse/CMakeLists.txt new file mode 100644 index 0000000..871c96f --- /dev/null +++ b/wilzorApis/xcbMouse/CMakeLists.txt @@ -0,0 +1,22 @@ +# XCB/Xorg Mouse Wilzor API backend +cmake_dependent_option(ENABLE_WILZORAPI_xcbMouse + "Enable XCB/Xorg Mouse Wilzor API backend" OFF + "ENABLE_LIB_xcbXorg" OFF) + +if(ENABLE_WILZORAPI_xcbMouse) + # For now, just create a placeholder library + add_library(wilzorApiXcbMouse STATIC + # xcbMouse.cpp would go here + ) + + target_link_libraries(wilzorApiXcbMouse + xcbXorg + ) + + target_include_directories(wilzorApiXcbMouse PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ) + + # Set config define for header generation + add_compile_definitions(CONFIG_WILZORAPI_XCBMOUSE_ENABLED) +endif()