-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddExternal.cmake
82 lines (74 loc) · 3.25 KB
/
AddExternal.cmake
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
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
set(CMAKE_XCODE_GENERATE_SCHEME TRUE)
cmake_path(GET CMAKE_CURRENT_LIST_FILE PARENT_PATH CURRENT_MODULE_DIR)
function(add_external TARGET)
cmake_parse_arguments(ARG "CUSTOM_DOCUMENTATION" "NAME;VERSION;REVERSE_DOMAIN;COPYRIGHT;OUTPUT_DIRECTORY" "" ${ARGN})
if(ARG_NAME)
set(EXTERNAL_NAME ${ARG_NAME})
endif()
if(ARG_VERSION)
set(PACKAGE_VERSION ${ARG_VERSION})
endif()
if(ARG_REVERSE_DOMAIN)
set(PACKAGE_REVERSE_DOMAIN ${ARG_REVERSE_DOMAIN})
endif()
if(ARG_COPYRIGHT)
set(PACKAGE_COPYRIGHT ${ARG_COPYRIGHT})
endif()
if(ARG_OUTPUT_DIRECTORY)
set(OUTPUT_DIRECTORY ${ARG_OUTPUT_DIRECTORY})
else()
set(OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/externals)
endif()
set(PRODUCT_IDENTIFIER ${EXTERNAL_NAME})
string(REPLACE ~ - PRODUCT_IDENTIFIER ${PRODUCT_IDENTIFIER})
set(BUNDLE_IDENTIFIER ${PACKAGE_REVERSE_DOMAIN}.${PRODUCT_IDENTIFIER})
add_library(${TARGET} MODULE)
set_target_properties(${TARGET} PROPERTIES
BUNDLE TRUE
BUNDLE_EXTENSION mxo
INTERPROCEDURAL_OPTIMIZATION ON
LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${OUTPUT_DIRECTORY}
MACOSX_BUNDLE_INFO_PLIST ${CURRENT_MODULE_DIR}/ExternalInfo.plist.in
MACOSX_BUNDLE_BUNDLE_NAME ${EXTERNAL_NAME}
MACOSX_BUNDLE_BUNDLE_VERSION ${PACKAGE_VERSION}
MACOSX_BUNDLE_COPYRIGHT ${PACKAGE_COPYRIGHT}
MACOSX_BUNDLE_GUI_IDENTIFIER ${BUNDLE_IDENTIFIER}
MACOSX_BUNDLE_LONG_VERSION_STRING "${EXTERNAL_NAME} ${PACKAGE_VERSION} - ${PACKAGE_COPYRIGHT}"
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PACKAGE_VERSION}
MSVC_DEBUG_INFORMATION_FORMAT ProgramDatabase
MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>
OUTPUT_NAME ${EXTERNAL_NAME}
PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>
PREFIX ""
SUFFIX .mxe64
XCODE_ATTRIBUTE_CONFIGURATION_BUILD_DIR ${OUTPUT_DIRECTORY}
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER ${BUNDLE_IDENTIFIER}
XCODE_ATTRIBUTE_PRODUCT_MODULE_NAME ${EXTERNAL_NAME}
XCODE_ATTRIBUTE_WRAPPER_EXTENSION mxo
XCODE_SCHEME_EXECUTABLE /Applications/Max.app
XCODE_SCHEME_ARGUMENTS "\"\${PROJECT_DIR}/help/${EXTERNAL_NAME}.maxhelp\""
)
if(MSVC)
target_link_options(${TARGET} PRIVATE /INCREMENTAL:NO)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
include(Max/AddSigning)
add_signing(${TARGET})
endif()
if(ARG_CUSTOM_DOCUMENTATION)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_SOURCE_DIR}/docs/${EXTERNAL_NAME}.maxref.xml
COMMENT "Touching documentation to avoid regeneration"
)
else()
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rm -rf ${CMAKE_SOURCE_DIR}/docs/${EXTERNAL_NAME}.maxref.xml
COMMENT "Removing documentation to force regeneration"
)
endif()
endfunction()