forked from rtissera/libchdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
125 lines (102 loc) · 4.13 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
cmake_minimum_required(VERSION 3.9)
project(chdr C)
set(CHDR_VERSION_MAJOR 0)
set(CHDR_VERSION_MINOR 1)
option(BUILD_SHARED_LIBS "Build libchdr also as a shared library" ON)
option(INSTALL_STATIC_LIBS "Install static libraries" OFF)
option(WITH_SYSTEM_ZLIB "Use system provided zlib library" OFF)
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fPIC -O3 -flto")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
endif()
include(FindPkgConfig)
include(GNUInstallDirs)
# Detect processor type.
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
set(CPU_ARCH "x64")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
# MSVC x86/x64
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CPU_ARCH "x64")
else()
set(CPU_ARCH "x86")
endif()
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386" OR
${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
set(CPU_ARCH "x86")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set(CPU_ARCH "aarch64")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
set(CPU_ARCH "arm")
else()
message(FATAL_ERROR "Unknown system processor: " ${CMAKE_SYSTEM_PROCESSOR})
endif()
#--------------------------------------------------
# dependencies
#--------------------------------------------------
# lzma
add_subdirectory(deps/lzma-19.00 EXCLUDE_FROM_ALL)
list(APPEND CHDR_LIBS lzma)
list(APPEND CHDR_INCLUDES lzma)
# zlib
if (WITH_SYSTEM_ZLIB)
pkg_check_modules(ZLIB REQUIRED zlib)
list(APPEND PLATFORM_INCLUDES ${ZLIB_INCLUDE_DIRS})
list(APPEND PLATFORM_LIBS ${ZLIB_LIBRARIES})
else()
add_subdirectory(deps/zlib-1.2.11 EXCLUDE_FROM_ALL)
list(APPEND CHDR_LIBS zlib)
list(APPEND CHDR_INCLUDES zlib)
endif()
#--------------------------------------------------
# chdr
#--------------------------------------------------
set(CHDR_SOURCES
src/libchdr_bitstream.c
src/libchdr_cdrom.c
src/libchdr_chd.c
src/libchdr_flac.c
src/libchdr_huffman.c
)
list(APPEND CHDR_INCLUDES include ${CMAKE_CURRENT_BINARY_DIR}/include)
add_library(chdr-static STATIC ${CHDR_SOURCES})
target_include_directories(chdr-static PRIVATE ${CHDR_INCLUDES} ${PLATFORM_INCLUDES})
target_compile_definitions(chdr-static PRIVATE ${CHDR_DEFS})
target_link_libraries(chdr-static ${CHDR_LIBS} ${PLATFORM_LIBS})
if (INSTALL_STATIC_LIBS)
install(TARGETS chdr-static ${CHDR_LIBS}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()
if (BUILD_SHARED_LIBS)
set(LIBS ${PLATFORM_LIBS})
list(TRANSFORM LIBS PREPEND "-l")
list(JOIN LIBS " " LIBS)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
add_library(chdr SHARED ${CHDR_SOURCES})
target_include_directories(chdr PRIVATE ${CHDR_INCLUDES} ${PLATFORM_INCLUDES})
target_compile_definitions(chdr PRIVATE ${CHDR_DEFS})
target_link_libraries(chdr ${CHDR_LIBS} ${PLATFORM_LIBS})
if(MSVC)
target_compile_definitions(chdr PUBLIC "CHD_DLL")
target_compile_definitions(chdr PRIVATE "CHD_DLL_EXPORTS")
else()
target_link_options(chdr PRIVATE -Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/src/link.T -Wl,--no-undefined)
endif()
set_target_properties(chdr PROPERTIES PUBLIC_HEADER "include/libchdr/bitstream.h;include/libchdr/cdrom.h;include/libchdr/chd.h;include/libchdr/coretypes.h;include/libchdr/flac.h;include/libchdr/huffman.h")
set_target_properties(chdr PROPERTIES VERSION "${CHDR_VERSION_MAJOR}.${CHDR_VERSION_MINOR}")
if (CMAKE_BUILD_TYPE MATCHES Release)
#add_custom_command(TARGET chdr POST_BUILD COMMAND ${CMAKE_STRIP} libchdr.so)
endif (CMAKE_BUILD_TYPE MATCHES Release)
install(TARGETS chdr
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libchdr"
)
configure_file(pkg-config.pc.in ${CMAKE_BINARY_DIR}/libchdr.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/libchdr.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()