aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 21be30ddc7d3522f149687336cb94aa1015150f3 (plain)
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
cmake_minimum_required(VERSION 2.8)

project(canvas.lv2)

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/pugl)
include_directories(${PROJECT_SOURCE_DIR}/ardour.lv2)

set(CMAKE_FIND_FRAMEWORK FIRST)

set(CMAKE_C_FLAGS "-fdata-sections -ffunction-sections ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-std=gnu11 -Wextra -Wno-unused-parameter -ffast-math -fvisibility=hidden ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-Wshadow -Wimplicit-function-declaration -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes ${CMAKE_C_FLAGS}")

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
	set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-z,defs ${CMAKE_MODULE_LINKER_FLAGS}")
	set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-z,nodelete ${CMAKE_MODULE_LINKER_FLAGS}")
elseif(WIN32)
	set(CMAKE_C_FLAGS "-mstackrealign ${CMAKE_C_FLAGS}")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
	if(APPLE)
		set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-dead_strip ${CMAKE_MODULE_LINKER_FLAGS}")
	else()
		set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--gc-sections -Wl,-s ${CMAKE_MODULE_LINKER_FLAGS}")
	endif()
endif()

add_definitions("-D_GNU_SOURCE=1") # asprintf

if(WIN32)
	set(CANVAS_UI_TYPE "WindowsUI")
elseif(APPLE)
	set(CANVAS_UI_TYPE "CocoaUI")
else()
	set(CANVAS_UI_TYPE "X11UI")
endif()

file(STRINGS "VERSION" CANVAS_VERSION)
string(REPLACE "." ";" VERSION_LIST ${CANVAS_VERSION})
list(GET VERSION_LIST 0 CANVAS_MAJOR_VERSION)
list(GET VERSION_LIST 1 CANVAS_MINOR_VERSION)
list(GET VERSION_LIST 2 CANVAS_MICRO_VERSION)
add_definitions("-DCANVAS_VERSION=\"${CANVAS_VERSION}\"")

if(NOT DEFINED PLUGIN_DEST)
	set(PLUGIN_DEST lib/lv2/canvas.lv2)
endif()

find_package(PkgConfig) # ${PKG_CONFIG_FOUND}

set(LIBS m)
set(LIBS_UI m)
set(TAR_UI test/canvas_ui.c)

pkg_search_module(LV2 REQUIRED lv2>=1.10)
include_directories(${LV2_INCLUDE_DIRS})

pkg_search_module(CAIRO REQUIRED cairo>=1.14)
include_directories(${CAIRO_INCLUDE_DIRS})
if(DEFINED STATIC_CAIRO)
	set(LIBS ${STATIC_CAIRO} ${STATIC_PIXMAN} ${LIBS})
	set(LIBS_UI ${STATIC_CAIRO} ${STATIC_PIXMAN} ${LIBS})

	if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
		set(LIBS ${LIBS} pthread)
		set(LIBS_UI ${LIBS_UI} pthread)
	endif()
else()
	set(LIBS ${LIBS} ${CAIRO_LDFLAGS})
	set(LIBS_UI ${LIBS_UI} ${CAIRO_LDFLAGS})
endif()
add_definitions("-DPUGL_HAVE_CAIRO")

find_package(OpenGL)
if(${OPENGL_FOUND})
	set(LIBS_UI ${LIBS_UI} ${OPENGL_LIBRARIES})
	add_definitions("-DPUGL_HAVE_GL")
else()
	message(STATUS "OpenGL not found")
endif()

if(WIN32)
	find_library(GDI32_LIBRARY NAMES gdi32)
	if(GDI32_LIBRARY)
		set(LIBS_UI ${LIBS_UI} ${GDI32_LIBRARY})
	else()
		message(FATAL_ERROR "gdi32 library not found")
	endif()

	find_library(USER32_LIBRARY NAMES user32)
	if(USER32_LIBRARY)
		set(LIBS_UI ${LIBS_UI} ${USER32_LIBRARY})
	else()
		message(FATAL_ERROR "user32 library not found")
	endif()

	set(TAR_UI ${TAR_UI} pugl/pugl/pugl_win.cpp)

elseif(APPLE)
	find_library(COCOA_LIBRARY NAMES Cocoa)
	if(COCOA_LIBRARY)
		set(LIBS_UI ${LIBS_UI} ${COCOA_LIBRARY})
	else()
		message(FATAL_ERROR "Cocoa framework not found")
	endif()

	set(TAR_UI ${TAR_UI} pugl/pugl/pugl_osx.m)

else() # GNU/Linux
	pkg_search_module(X11 REQUIRED x11>=1.6)
	include_directories(${X11_INCLUDE_DIRS})
	set(LIBS_UI ${LIBS_UI} ${X11_LDFLAGS})

	pkg_search_module(XEXT REQUIRED xext>=1.3)
	include_directories(${XEXT_INCLUDE_DIRS})
	set(LIBS_UI ${LIBS_UI} ${XEXT_LDFLAGS})

	set(TAR_UI ${TAR_UI} pugl/pugl/pugl_x11.c)
endif()

add_library(canvas MODULE test/canvas.c)
target_link_libraries(canvas ${LIBS})
set_target_properties(canvas PROPERTIES PREFIX "")
set_target_properties(canvas PROPERTIES INTERPROCEDURAL_OPTIMIZATION true) # -flto
if(NOT WIN32)
set_target_properties(canvas PROPERTIES LINK_FLAGS "-Wl,-e,lv2_descriptor")
endif()
install(TARGETS canvas DESTINATION ${PLUGIN_DEST})

add_library(canvas_ui MODULE ${TAR_UI})
target_link_libraries(canvas_ui ${LIBS_UI})
set_target_properties(canvas_ui PROPERTIES PREFIX "")
set_target_properties(canvas_ui PROPERTIES INTERPROCEDURAL_OPTIMIZATION true) # -flto
if(NOT WIN32)
set_target_properties(canvas_ui PROPERTIES LINK_FLAGS "-Wl,-e,lv2ui_descriptor")
endif()
install(TARGETS canvas_ui DESTINATION ${PLUGIN_DEST})

configure_file(${PROJECT_SOURCE_DIR}/test/manifest.ttl.in ${PROJECT_BINARY_DIR}/manifest.ttl)
install(FILES ${PROJECT_BINARY_DIR}/manifest.ttl DESTINATION ${PLUGIN_DEST})
install(FILES ${PROJECT_SOURCE_DIR}/test/canvas.ttl DESTINATION ${PLUGIN_DEST})
install(FILES ${PROJECT_SOURCE_DIR}/test/canvas_ui.ttl DESTINATION ${PLUGIN_DEST})