forked from leecbaker/xplane_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
104 lines (92 loc) · 4.96 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Set up the imported targets for X-Plane plugin libraries:
IF(APPLE)
SET(XPLANE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/sdk/Libraries/Mac/")
ELSEIF(WIN32)
SET(XPLANE_LIBRARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/sdk/Libraries/Win/")
ENDIF()
SET(XPLANE_INCLUDES_PATH "${CMAKE_CURRENT_SOURCE_DIR}/sdk/CHeaders/" CACHE STRING PATH)
IF(APPLE)
FIND_LIBRARY(XPLM_LIBRARY XPLM "${XPLANE_LIBRARY_PATH}")
FIND_LIBRARY(XPWIDGETS_LIBRARY XPWidgets "${XPLANE_LIBRARY_PATH}")
add_library(xplm STATIC IMPORTED GLOBAL)
add_library(xpwidgets STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET xplm PROPERTY IMPORTED_LOCATION "${XPLM_LIBRARY}")
SET_PROPERTY(TARGET xpwidgets PROPERTY IMPORTED_LOCATION "${XPWIDGETS_LIBRARY}")
ELSEIF(WIN32)
FIND_LIBRARY(XPLM_LIBRARY XPLM_64 "${XPLANE_LIBRARY_PATH}")
FIND_LIBRARY(XPWIDGETS_LIBRARY XPWidgets_64 "${XPLANE_LIBRARY_PATH}")
add_library(xplm SHARED IMPORTED GLOBAL)
add_library(xpwidgets SHARED IMPORTED GLOBAL)
SET_PROPERTY(TARGET xplm PROPERTY IMPORTED_IMPLIB "${XPLM_LIBRARY}")
SET_PROPERTY(TARGET xpwidgets PROPERTY IMPORTED_IMPLIB "${XPWIDGETS_LIBRARY}")
ELSEIF(UNIX)
message(STATUS linux target made)
add_library(xplm INTERFACE)
add_library(xpwidgets INTERFACE)
ENDIF()
SET(XPLM_LIBRARY "${XPLM_LIBRARY}" PARENT_SCOPE)
SET(XPWIDGETS_LIBRARY "${XPWIDGETS_LIBRARY}" PARENT_SCOPE)
# For some reason this doesn't work. It's not worth wasting more time on fixing it, so
# I'll manually include the directories below
SET_PROPERTY(TARGET xplm APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sdk/CHeaders/XPLM" "${CMAKE_CURRENT_SOURCE_DIR}/sdk/CHeaders/Wrappers")
SET_PROPERTY(TARGET xpwidgets APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sdk/CHeaders/XPLM" "${CMAKE_CURRENT_SOURCE_DIR}/sdk/CHeaders/Widgets" "${CMAKE_CURRENT_SOURCE_DIR}/sdk/CHeaders/Wrappers")
FUNCTION(add_xplane_sdk_definitions library_name library_version)
IF(APPLE)
TARGET_COMPILE_DEFINITIONS(${library_name} PUBLIC -DAPL=1 -DIBM=0 -DLIN=0)
ELSEIF(UNIX)
TARGET_COMPILE_DEFINITIONS(${library_name} PUBLIC -DAPL=0 -DIBM=0 -DLIN=1)
ELSEIF(WIN32)
TARGET_COMPILE_OPTIONS(${library_name} PRIVATE "/MT$<$<CONFIG:Debug>:d>")
TARGET_COMPILE_DEFINITIONS(${library_name} PUBLIC -DAPL=0 -DIBM=1 -DLIN=0)
ENDIF()
IF(library_version EQUAL 200)
TARGET_COMPILE_DEFINITIONS(${library_name} PUBLIC -DXPLM200=1)
ELSEIF(library_version EQUAL 210)
TARGET_COMPILE_DEFINITIONS(${library_name} PUBLIC -DXPLM200=1 -DXPLM210=1)
ELSEIF(library_version EQUAL 300)
TARGET_COMPILE_DEFINITIONS(${library_name} PUBLIC -DXPLM200=1 -DXPLM210=1 -DXPLM300=1)
ELSEIF(library_version EQUAL 301)
TARGET_COMPILE_DEFINITIONS(${library_name} PUBLIC -DXPLM200=1 -DXPLM210=1 -DXPLM300=1 -DXPLM301=1)
ELSE()
MESSAGE(FATAL_ERROR "Library version one of: 200, 210, 300, 301")
ENDIF()
TARGET_INCLUDE_DIRECTORIES(${library_name} PUBLIC "${XPLANE_INCLUDES_PATH}/XPLM" "${XPLANE_INCLUDES_PATH}/Widgets" "${XPLANE_INCLUDES_PATH}/Wrappers")
ENDFUNCTION(add_xplane_sdk_definitions)
# Set up an X-Plane plugin
FUNCTION(add_xplane_plugin library_name library_version ...)
SET(FILES ${ARGV})
LIST(REMOVE_AT FILES 0)
LIST(REMOVE_AT FILES 0)
MESSAGE(STATUS "Making X-Plane plugin called ${library_name}")
IF(APPLE)
ADD_EXECUTABLE(${library_name} ${FILES})
ELSEIF(UNIX)
ADD_LIBRARY(${library_name} SHARED ${FILES})
ELSEIF(WIN32)
ADD_LIBRARY(${library_name} MODULE ${FILES})
TARGET_COMPILE_DEFINITIONS(${library_name} PUBLIC -D_CRT_SECURE_NO_WARNINGS)
ENDIF()
#IF(${library_version} LESS 300)
# IF(APPLE)
# SET_TARGET_PROPERTIES(${library_name} PROPERTIES OUTPUT_NAME "mac.xpl")
# ELSEIF(UNIX)
# SET_TARGET_PROPERTIES(${library_name} PROPERTIES OUTPUT_NAME "lin.xpl")
# ELSEIF(WIN32)
# SET_TARGET_PROPERTIES(${library_name} PROPERTIES OUTPUT_NAME "win.xpl")
# ENDIF()
#ELSE()
# SET_TARGET_PROPERTIES(${library_name} PROPERTIES OUTPUT_NAME "${library_name}.xpl")
#ENDIF()
SET_TARGET_PROPERTIES(${library_name} PROPERTIES OUTPUT_NAME "win.xpl")
add_xplane_sdk_definitions(${library_name} ${library_version})
SET_TARGET_PROPERTIES(${library_name} PROPERTIES PREFIX "")
SET_TARGET_PROPERTIES(${library_name} PROPERTIES SUFFIX "")
#link flags
IF(APPLE)
SET_PROPERTY(TARGET ${library_name} APPEND_STRING PROPERTY LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fPIC -fvisibility=hidden -bundle")
ELSEIF(UNIX)
SET_PROPERTY(TARGET ${library_name} APPEND_STRING PROPERTY LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic -nodefaultlibs -undefined_warning -fPIC -fvisibility=hidden")
ENDIF()
TARGET_LINK_LIBRARIES(${library_name} PUBLIC ${XPLM_LIBRARY} ${XPWIDGETS_LIBRARY})
TARGET_INCLUDE_DIRECTORIES(${library_name} PUBLIC "${XPLANE_INCLUDES_PATH}/XPLM" "${XPLANE_INCLUDES_PATH}/Widgets" "${XPLANE_INCLUDES_PATH}/Wrappers")
ENDFUNCTION(add_xplane_plugin)