aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 040b4e28c0eca0da3cdf7061e8e9d165c5dcf763 (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
project("csound_jstick")

cmake_minimum_required(VERSION 3.8)

set(APIVERSION "6.0")

# Release or Debug
set(CMAKE_BUILD_TYPE "Release")

# force make to print the command lines
set(CMAKE_VERBOSE_MAKEFILE on)

# path to Csound cmake module
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# set compilation flags
set(CMAKE_CXX_FLAGS  ${CMAKE_CXX_FLAGS}  "-std=c++11 -fpermissive -fPIC -w -DUSE_DOUBLE -DB64BIT")

# options
option(USE_LIB64 "Set to on to set installation dir for libs to lib64" OFF)
option(USE_DOUBLE "Use doubles for audio calculations" ON)
option(CPP11 "c++11" ON)

set(BUILDING_CSOUND_PLUGINS ON)

# ----------------------------------------------

include(FindCsound)

include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

# -----------------------------------------------

function(addflag flag flagname)
  check_c_compiler_flag(${flag} ${flagname})
  if (${flagname})
    # message(STATUS "Setting C flag ${flag}")    
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
  endif()
  check_cxx_compiler_flag(${flag} CXX_${flagname})
  if (CXX_${flagname})
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
  endif()
endfunction(addflag)


# set optimization flags
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
  add_definitions(-fvisibility=hidden)
  if(NATIVE)
	add_definitions(-march=native)
  endif()
  
  include(CheckCCompilerFlag)
  include(CheckCXXCompilerFlag)

  addflag(-msse HAS_SSE)
  addflag(-msse2 HAS_SSE2)
  addflag(-mfgpath=sse HAS_FPMATH_SSE)
  
endif()

if(MINGW)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstackrealign")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign")
endif()

addflag(-ftree-vectorize HAS_TREE_VECTORIZE)
addflag(-ffast-math HAS_FAST_MATH)
addflag(-fomit-frame-pointer HAS_OMIT_FRAME_POINTER)


# -------------------------------------------------------------------

set(CS_FRAMEWORK_DEST "~/Library/Frameworks")


if(USE_LIB64)
  set(LIBRARY_INSTALL_DIR "lib64")
  add_definitions("-DLIB64")
else()
  set(LIBRARY_INSTALL_DIR "lib")
endif()

message(STATUS "LIBRARY INSTALL DIR: ${LIBRARY_INSTALL_DIR}")

# -------------------------------------------------------------------


if(USE_DOUBLE)
  message(STATUS ">>> using doubles")
  
  if(APPLE)
    set(CSOUNDLIB "CsoundLib64")
    set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes64")
  else()
    set(CSOUNDLIB "csound64")
    set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins64-${APIVERSION}")
  endif()
else()
  message(STATUS ">>> not using doubles")
  if(APPLE)
    set(CSOUNDLIB "CsoundLib")
    set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes")
  else()
    set(CSOUNDLIB "csound")
    set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins-${APIVERSION}")
  endif()
endif()


# -------------------------------------------------------------------
  
# Csound opcode build
find_package(Csound)


set(BUILD_PLUGINS_DIR ${CMAKE_CURRENT_BINARY_DIR})

if(NOT CSOUND_FOUND)
  message(FATAL_ERROR "Csound installation not found")
endif()


set(CPPFILES src/opcodes.cpp src/joystick.cpp)


add_library(jstick SHARED ${CPPFILES})
include_directories(${CSOUND_INCLUDE_DIRS})
include_directories(include)


set_target_properties(jstick PROPERTIES
  RUNTIME_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR}
  LIBRARY_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR})
 
install(TARGETS jstick LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" )