-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
148 lines (127 loc) · 5.15 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# @TESTALL:ANY@
cmake_minimum_required(VERSION 3.22)
if(UNIX)
cmake_path(SET USERHOME NORMALIZE $ENV{HOME})
else()
cmake_path(SET USERHOME NORMALIZE $ENV{USERPROFILE})
endif()
#
# USER CONFIG
#
# Use preloading via withdll.exe from Microsoft Detours project?
# (ie 'withdll.exe /d:ReaperThemeHackDll.dll reaper.exe')
# (recommended for best results)
# (also debugging needs a manual connect to the reaper process - CTRL-ALT-P)
set(WITH_DETOURS_WITHDLL TRUE CACHE BOOL TRUE)
# your reaper install directory for debugging
# (best to use a separate and clean portable install that's user-writable)
cmake_path(SET REAPER_HOME NORMALIZE "${USERHOME}/source/reaper" )
#
# DEPENDENCIES
#
include(FetchContent)
FetchContent_Populate(
reapersdk
URL https://github.com/justinfrankel/reaper-sdk/archive/02deb819c4ba0fc1bac001c8dfff7b9dbaf408ad.zip
URL_HASH SHA256=da690f80c498005046a7301b10923f7345a49a0e5691f621bf289099ce20230f
EXCLUDE_FROM_ALL
)
cmake_path(SET REAPERSDK_INCLUDE_DIRS NORMALIZE "${reapersdk_SOURCE_DIR}/sdk/")
FetchContent_Populate(
inipp
URL https://github.com/mcmtroffaes/inipp/archive/c61e699682d3f1091209c2179f1d03f5fc593327.zip
URL_HASH SHA256=1727e025c03e80db4f66925fa5e20e36943c2a2f94c6b141cb1f6f792a6cdca8
EXCLUDE_FROM_ALL
)
cmake_path(SET INIPP_INCLUDE_DIRS NORMALIZE "${inipp_SOURCE_DIR}/inipp/")
if(WITH_DETOURS_WITHDLL)
include(ExternalProject)
ExternalProject_Add(
detours
URL https://github.com/microsoft/Detours/archive/4b8c659f549b0ab21cf649377c7a84eb708f5e68.zip
URL_HASH SHA256=08d965a8374ca1e56bcf05380d2ee7daa846080b85d568223a41c20b5913bbf8
CONFIGURE_COMMAND ""
BUILD_COMMAND nmake $<$<CONFIG:Debug>:DETOURS_CONFIG=Debug>
INSTALL_COMMAND ""
BUILD_IN_SOURCE TRUE
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
ExternalProject_Get_property(detours SOURCE_DIR)
cmake_path(SET WITHDLLEXE_PATH NORMALIZE "${SOURCE_DIR}/bin.X64$<$<CONFIG:Debug>:Debug>/withdll.exe")
endif()
#
# THE PROJECT
#
project(ReaperThemeHackDll)
set(CMAKE_CXX_STANDARD 20)
if (MSVC)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
add_compile_options(/MP)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_compile_definitions(NOMINMAX UNICODE)
endif()
add_library(${PROJECT_NAME} SHARED
framework.h
reaper_impl.cpp
utils.cpp
utils.h
UAHMenuBar.h
ReaperMenuBarThemeDll.cpp
ReaperMenuBarThemeDll.def
README.md
)
target_include_directories(${PROJECT_NAME} PRIVATE ${REAPERSDK_INCLUDE_DIRS} ${INIPP_INCLUDE_DIRS})
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
target_precompile_headers(${PROJECT_NAME} PRIVATE framework.h)
# withdll.exe wants ordinal 1
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.def\"")
if(WITH_DETOURS_WITHDLL)
add_dependencies(${PROJECT_NAME} detours)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/runwithdll.cmd
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/."
COMMENT "Copying runwithdll.cmd into $<TARGET_FILE_DIR:${PROJECT_NAME}>"
DEPENDS detours
)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${WITHDLLEXE_PATH}
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/."
COMMENT "Copying withdll.exe into $<TARGET_FILE_DIR:${PROJECT_NAME}>"
DEPENDS detours
)
endif()
#
# set up debugging under reaper for convenience
#
cmake_path(SET REAPER_EXE_PATH NORMALIZE "${REAPER_HOME}/reaper.exe")
cmake_path(SET REAPER_USERDLL_PATH NORMALIZE "${REAPER_HOME}/UserPlugins/reaper_themehack-x64.dll")
if (EXISTS "${REAPER_EXE_PATH}")
if(WITH_DETOURS_WITHDLL) # dll 'preload' mode
cmake_path(GET REAPER_EXE_PATH PARENT_PATH REAPER_INSTALL_PATH)
# remove UserPlugin variant so we don't end up running two instances
# within the same Reaper process
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E rm -f
"${REAPER_USERDLL_PATH}"
COMMENT "Removing ${REAPER_USERDLL_PATH}")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${PROJECT_NAME}>"
"${REAPER_INSTALL_PATH}"
COMMENT "Copying $<TARGET_FILE_NAME:${PROJECT_NAME}> into reaper install directory ${REAPER_INSTALL_PATH}")
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND "${WITHDLLEXE_PATH}"
VS_DEBUGGER_COMMAND_ARGUMENTS "/d:${REAPER_INSTALL_PATH}/${PROJECT_NAME}.dll ${REAPER_EXE_PATH}")
else() # Reaper UserPlugin mode
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${PROJECT_NAME}>"
"${REAPER_USERDLL_PATH}"
COMMENT "Copying to reaper userplugins directory ${REAPER_USERDLL_PATH}")
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND "${REAPER_EXE_PATH}"
VS_DEBUGGER_COMMAND_ARGUMENTS "")
endif()
endif()