forked from Yikai-Liao/symusic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
140 lines (118 loc) · 4.79 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
cmake_minimum_required(VERSION 3.20)
project(symusic)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15)
option(BUILD_SYMUSIC_PY "Build the python binding of symusic" OFF)
option(BUILD_SYMUSIC_EXAMPLE "Build the test target" OFF)
option(BUILD_SYMUSIC_TEST "Build the test target" OFF)
option(ENABLE_LTO "Enables link-time optimization, requires compiler support." ON)
option(VTUNE "Compile Options for Intel VTune" Off)
# set /utf-8 for MSVC
if(MSVC)
add_compile_options(-bigobj)
add_compile_options(/utf-8)
endif()
add_subdirectory(3rdparty/fmt EXCLUDE_FROM_ALL)
add_subdirectory(3rdparty/minimidi EXCLUDE_FROM_ALL)
add_subdirectory(3rdparty/prestosynth EXCLUDE_FROM_ALL)
add_subdirectory(3rdparty/pyvec EXCLUDE_FROM_ALL)
include_directories(include)
include_directories(3rdparty/pdqsort)
include_directories(3rdparty/zpp_bits)
include_directories(3rdparty)
file(GLOB_RECURSE symusic_src src/*.cpp src/io/*.cpp)
foreach(src_file ${symusic_src})
message(STATUS "symusic_src: ${src_file}")
endforeach()
add_library(symusic ${symusic_src})
target_link_libraries(symusic fmt::fmt-header-only)
target_link_libraries(symusic minimidi)
target_link_libraries(symusic prestosynth)
target_link_libraries(symusic pyvec)
if(BUILD_SYMUSIC_PY)
message("Building python binding.")
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
# set symusic target to O3 and release mode because nanobind use minisize
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")
find_package(nanobind CONFIG REQUIRED)
# show python executable path
message(STATUS "Python_EXECUTABLE: ${Python_EXECUTABLE}")
find_package(nanobind CONFIG REQUIRED)
nanobind_add_module(core NOMINSIZE py_src/core.cpp py_src/py_utils.h py_src/bind_vector_copy.h)
target_link_libraries(core PRIVATE symusic)
install(TARGETS core LIBRARY DESTINATION symusic)
# install abc2midi and midi2abc
add_subdirectory(3rdparty/abcmidi)
install(TARGETS abc2midi midi2abc DESTINATION symusic/bin)
endif()
if(BUILD_SYMUSIC_EXAMPLE)
add_subdirectory(./3rdparty/nanobench EXCLUDE_FROM_ALL)
add_executable(note_count examples/cpp/note_count.cpp)
add_executable(dump examples/cpp/dump.cpp)
add_executable(io_bench examples/cpp/io_bench.cpp)
add_executable(synth examples/cpp/synth.cpp)
add_executable(adjust_time examples/cpp/adjust_time.cpp)
target_link_libraries(note_count PRIVATE symusic)
target_link_libraries(dump PRIVATE symusic)
target_link_libraries(io_bench PRIVATE symusic nanobench)
target_link_libraries(synth PUBLIC symusic)
target_link_libraries(adjust_time PUBLIC symusic)
endif()
if(BUILD_SYMUSIC_TEST)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0 # or a later release
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
add_executable(symusic_test tests/cpp/test_main.cpp)
target_include_directories(symusic_test PRIVATE tests/cpp)
target_link_libraries(symusic_test PRIVATE Catch2::Catch2WithMain symusic)
include(CTest)
include(Catch)
enable_testing()
add_test(
NAME symusic_ctest
COMMAND $<TARGET_FILE:symusic_test> --success
)
endif()
if (ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT has_lto OUTPUT lto_check_output)
if(has_lto)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "Clang detected, use -fuse-ld=lld")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
endif ()
message(STATUS "Link-time optimization (LTO) enabled")
set_property(TARGET symusic PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
if(BUILD_SYMUSIC_PY)
set_property(TARGET core PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
else()
message(WARNING "Link-time optimization (LTO) is not supported: \n${lto_check_output}")
endif()
endif()
# enable parallel compilation for MSVC
if(MSVC)
message(STATUS "MSVC parallel compilation enabled")
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/Gm->)
cmake_host_system_information(RESULT CPU_NUMBER_OF_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP${CPU_NUMBER_OF_LOGICAL_CORES}>)
endif()
if(VTUNE)
message(STATUS "VTune enabled")
if(MSVC)
add_compile_options(/Zi)
add_compile_options(/MDd)
add_compile_options(/D "TBB_USE_THREADING_TOOLS")
else()
add_compile_options(-g)
endif ()
endif ()