-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
153 lines (126 loc) · 4.78 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
148
149
150
151
152
153
cmake_minimum_required (VERSION 3.14)
project(pd-shmem C)
# Platform-specific and compiler-specific settings
if(MSVC)
# MSVC-specific flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /O2 /Ot /fp:fast")
else()
# GCC/Clang-specific flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -ffast-math -ffinite-math-only -finline-functions -funroll-loops")
endif()
if(APPLE)
set(platform "darwin")
elseif(LINUX)
set(platform "linux")
elseif(UNIX)
set(platform "linux")
elseif(WIN32)
set(platform "windows")
endif()
if(platform STREQUAL "windows")
set(extension "dll")
else()
set(extension "so")
endif()
if(CMAKE_GENERATOR_PLATFORM MATCHES Win32)
set(arch i386)
elseif(APPLE AND CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(arch "fat")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*arm64.*")
set(arch "arm64")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*arm.*")
set(arch "arm")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*aarch64.*")
set(arch "arm64")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*64.*")
set(arch "amd64")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*86.*")
set(arch "i386")
endif()
if(PD_FLOATSIZE64)
set(floatsize "64")
else()
set(floatsize "32")
endif()
set (PUREDATA_PLATFORM_SUFFIX "${platform}" CACHE STRING "the target platform (darwin, linux, windows) - leave empty to autodetect")
set (PUREDATA_ARCH_SUFFIX "${arch}" CACHE STRING "the target architecture (amd64, arm, arm64, i386, fat) - leave empty to autodetect")
set (PUREDATA_LIB_SUFFIX "${extension}" CACHE STRING "the dynamic library extension (so, dll) - leave empty to autodetect")
# apply with argument '-DPD_FLOATSIZE64=ON' or '-DPUREDATA_FLOATSIZE=64'
set(PUREDATA_FLOATSIZE ${floatsize} CACHE STRING "the floatsize for processing (32, 64) - the default is 32")
if(PUREDATA_FLOATSIZE STREQUAL 64)
add_definitions(-DPD_FLOATSIZE=64)
elseif(PUREDATA_FLOATSIZE STREQUAL 32)
else()
message(FATAL "FLOATSIZE must be 32 or 64")
endif()
set (PUREDATA_SUFFIX "" CACHE STRING "the external extension (.linux_amd64_64.so, .d_fat, .dll) - leave empty to autodetect (.${platform}-${arch}-${floatsize}.${extension})")
if(PUREDATA_SUFFIX STREQUAL "")
if(PUREDATA_PLATFORM_SUFFIX STREQUAL "")
message(FATAL "Could not determine target platform")
endif()
if(PUREDATA_ARCH_SUFFIX STREQUAL "")
message(FATAL "Could not determine target architecture")
endif()
set(PUREDATA_SUFFIX ".${PUREDATA_PLATFORM_SUFFIX}-${PUREDATA_ARCH_SUFFIX}-${PUREDATA_FLOATSIZE}.${PUREDATA_LIB_SUFFIX}")
# necessary exception?
if(PUREDATA_FLOATSIZE STREQUAL 32 AND APPLE AND CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(PUREDATA_SUFFIX ".d_fat")
endif()
endif()
set(PUREDATA_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/pure-data/src" CACHE PATH "Path to folder containing m_pd.h" )
if(WIN32)
set(PUREDATA_LIB "${CMAKE_SOURCE_DIR}/pure-data/bin/pd.lib" CACHE PATH "Path to pd.lib for Windows")
endif()
include_directories(${PUREDATA_INCLUDE_DIRS} ${CMAKE_BINARY_DIR})
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/package" CACHE PATH "Package destination folder" FORCE)
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang$")
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
endif()
# Get git info
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
include(git_info)
get_commit_sha(GIT_SHA)
get_commit_date(GIT_DATE)
get_tag(GIT_TAG)
configure_file("${CMAKE_SOURCE_DIR}/shmem_version.c.in" "${CMAKE_BINARY_DIR}/shmem_version.c" @ONLY)
set(SOURCES
shmem.c
)
foreach(SOURCE IN LISTS SOURCES)
message(STATUS "Processing ${SOURCE}")
get_filename_component(OBJECT_NAME ${SOURCE} NAME_WLE)
string(REPLACE "~" "_tilde" SHMEM_TARGET ${OBJECT_NAME})
add_library(${SHMEM_TARGET} SHARED ${SOURCE} shmem_version.h "${CMAKE_BINARY_DIR}/shmem_version.c")
if(WIN32)
target_link_libraries(${SHMEM_TARGET} PRIVATE "${PUREDATA_LIB}")
endif()
# set library binary file name and extension
set_target_properties(${SHMEM_TARGET}
PROPERTIES
PREFIX ""
OUTPUT_NAME "${OBJECT_NAME}"
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
DEFINE_SYMBOL "SHMEM_EXPORTS"
)
set_target_properties(${SHMEM_TARGET} PROPERTIES SUFFIX "${PUREDATA_SUFFIX}")
install(TARGETS ${SHMEM_TARGET}
DESTINATION shmem
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
install(FILES "${OBJECT_NAME}-help.pd" DESTINATION shmem)
endforeach()
include(GenerateExportHeader)
generate_export_header(shmem)
install(DIRECTORY examples/ DESTINATION shmem/examples
FILES_MATCHING PATTERN "*.pd" PATTERN "*.html")
install(FILES
LICENSE.txt
README.md
DESTINATION shmem
)