This repository has been archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
135 lines (111 loc) · 4.81 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
cmake_minimum_required(VERSION 3.1)
project (finemedia)
# Some required properties
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Select build type")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_INSTALL "Install library" ON)
# Add third party libraries
include(${CMAKE_CURRENT_SOURCE_DIR}/ExternalLibs.cmake)
# Grab the files
file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/ffw/media/*.h)
# Create the library
add_definitions(-DFFW_EXPORTS)
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "fineframework/libs")
add_dependencies(${PROJECT_NAME} ZLIB)
add_dependencies(${PROJECT_NAME} LIBPNG)
add_dependencies(${PROJECT_NAME} LIBTIFF)
add_dependencies(${PROJECT_NAME} LIBJPEG)
if(UNIX OR APPLE)
add_dependencies(${PROJECT_NAME} BZIP2)
endif()
# Dependencies
include_directories(${CMAKE_SOURCE_DIR}/include)
if(MSVC)
link_directories(${CMAKE_BINARY_DIR}/Debug)
link_directories(${CMAKE_BINARY_DIR}/Release)
endif(MSVC)
if(APPLE)
target_link_libraries(${PROJECT_NAME} ${LIBPNG_LIBRARY} ${LIBJPEG_LIBRARY} ${LIBTIFF_LIBRARY} ${ZLIB_LIBRARY})
elseif(UNIX)
target_link_libraries(${PROJECT_NAME} ${LIBPNG_LIBRARY} ${LIBJPEG_LIBRARY} ${LIBTIFF_LIBRARY} ${ZLIB_LIBRARY} lzma jbig)
elseif(MSVC)
target_link_libraries(${PROJECT_NAME} ${LIBPNG_LIBRARY} ${LIBJPEG_LIBRARY} ${LIBTIFF_LIBRARY} ${ZLIB_LIBRARY})
else()
target_link_libraries(${PROJECT_NAME} ${LIBPNG_LIBRARY} ${LIBJPEG_LIBRARY} ${LIBTIFF_LIBRARY} ${ZLIB_LIBRARY})
endif()
# Additional C++ headers
include_directories(${PROJECT_NAME} PUBLIC ${LIBPNG_INCLUDE_DIR} ${LIBJPEG_INCLUDE_DIR} ${LIBTIFF_INCLUDE_DIR})
# Compile with static stdlib ?
if(STATIC_STDLIB)
target_link_libraries(${PROJECT_NAME} -static-libgcc -static-libstdc++)
endif(STATIC_STDLIB)
# Examples extra files
set(EXAMPLES_FILES owl.png)
# Add examples
if(BUILD_EXAMPLES)
foreach(FILENAME ${EXAMPLES_FILES})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/examples/${FILENAME} DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/examples/${FILENAME} DESTINATION ${CMAKE_BINARY_DIR}/examples)
endforeach(FILENAME)
file(GLOB EXAMPLES ${CMAKE_CURRENT_SOURCE_DIR}/examples/*.cpp)
foreach(FILENAME ${EXAMPLES})
# Get file name without extension
get_filename_component(FILENAME_NO_EXT ${FILENAME} NAME_WE)
set(EXAMPLE_PROJ example_${FILENAME_NO_EXT})
add_executable(${EXAMPLE_PROJ} ${FILENAME})
add_dependencies(${EXAMPLE_PROJ} ${PROJECT_NAME})
# Examples dependencies
target_link_libraries(${EXAMPLE_PROJ} finemedia)
if(MSVC)
set_target_properties(${EXAMPLE_PROJ} PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE")
endif()
# Compile with static stdlib ?
if(STATIC_STDLIB)
target_link_libraries(${EXAMPLE_PROJ} -static-libgcc -static-libstdc++)
endif(STATIC_STDLIB)
set_property(TARGET ${EXAMPLE_PROJ} PROPERTY FOLDER "fineframework/examples")
endforeach(FILENAME)
endif()
# Examples extra files
set(TESTS_FILES imgs)
# Add tests
if(BUILD_TESTS)
enable_testing ()
foreach(FILENAME ${TESTS_FILES})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tests/${FILENAME} DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tests/${FILENAME} DESTINATION ${CMAKE_BINARY_DIR}/tests)
endforeach(FILENAME)
file(GLOB TESTS ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)
foreach(FILENAME ${TESTS})
# Get file name without extension
get_filename_component(FILENAME_NO_EXT ${FILENAME} NAME_WE)
set(TEST_PROJ test_${FILENAME_NO_EXT})
add_executable(${TEST_PROJ} ${FILENAME})
add_dependencies(${TEST_PROJ} ${PROJECT_NAME})
# Tests dependencies
target_link_libraries(${TEST_PROJ} finemedia)
if(MSVC)
set_target_properties(${TEST_PROJ} PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE")
endif()
# Compile with static stdlib ?
if(STATIC_STDLIB)
target_link_libraries(${TEST_PROJ} -static-libgcc -static-libstdc++)
endif(STATIC_STDLIB)
set_property(TARGET ${TEST_PROJ} PROPERTY FOLDER "fineframework/tests")
add_test(NAME ${TEST_PROJ} COMMAND ${TEST_PROJ})
endforeach(FILENAME)
endif()
# Add install step
if(BUILD_INSTALL)
install(DIRECTORY include/ffw DESTINATION include)
if(MSVC)
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION bin OPTIONAL)
endif()
install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin COMPONENT library)
endif()