spu: don't leave garbage in capture buffers
[pcsx_rearmed.git] / deps / libchdr / CMakeLists.txt
CommitLineData
b24e7fce 1cmake_minimum_required(VERSION 3.9)
2
9e052883 3project(chdr VERSION 0.2 LANGUAGES C)
b24e7fce 4
5if(CMAKE_PROJECT_NAME STREQUAL "chdr")
6 option(BUILD_SHARED_LIBS "Build libchdr also as a shared library" ON)
7endif()
8option(INSTALL_STATIC_LIBS "Install static libraries" OFF)
9option(WITH_SYSTEM_ZLIB "Use system provided zlib library" OFF)
10
9e052883 11option(BUILD_LTO "Compile libchdr with link-time optimization if supported" OFF)
12if(BUILD_LTO)
13 include(CheckIPOSupported)
14 check_ipo_supported(RESULT HAVE_IPO)
15 if(HAVE_IPO)
16 set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
17 endif()
b24e7fce 18endif()
19
b24e7fce 20include(GNUInstallDirs)
21
b24e7fce 22#--------------------------------------------------
23# dependencies
24#--------------------------------------------------
25
26
27# lzma
9e052883 28add_subdirectory(deps/lzma-22.01 EXCLUDE_FROM_ALL)
b24e7fce 29 list(APPEND CHDR_LIBS lzma)
30 list(APPEND CHDR_INCLUDES lzma)
31
32# zlib
33if (WITH_SYSTEM_ZLIB)
9e052883 34 find_package(ZLIB REQUIRED)
35 list(APPEND PLATFORM_LIBS ZLIB::ZLIB)
b24e7fce 36else()
9e052883 37 add_subdirectory(deps/zlib-1.2.13 EXCLUDE_FROM_ALL)
38 set_target_properties(zlibstatic PROPERTIES POSITION_INDEPENDENT_CODE ON)
39 list(APPEND CHDR_LIBS zlibstatic)
40 list(APPEND CHDR_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib-1.2.13" "${CMAKE_CURRENT_BINARY_DIR}/deps/zlib-1.2.13")
b24e7fce 41endif()
42
43#--------------------------------------------------
44# chdr
45#--------------------------------------------------
46
47set(CHDR_SOURCES
48 src/libchdr_bitstream.c
49 src/libchdr_cdrom.c
50 src/libchdr_chd.c
51 src/libchdr_flac.c
52 src/libchdr_huffman.c
53)
54
55list(APPEND CHDR_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/include)
56
57add_library(chdr-static STATIC ${CHDR_SOURCES})
9e052883 58target_include_directories(chdr-static PRIVATE ${CHDR_INCLUDES} PUBLIC include)
b24e7fce 59target_link_libraries(chdr-static PRIVATE ${CHDR_LIBS} ${PLATFORM_LIBS})
60
9e052883 61if(MSVC)
62 target_compile_definitions(chdr-static PRIVATE _CRT_SECURE_NO_WARNINGS)
63endif()
64
b24e7fce 65if (INSTALL_STATIC_LIBS)
66 install(TARGETS chdr-static ${CHDR_LIBS}
67 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
68 )
69endif()
70
71if (BUILD_SHARED_LIBS)
b24e7fce 72 add_library(chdr SHARED ${CHDR_SOURCES})
9e052883 73 target_include_directories(chdr PRIVATE ${CHDR_INCLUDES} PUBLIC include)
b24e7fce 74 target_link_libraries(chdr PRIVATE ${CHDR_LIBS} ${PLATFORM_LIBS})
75
76 if(MSVC)
77 target_compile_definitions(chdr PUBLIC "CHD_DLL")
78 target_compile_definitions(chdr PRIVATE "CHD_DLL_EXPORTS")
9e052883 79 target_compile_definitions(chdr PRIVATE _CRT_SECURE_NO_WARNINGS)
b24e7fce 80 elseif(APPLE)
9e052883 81 target_link_libraries(chdr PRIVATE -Wl,-dead_strip -Wl,-exported_symbol,_chd_*)
b24e7fce 82 else()
9e052883 83 target_link_libraries(chdr PRIVATE -Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/src/link.T -Wl,--no-undefined)
b24e7fce 84 endif()
85
9e052883 86 set_target_properties(chdr PROPERTIES C_VISIBILITY_PRESET hidden)
87 set_target_properties(chdr PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
b24e7fce 88 set_target_properties(chdr PROPERTIES PUBLIC_HEADER "include/libchdr/bitstream.h;include/libchdr/cdrom.h;include/libchdr/chd.h;include/libchdr/chdconfig.h;include/libchdr/coretypes.h;include/libchdr/flac.h;include/libchdr/huffman.h")
9e052883 89 set_target_properties(chdr PROPERTIES VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" SOVERSION ${PROJECT_VERSION_MAJOR})
b24e7fce 90
91 if (CMAKE_BUILD_TYPE MATCHES Release)
92 #add_custom_command(TARGET chdr POST_BUILD COMMAND ${CMAKE_STRIP} libchdr.so)
93 endif (CMAKE_BUILD_TYPE MATCHES Release)
94
95 install(TARGETS chdr
96 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
97 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
98 PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libchdr"
99 )
100
101 configure_file(pkg-config.pc.in ${CMAKE_BINARY_DIR}/libchdr.pc @ONLY)
102 install(FILES ${CMAKE_BINARY_DIR}/libchdr.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
103endif()
104
9e052883 105add_subdirectory(tests)