1 |
cmake_minimum_required(VERSION 3.0) |
2 |
project(libgig) |
3 |
|
4 |
if(NOT MSVC) |
5 |
message(FATAL_ERROR "Please use configure and make, this cmake file is currently only to generate msvc solution files") |
6 |
endif() |
7 |
|
8 |
|
9 |
#configuration options |
10 |
set(LIBGIG_BUILD_TOOLS ON CACHE BOOL "Build the extra tools") |
11 |
set(LIBGIG_ENABLE_TESTING ON CACHE BOOL "Build the test cases") |
12 |
set(LIBGIG_BUILD_SHARED ${BUILD_SHARED_LIBS} CACHE BOOL "build dynamic libraries") |
13 |
|
14 |
set(BUILD_SHARED_LIBS ${LIBGIG_BUILD_SHARED}) |
15 |
|
16 |
if(LIBGIG_ENABLE_TESTING) |
17 |
enable_testing() |
18 |
endif() |
19 |
|
20 |
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
21 |
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
22 |
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
23 |
|
24 |
#TODO: this is written for vcpkg cppunit install |
25 |
#if you're adding other platform and package managers it's probably better to put everything in FindCppUnit.cmake |
26 |
#and replace everything here with a simple find_package(CppUnit) |
27 |
if(WIN32) |
28 |
find_path(CPPUNIT_INCLUDE_DIRS cppunit/TestFixture.h) |
29 |
find_library(CPPUNIT_LIBRARIES_DEBUG cppunitd_dll) |
30 |
find_library(CPPUNIT_LIBRARIES_RELEASE cppunit_dll) |
31 |
mark_as_advanced(CPPUNIT_INCLUDE_DIRS CPPUNIT_LIBRARIES_DEBUG CPPUNIT_LIBRARIES_RELEASE) |
32 |
|
33 |
if(CPPUNIT_LIBRARIES_DEBUG AND CPPUNIT_LIBRARIES_RELEASE AND CPPUNIT_INCLUDE_DIRS) |
34 |
set(CPPUNIT_FOUND TRUE) |
35 |
set(CPPUNIT_LIBRARIES |
36 |
$<$<CONFIG:Debug>:${CPPUNIT_LIBRARIES_DEBUG}> |
37 |
$<$<CONFIG:RelWithDebInfo>:${CPPUNIT_LIBRARIES_RELEASE}> |
38 |
$<$<CONFIG:Release>:${CPPUNIT_LIBRARIES_RELEASE}> |
39 |
$<$<CONFIG:MinSizeRel>:${CPPUNIT_LIBRARIES_RELEASE}>) |
40 |
else() |
41 |
message("cppunit not found. Testcases will not be built.") |
42 |
endif() |
43 |
endif(WIN32) |
44 |
|
45 |
if(LIBGIG_BUILD_TOOLS) |
46 |
find_package(LibSndFile) |
47 |
endif() |
48 |
|
49 |
#get version from configure.ac |
50 |
#have to make a slight detour since I cannot get the cmake regex subgroup to work with file |
51 |
file(STRINGS configure.ac VERSION_STRINGS REGEX "^m4_define\\(libgig_release.*\\)$") |
52 |
|
53 |
string(REGEX MATCH "libgig_release_major, ([^)]*)\\)" TEMP ${VERSION_STRINGS}) |
54 |
set(VERSION_MAJOR ${CMAKE_MATCH_1}) |
55 |
string(REGEX MATCH "libgig_release_minor, ([^)]*)\\)" TEMP ${VERSION_STRINGS}) |
56 |
set(VERSION_MINOR ${CMAKE_MATCH_1}) |
57 |
string(REGEX MATCH "libgig_release_build, ([^)]*)\\)" TEMP ${VERSION_STRINGS}) |
58 |
set(VERSION_BUILD ${CMAKE_MATCH_1}) |
59 |
|
60 |
set(PACKAGE_NAME "libgig") |
61 |
|
62 |
set(LIBGIG_HEADERS |
63 |
src/DLS.h |
64 |
src/gig.h |
65 |
src/RIFF.h |
66 |
src/SF.h |
67 |
src/Korg.h |
68 |
src/Serialization.h) |
69 |
|
70 |
#libgig core library |
71 |
add_library(libgig |
72 |
src/DLS.cpp |
73 |
src/gig.cpp |
74 |
src/helper.cpp |
75 |
src/Korg.cpp |
76 |
src/RIFF.cpp |
77 |
src/Serialization.cpp |
78 |
src/SF.cpp |
79 |
src/typeinfo.cpp) |
80 |
if(WIN32) |
81 |
target_sources(libgig PRIVATE win32/dllmain.cpp) |
82 |
endif() |
83 |
|
84 |
set_target_properties(libgig PROPERTIES PUBLIC_HEADER "${LIBGIG_HEADERS}") |
85 |
target_compile_definitions(libgig PRIVATE PACKAGE="${PACKAGE_NAME}" VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}") |
86 |
target_include_directories(libgig PUBLIC $<INSTALL_INTERFACE:include>) |
87 |
if(MSVC) |
88 |
target_compile_definitions(libgig PRIVATE NOMINMAX) |
89 |
endif() |
90 |
if(WIN32) |
91 |
target_link_libraries(libgig Rpcrt4.lib dbghelp.lib) |
92 |
endif() |
93 |
if(BUILD_SHARED_LIBS AND MSVC) |
94 |
set_target_properties(libgig PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
95 |
endif() |
96 |
|
97 |
#libakai library |
98 |
add_library(libakai src/Akai.cpp) |
99 |
if(WIN32) |
100 |
target_sources(libakai PRIVATE win32/dllmain.cpp) |
101 |
endif() |
102 |
set_target_properties(libakai PROPERTIES PUBLIC_HEADER src/Akai.h) |
103 |
target_include_directories(libakai PUBLIC $<INSTALL_INTERFACE:include>) |
104 |
target_compile_definitions(libakai PRIVATE PACKAGE="${PACKAGE_NAME}" VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}") |
105 |
|
106 |
if(MSVC) |
107 |
target_compile_definitions(libakai PRIVATE NOMINMAX) |
108 |
endif() |
109 |
if(BUILD_SHARED_LIBS AND MSVC) |
110 |
set_target_properties(libakai PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
111 |
endif() |
112 |
if(WIN32) |
113 |
target_link_libraries(libakai Rpcrt4.lib ) |
114 |
endif() |
115 |
|
116 |
if(CPPUNIT_FOUND AND LIBGIG_ENABLE_TESTING) |
117 |
add_subdirectory(src/testcases) |
118 |
endif() |
119 |
|
120 |
if(LIBGIG_BUILD_TOOLS) |
121 |
add_subdirectory(src/tools) |
122 |
endif(LIBGIG_BUILD_TOOLS) |
123 |
|
124 |
#installation |
125 |
#It also creates a *-config.cmake files so other cmake users can include it more easily into their projects |
126 |
install(TARGETS libgig EXPORT libgig-config |
127 |
LIBRARY DESTINATION lib |
128 |
ARCHIVE DESTINATION lib |
129 |
RUNTIME DESTINATION bin |
130 |
PUBLIC_HEADER DESTINATION include/libgig) |
131 |
install(EXPORT libgig-config NAMESPACE libgig:: DESTINATION share/libgig) |
132 |
|
133 |
install(TARGETS libakai EXPORT libakai-config |
134 |
LIBRARY DESTINATION lib |
135 |
ARCHIVE DESTINATION lib |
136 |
RUNTIME DESTINATION bin |
137 |
PUBLIC_HEADER DESTINATION include/libgig) |
138 |
install(EXPORT libakai-config NAMESPACE libgig:: DESTINATION share/libgig) |
139 |
|