CMakeLists.txt 2.98 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1
2
3
4
project(medialibrary)

cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
5
include(cpp11)
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
6

7
8
9
10
11
12
if (UNIX)
    option(WITH_ASAN "Build with address sanitizer" OFF)
    option(WITH_TSAN "Build with thread sanitizer" OFF)
    option(WITH_UBSAN "Build with undefined behavior sanitizer" OFF)
endif()

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Fetch gtest
ExternalProject_Add(
    gtest-dependency
    SVN_REPOSITORY http://googletest.googlecode.com/svn/trunk/
    TIMEOUT 10
    # Disable install step
    INSTALL_COMMAND ""
    UPDATE_COMMAND ""
    # Wrap download, configure and build steps in a script to log output
    LOG_DOWNLOAD ON
    LOG_CONFIGURE ON
    LOG_BUILD ON
)

ExternalProject_Get_Property(gtest-dependency source_dir)
include_directories(${source_dir}/include)
# Also link with gtest:
# fetch the directory which contains the built libraries (gtest & gtest_main)
ExternalProject_Get_Property(gtest-dependency binary_dir)
link_directories(${binary_dir})

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
34
EnableCpp11()
35
36
add_definitions("-Wall -Wextra -pedantic")

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
37
include_directories(${CMAKE_SOURCE_DIR}/include)
38
include_directories(${CMAKE_SOURCE_DIR}/src)
39
include_directories(${CMAKE_SOURCE_DIR}/test)
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
40
include_directories(${LIBVLC_INCLUDE_DIR})
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
41
42

list(APPEND TEST_SRCS
43
44
45
46
47
48
49
50
51
52
53
54
55
    unittest/MediaTests.cpp
    unittest/Folders.cpp
    unittest/Labels.cpp
    unittest/Albums.cpp
    unittest/Tests.cpp
    unittest/Shows.cpp
    unittest/Movies.cpp
    unittest/VideoTracks.cpp
    unittest/AudioTracks.cpp
    unittest/VLCMetadataServices.cpp
    unittest/FsUtilsTests.cpp
    unittest/ArtistTests.cpp
    unittest/AlbumTrackTests.cpp
56
57

    mocks/FileSystem.h
58
    mocks/DiscovererCbMock.h
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
59
60
61
62
63
64
65
)

add_executable(unittest ${TEST_SRCS})
add_dependencies(unittest gtest-dependency)

target_link_libraries(unittest medialibrary)
target_link_libraries(unittest gtest gtest_main)
66
include_directories(${LIBVLCPP_DIR})
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
67
68
69
# Also add pthread, as gtest requires it
if(UNIX)
    target_link_libraries(unittest "pthread")
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

    if(${WITH_ASAN})
        if(${WITH_TSAN} OR ${WITH_UBSAN})
            message(SEND_ERROR "Sanitizers are mutually exclusive")
        endif()
        add_definitions("-fsanitize=address -fno-omit-frame-pointer")
        target_link_libraries(unittest "asan")
    endif()

    if(${WITH_TSAN})
        if(${WITH_ASAN} OR ${WITH_UBSAN})
            message(SEND_ERROR "Sanitizers are mutually exclusive")
        endif()
        add_definitions("-fsanitize=thread -fno-omit-frame-pointer")
        target_link_libraries(unittest "tsan")
    endif()

    if(${WITH_UBSAN})
        if(${WITH_ASAN} OR ${WITH_TSAN})
            message(SEND_ERROR "Sanitizers are mutually exclusive")
        endif()
        add_definitions("-fsanitize=undefined -fno-omit-frame-pointer")
        target_link_libraries(unittest "ubsan")
    endif()
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
94
endif()
95
96
97

## Download files for parsing unit tests
file(DOWNLOAD "http://streams.videolan.org/streams/mp3/05-Mr.%20Zebra.mp3" "${CMAKE_CURRENT_BINARY_DIR}/mr-zebra.mp3")
98
file(DOWNLOAD "http://streams.videolan.org/streams/mp4/Mr_MrsSmith-h264_aac.mp4" "${CMAKE_CURRENT_BINARY_DIR}/mrmssmith.mp4")