1
1
cmake_minimum_required (VERSION 2.8.4)
2
2
project (XInputSimulator)
3
+ set (PROJECT_VERSION 0.1)
4
+
5
+ option (WITH_PIC "Compile static library as position-independent code" OFF ) # Shared library is always PIC
6
+ option (BUILD_STATIC_LIBS "Build the static library" ON )
7
+ option (BUILD_SHARED_LIBS "Build the shared library" ON )
8
+ option (BUILD_MACOS_FATLIB "Build Fat library for both i386 and x86_64 on macOS" ON )
9
+ option (BUILD_MANUAL_TEST "Build the test application" ON )
10
+
11
+ if (BUILD_MACOS_FATLIB)
12
+ if (CMAKE_OSX_ARCHITECTURES)
13
+ message (FATAL_ERROR "User supplied -DCMAKE_OSX_ARCHITECTURES overrides BUILD_MACOS_FATLIB=ON" )
14
+ else ()
15
+ SET (CMAKE_OSX_ARCHITECTURES "x86_64;i386" )
16
+ endif ()
17
+ endif ()
3
18
4
19
# Linux
5
20
if (UNIX AND NOT APPLE )
6
- find_library (X_11 X11)
7
- find_library (X_TST Xtst)
8
- set (EXTRA_LIBS ${X_11} ${X_TST} )
9
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
10
- set (PLATFORM_SOURCE_FILES xinputsimulatorimpllinux.cpp xinputsimulatorimpllinux.h)
21
+ find_library (X_11 X11)
22
+ find_library (X_TST Xtst)
23
+ set (EXTRA_LIBS ${X_11} ${X_TST} )
24
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
25
+ # Not nice, but I don't know how to have CMake generate all dependencies
26
+ # One could run ldd(1) on the .so and extract all deps...
27
+ set (PKG_CONFIG_EXTRA_LIBS "-lX11 -lXtst -lXext -lxcb -lXau -pthread -lXdmcp -lrt" )
28
+ set (PLATFORM_SOURCE_FILES xinputsimulatorimpllinux.cpp xinputsimulatorimpllinux.h)
29
+ set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX} /lib" )
30
+ set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
11
31
endif (UNIX AND NOT APPLE )
12
32
13
33
# Apple
14
34
if (APPLE )
15
- find_library (APP_SERVICES ApplicationServices)
16
35
find_library (CARBON Carbon)
17
36
find_library (CORE_FOUNDATION CoreFoundation)
18
- set (EXTRA_LIBS ${APP_SERVICES_LIBRARY} ${CARBON} ${CORE_FOUNDATION} )
19
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
20
- set (PLATFORM_SOURCE_FILES xinputsimulatorimplmacos.cpp xinputsimulatorimplmacos.h)
37
+ set (EXTRA_LIBS ${CARBON} ${CORE_FOUNDATION} )
38
+ set (PKG_CONFIG_EXTRA_LIBS "-framework Carbon -framework Core" )
39
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
40
+ set (PLATFORM_SOURCE_FILES xinputsimulatorimplmacos.cpp xinputsimulatorimplmacos.h)
41
+ set (CMAKE_MACOSX_RPATH ON )
21
42
endif (APPLE )
22
-
23
- # Windows
24
- if (WIN32 )
25
- #find_library(USER_32 User32.Lib)
26
- #set(EXTRA_LIBS ${USER_32})
27
- set (PLATFORM_SOURCE_FILES xinputsimulatorimplwin.cpp xinputsimulatorimplwin.h)
28
- endif (WIN32 )
29
-
30
- set (SOURCE_FILES
31
- main.cpp
32
- notimplementedexception.cpp
33
- notimplementedexception.h
34
- xinputsimulator.cpp
35
- xinputsimulator.h
36
- xinputsimulatorimpl.cpp
37
- xinputsimulatorimpl.h
38
- ${PLATFORM_SOURCE_FILES} )
39
-
40
- add_executable (XInputSimulator ${SOURCE_FILES} )
41
- target_link_libraries (XInputSimulator ${EXTRA_LIBS} )
43
+
44
+ # Windows
45
+ if (WIN32 )
46
+ #find_library(USER_32 User32.Lib)
47
+ #set(EXTRA_LIBS ${USER_32})
48
+ set (PLATFORM_SOURCE_FILES xinputsimulatorimplwin.cpp xinputsimulatorimplwin.h)
49
+ endif (WIN32 )
50
+
51
+ set (SOURCE_FILES
52
+ notimplementedexception.cpp
53
+ xinputsimulator.cpp
54
+ xinputsimulator.h
55
+ xinputsimulatorimpl.cpp
56
+ xinputsimulatorimpl.h
57
+ ${PLATFORM_SOURCE_FILES} )
58
+
59
+ link_libraries (${EXTRA_LIBS} )
60
+ configure_file (XInputSimulator.pc.in XInputSimulator.pc @ONLY)
61
+
62
+ if (BUILD_SHARED_LIBS )
63
+ add_library (XInputSimulator SHARED ${SOURCE_FILES} )
64
+ set_property (TARGET XInputSimulator PROPERTY POSITION_INDEPENDENT_CODE ON )
65
+ endif ()
66
+ if (BUILD_STATIC_LIBS)
67
+ add_library (XInputSimulator_static STATIC ${SOURCE_FILES} )
68
+ if (WITH_PIC)
69
+ set_property (TARGET XInputSimulator_static PROPERTY POSITION_INDEPENDENT_CODE ON )
70
+ endif ()
71
+ if (NOT WIN32 ) # Keep lib*.(a|dll) name, but avoid *.lib files overwriting each other on Windows
72
+ set_target_properties (XInputSimulator_static PROPERTIES OUTPUT_NAME XInputSimulator)
73
+ endif ()
74
+ endif ()
75
+
76
+
77
+
78
+ IF (NOT (BUILD_STATIC_LIBS OR BUILD_SHARED_LIBS ))
79
+ MESSAGE (FATAL_ERROR "Both -DBUILD_SHARED_LIBS=OFF and -DBUILD_STATIC_LIBS=OFF supplied. Nothing to do..." )
80
+ ENDIF ()
81
+
82
+ if (BUILD_MANUAL_TEST)
83
+ add_executable (XInputSimulator_bin main.cpp)
84
+ target_link_libraries (XInputSimulator_bin XInputSimulator)
85
+ set_target_properties (XInputSimulator_bin PROPERTIES OUTPUT_NAME "XInputSimulator" )
86
+ endif ()
87
+
88
+ install (FILES ${CMAKE_BINARY_DIR} /XInputSimulator.pc DESTINATION lib/pkgconfig)
89
+ install (TARGETS XInputSimulator XInputSimulator_static
90
+ LIBRARY DESTINATION lib
91
+ ARCHIVE DESTINATION lib)
92
+ install (FILES xinputsimulator.h DESTINATION include )
93
+
0 commit comments