1 | cmake_minimum_required(VERSION 2.8)
|
2 |
|
3 | macro(use_c99)
|
4 | if (CMAKE_VERSION VERSION_LESS "3.1")
|
5 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
6 | set (CMAKE_C_FLAGS "--std=gnu99 ${CMAKE_C_FLAGS}")
|
7 | endif ()
|
8 | else ()
|
9 | set (CMAKE_C_STANDARD 99)
|
10 | endif ()
|
11 | endmacro(use_c99)
|
12 |
|
13 | use_c99()
|
14 |
|
15 | set (CMAKE_CXX_STANDARD 11)
|
16 |
|
17 | project(iohook)
|
18 |
|
19 | if(WIN32 OR WIN64)
|
20 | add_subdirectory(libuiohook ${CMAKE_CURRENT_SOURCE_DIR}/libuiohook)
|
21 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
|
22 |
|
23 | #bootstrap and configure
|
24 | set(_config_headers "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/include/config.h")
|
25 | add_custom_target( "prepare_iuhook"
|
26 | COMMAND "./bootstrap.sh"
|
27 | COMMAND "./configure"
|
28 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook")
|
29 |
|
30 | file(GLOB SOURCE_UIHOOK_FILES "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/logger.c"
|
31 | "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/logger.h"
|
32 | "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/x11/*.c"
|
33 | "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/x11/*.h"
|
34 | "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/include/config.h" )
|
35 |
|
36 | add_library( "uiohook" STATIC ${SOURCE_UIHOOK_FILES} )
|
37 | set_target_properties("uiohook" PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H=1 -fPIC")
|
38 | add_dependencies( "uiohook" "prepare_iuhook")
|
39 | target_include_directories("uiohook" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/include/" "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src" ${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/x11 )
|
40 | else()
|
41 | #bootstrap and configure
|
42 | set(_config_headers "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/include/config.h")
|
43 | add_custom_target( "prepare_iuhook"
|
44 | COMMAND "./bootstrap.sh"
|
45 | COMMAND "./configure"
|
46 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook")
|
47 |
|
48 | file(GLOB SOURCE_UIHOOK_FILES "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/logger.c"
|
49 | "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/logger.h"
|
50 | "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/darwin/*.c"
|
51 | "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/darwin/*.h"
|
52 | "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/include/config.h" )
|
53 |
|
54 | add_library( "uiohook" STATIC ${SOURCE_UIHOOK_FILES} )
|
55 | set_target_properties("uiohook" PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H=1")
|
56 | add_dependencies( "uiohook" "prepare_iuhook")
|
57 | target_include_directories("uiohook" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/include/" "${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src" ${CMAKE_CURRENT_SOURCE_DIR}/libuiohook/src/darwin )
|
58 |
|
59 | endif()
|
60 |
|
61 | # Build a shared library named after the project from the files in `src/`
|
62 | file(GLOB SOURCE_FILES "src/*.cc" "src/*.h")
|
63 | add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
|
64 |
|
65 | # Gives our library file a .node extension without any "lib" prefix
|
66 | set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
|
67 |
|
68 | # Essential include files to build a node addon,
|
69 | # You should add this line in every CMake.js based project
|
70 | target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
|
71 |
|
72 | # Essential library files to link to a node addon
|
73 | # You should add this line in every CMake.js based project
|
74 | target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} "uiohook")
|
75 |
|
76 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
|
77 | target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} "uiohook" "xkbfile" "xkbcommon-x11" "xkbcommon" "X11-xcb" "xcb" "Xinerama" "Xt" "Xtst" "X11")
|
78 | endif()
|
79 |
|
80 | if(CMAKE_SYSTEM_NAME MATCHES "(Darwin)")
|
81 | find_library(FRAMEWORK_IOKIT IOKit)
|
82 | find_library(FRAMEWORK_Carbon Carbon)
|
83 | target_link_libraries(${PROJECT_NAME} ${FRAMEWORK_IOKIT} ${FRAMEWORK_Carbon})
|
84 | endif()
|