This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
131 lines (105 loc) · 5.23 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
cmake_minimum_required(VERSION 3.17)
# Set this to On to include the examples in the project to easier build them
option(INCLUDE_HAXE_EXAMPLES "Include the examples in the project" OFF)
project(HaxeWrapper)
set (CMAKE_CXX_STANDARD 11)
if(UNIX AND NOT APPLE)
set(ARCH "_x64") # @todo: Determine this dynamically
set(PLATFORM "${CMAKE_CXX_PLATFORM_ID}")
elseif(WIN32)
set(ARCH "_${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
string(TOLOWER "${ARCH}" ARCH)
set(PLATFORM "${CMAKE_CXX_PLATFORM_ID}")
elseif(APPLE)
set(ARCH "")
set(PLATFORM "MacOS")
endif()
add_custom_target(CopyHaxewrapperForExamples
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/examples/ModioWrapper.hx)
function(add_example EXAMPLE_NAME EXAMPLE_LIST_NAME)
string(TOLOWER "${PLATFORM}" COMPILE_PLATFORM)
# ensure that we keep src/Mod
add_custom_command(OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/src/examples/ModioWrapper.hx
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/src/ModioWrapper.hx ${CMAKE_CURRENT_SOURCE_DIR}/src/examples/ModioWrapper.hx
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/ModioWrapper.hx)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/bin/${EXAMPLE_NAME}${CMAKE_EXECUTABLE_SUFFIX}
COMMAND haxe
ARGS -cp src/examples -main ${EXAMPLE_NAME} -cpp bin -D "${COMPILE_PLATFORM}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS HaxeWrapper CopyHaxewrapperForExamples ${CMAKE_CURRENT_SOURCE_DIR}/src/examples/${EXAMPLE_NAME}.hx
COMMENT "Building ${EXAMPLE_NAME}")
add_custom_target(${EXAMPLE_NAME}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${EXAMPLE_NAME}${CMAKE_EXECUTABLE_SUFFIX})
add_dependencies(${EXAMPLE_NAME} modio HaxeWrapper)
if(NOT DEFINED ${EXAMPLE_LIST_NAME})
set(${EXAMPLE_LIST_NAME} ${EXAMPLE_NAME} PARENT_SCOPE)
else()
set(${EXAMPLE_LIST_NAME} ${${EXAMPLE_LIST_NAME}} ${EXAMPLE_NAME} PARENT_SCOPE)
endif()
endfunction()
find_package(Git REQUIRED)
include(FetchContent)
message(STATUS "Fetching modio/SDK from github...")
FetchContent_Declare( ModioSDK
GIT_REPOSITORY https://github.com/MarkusRannare/SDK.git
GIT_TAG 93e7a1e9d2a7b52afcd0b06643935057f740f48e # this is 0.12.16-release but with the changes that you can use the cmake project as a subdirectory
)
FetchContent_Populate(ModioSDK)
add_subdirectory( ${modiosdk_SOURCE_DIR} )
include_directories(HaxeWrapper PUBLIC ${modiosdk_SOURCE_DIR}/include)
link_directories(${modiosdk_BINARY_DIR}/lib)
SET(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/modioWrapper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/modioWrapperCallbacks.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/modioWrapperObjects.cpp)
add_library(HaxeWrapper ${SOURCE_FILES})
target_include_directories(HaxeWrapper PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(HaxeWrapper modio)
# Ensure that we have the same output directory as we had in the previous setup
set_target_properties(HaxeWrapper
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/bin")
# Ensure that we don't prefix the ndll with lib as we didn't do that in the previous setup
set(CMAKE_SHARED_LIBRARY_PREFIX "")
# Because OUTPUT option may not use generator expressions,
# extract name of file from target's properties.
get_target_property(MODIO_BASENAME modio OUTPUT_NAME)
get_target_property(MODIO_SUFFIX modio SUFFIX)
set(MODIO_FILENAME ${MODIO_BASENAME}${MODIO_SUFFIX})
# make copied file be dependent from one which is build.
# Note, that DEPENDS here creates dependencies both from the target
# and from the file it creates.
add_custom_command(OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/bin/${MODIO_FILENAME}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:modio> "${CMAKE_CURRENT_SOURCE_DIR}/bin"
DEPENDS modio)
# Create target which consume the command via DEPENDS.
add_custom_target(copy_files_modio ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${MODIO_FILENAME})
set_target_properties(HaxeWrapper PROPERTIES
OUTPUT_NAME "modioWrapper${PLATFORM}${ARCH}"
SUFFIX ".ndll")
add_dependencies(HaxeWrapper modio)
# Ability to easily build examples
if(INCLUDE_HAXE_EXAMPLES)
add_example(Ex01_Authentication EXAMPLES)
add_example(Ex02_BrowseMods EXAMPLES)
add_example(Ex03_SubscribeToMod EXAMPLES)
add_example(Ex04_UnsubscribeFromMod EXAMPLES)
add_example(Ex05_AutomaticDownloads EXAMPLES)
add_example(Ex06_AddMod EXAMPLES)
add_example(Ex07_EditMod EXAMPLES)
add_example(Ex08_GetUserSubscriptions EXAMPLES)
add_example(Ex09_SetEventListener EXAMPLES)
add_example(Ex10_InstallDownloadedMods EXAMPLES)
add_example(Ex11_GetInstalledMods EXAMPLES)
# Removed the "All examples target, as we get a error when building it that I don't know how to handle:
# "error : Uncaught exception on main thread: [file_open,C:/Github/HaxeWrapper/bin/obj/msvc19xp/__pch/haxe/hxcpp.cpp]"
#add_custom_Target(Examples DEPENDS ${EXAMPLES})
endif()