1*09537850SAkhilesh Sanikop# Copyright 2019 The libgav1 Authors 2*09537850SAkhilesh Sanikop# 3*09537850SAkhilesh Sanikop# Licensed under the Apache License, Version 2.0 (the "License"); 4*09537850SAkhilesh Sanikop# you may not use this file except in compliance with the License. 5*09537850SAkhilesh Sanikop# You may obtain a copy of the License at 6*09537850SAkhilesh Sanikop# 7*09537850SAkhilesh Sanikop# http://www.apache.org/licenses/LICENSE-2.0 8*09537850SAkhilesh Sanikop# 9*09537850SAkhilesh Sanikop# Unless required by applicable law or agreed to in writing, software 10*09537850SAkhilesh Sanikop# distributed under the License is distributed on an "AS IS" BASIS, 11*09537850SAkhilesh Sanikop# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*09537850SAkhilesh Sanikop# See the License for the specific language governing permissions and 13*09537850SAkhilesh Sanikop# limitations under the License. 14*09537850SAkhilesh Sanikop 15*09537850SAkhilesh Sanikopif(LIBGAV1_CMAKE_GAV1_TARGETS_CMAKE_) 16*09537850SAkhilesh Sanikop return() 17*09537850SAkhilesh Sanikopendif() # LIBGAV1_CMAKE_GAV1_TARGETS_CMAKE_ 18*09537850SAkhilesh Sanikopset(LIBGAV1_CMAKE_GAV1_TARGETS_CMAKE_ 1) 19*09537850SAkhilesh Sanikop 20*09537850SAkhilesh Sanikopif(LIBGAV1_IDE_FOLDER) 21*09537850SAkhilesh Sanikop set(LIBGAV1_EXAMPLES_IDE_FOLDER "${LIBGAV1_IDE_FOLDER}/examples") 22*09537850SAkhilesh Sanikop set(LIBGAV1_TESTS_IDE_FOLDER "${LIBGAV1_IDE_FOLDER}/tests") 23*09537850SAkhilesh Sanikopelse() 24*09537850SAkhilesh Sanikop set(LIBGAV1_EXAMPLES_IDE_FOLDER "libgav1_examples") 25*09537850SAkhilesh Sanikop set(LIBGAV1_TESTS_IDE_FOLDER "libgav1_tests") 26*09537850SAkhilesh Sanikopendif() 27*09537850SAkhilesh Sanikop 28*09537850SAkhilesh Sanikop# Resets list variables used to track libgav1 targets. 29*09537850SAkhilesh Sanikopmacro(libgav1_reset_target_lists) 30*09537850SAkhilesh Sanikop unset(libgav1_targets) 31*09537850SAkhilesh Sanikop unset(libgav1_exe_targets) 32*09537850SAkhilesh Sanikop unset(libgav1_lib_targets) 33*09537850SAkhilesh Sanikop unset(libgav1_objlib_targets) 34*09537850SAkhilesh Sanikop unset(libgav1_sources) 35*09537850SAkhilesh Sanikop unset(libgav1_test_targets) 36*09537850SAkhilesh Sanikopendmacro() 37*09537850SAkhilesh Sanikop 38*09537850SAkhilesh Sanikop# Creates an executable target. The target name is passed as a parameter to the 39*09537850SAkhilesh Sanikop# NAME argument, and the sources passed as a parameter to the SOURCES argument: 40*09537850SAkhilesh Sanikop# libgav1_add_executable(NAME <name> SOURCES <sources> [optional args]) 41*09537850SAkhilesh Sanikop# 42*09537850SAkhilesh Sanikop# Optional args: 43*09537850SAkhilesh Sanikop# cmake-format: off 44*09537850SAkhilesh Sanikop# - OUTPUT_NAME: Override output file basename. Target basename defaults to 45*09537850SAkhilesh Sanikop# NAME. 46*09537850SAkhilesh Sanikop# - TEST: Flag. Presence means treat executable as a test. 47*09537850SAkhilesh Sanikop# - DEFINES: List of preprocessor macro definitions. 48*09537850SAkhilesh Sanikop# - INCLUDES: list of include directories for the target. 49*09537850SAkhilesh Sanikop# - COMPILE_FLAGS: list of compiler flags for the target. 50*09537850SAkhilesh Sanikop# - LINK_FLAGS: List of linker flags for the target. 51*09537850SAkhilesh Sanikop# - OBJLIB_DEPS: List of CMake object library target dependencies. 52*09537850SAkhilesh Sanikop# - LIB_DEPS: List of CMake library dependencies. 53*09537850SAkhilesh Sanikop# cmake-format: on 54*09537850SAkhilesh Sanikop# 55*09537850SAkhilesh Sanikop# Sources passed to this macro are added to $libgav1_test_sources when TEST is 56*09537850SAkhilesh Sanikop# specified. Otherwise sources are added to $libgav1_sources. 57*09537850SAkhilesh Sanikop# 58*09537850SAkhilesh Sanikop# Targets passed to this macro are always added $libgav1_targets. When TEST is 59*09537850SAkhilesh Sanikop# specified targets are also added to list $libgav1_test_targets. Otherwise 60*09537850SAkhilesh Sanikop# targets are added to $libgav1_exe_targets. 61*09537850SAkhilesh Sanikopmacro(libgav1_add_executable) 62*09537850SAkhilesh Sanikop unset(exe_TEST) 63*09537850SAkhilesh Sanikop unset(exe_TEST_DEFINES_MAIN) 64*09537850SAkhilesh Sanikop unset(exe_NAME) 65*09537850SAkhilesh Sanikop unset(exe_OUTPUT_NAME) 66*09537850SAkhilesh Sanikop unset(exe_SOURCES) 67*09537850SAkhilesh Sanikop unset(exe_DEFINES) 68*09537850SAkhilesh Sanikop unset(exe_INCLUDES) 69*09537850SAkhilesh Sanikop unset(exe_COMPILE_FLAGS) 70*09537850SAkhilesh Sanikop unset(exe_LINK_FLAGS) 71*09537850SAkhilesh Sanikop unset(exe_OBJLIB_DEPS) 72*09537850SAkhilesh Sanikop unset(exe_LIB_DEPS) 73*09537850SAkhilesh Sanikop set(optional_args TEST) 74*09537850SAkhilesh Sanikop set(single_value_args NAME OUTPUT_NAME) 75*09537850SAkhilesh Sanikop set(multi_value_args SOURCES DEFINES INCLUDES COMPILE_FLAGS LINK_FLAGS 76*09537850SAkhilesh Sanikop OBJLIB_DEPS LIB_DEPS) 77*09537850SAkhilesh Sanikop 78*09537850SAkhilesh Sanikop cmake_parse_arguments(exe "${optional_args}" "${single_value_args}" 79*09537850SAkhilesh Sanikop "${multi_value_args}" ${ARGN}) 80*09537850SAkhilesh Sanikop 81*09537850SAkhilesh Sanikop if(LIBGAV1_VERBOSE GREATER 1) 82*09537850SAkhilesh Sanikop message("--------- libgav1_add_executable ---------\n" 83*09537850SAkhilesh Sanikop "exe_TEST=${exe_TEST}\n" 84*09537850SAkhilesh Sanikop "exe_TEST_DEFINES_MAIN=${exe_TEST_DEFINES_MAIN}\n" 85*09537850SAkhilesh Sanikop "exe_NAME=${exe_NAME}\n" 86*09537850SAkhilesh Sanikop "exe_OUTPUT_NAME=${exe_OUTPUT_NAME}\n" 87*09537850SAkhilesh Sanikop "exe_SOURCES=${exe_SOURCES}\n" 88*09537850SAkhilesh Sanikop "exe_DEFINES=${exe_DEFINES}\n" 89*09537850SAkhilesh Sanikop "exe_INCLUDES=${exe_INCLUDES}\n" 90*09537850SAkhilesh Sanikop "exe_COMPILE_FLAGS=${exe_COMPILE_FLAGS}\n" 91*09537850SAkhilesh Sanikop "exe_LINK_FLAGS=${exe_LINK_FLAGS}\n" 92*09537850SAkhilesh Sanikop "exe_OBJLIB_DEPS=${exe_OBJLIB_DEPS}\n" 93*09537850SAkhilesh Sanikop "exe_LIB_DEPS=${exe_LIB_DEPS}\n" 94*09537850SAkhilesh Sanikop "------------------------------------------\n") 95*09537850SAkhilesh Sanikop endif() 96*09537850SAkhilesh Sanikop 97*09537850SAkhilesh Sanikop if(NOT (exe_NAME AND exe_SOURCES)) 98*09537850SAkhilesh Sanikop message(FATAL_ERROR "libgav1_add_executable: NAME and SOURCES required.") 99*09537850SAkhilesh Sanikop endif() 100*09537850SAkhilesh Sanikop 101*09537850SAkhilesh Sanikop list(APPEND libgav1_targets ${exe_NAME}) 102*09537850SAkhilesh Sanikop if(exe_TEST) 103*09537850SAkhilesh Sanikop list(APPEND libgav1_test_targets ${exe_NAME}) 104*09537850SAkhilesh Sanikop list(APPEND libgav1_test_sources ${exe_SOURCES}) 105*09537850SAkhilesh Sanikop else() 106*09537850SAkhilesh Sanikop list(APPEND libgav1_exe_targets ${exe_NAME}) 107*09537850SAkhilesh Sanikop list(APPEND libgav1_sources ${exe_SOURCES}) 108*09537850SAkhilesh Sanikop endif() 109*09537850SAkhilesh Sanikop 110*09537850SAkhilesh Sanikop add_executable(${exe_NAME} ${exe_SOURCES}) 111*09537850SAkhilesh Sanikop if(exe_TEST) 112*09537850SAkhilesh Sanikop add_test(NAME ${exe_NAME} COMMAND ${exe_NAME}) 113*09537850SAkhilesh Sanikop set_property(TARGET ${exe_NAME} PROPERTY FOLDER ${LIBGAV1_TESTS_IDE_FOLDER}) 114*09537850SAkhilesh Sanikop else() 115*09537850SAkhilesh Sanikop set_property(TARGET ${exe_NAME} 116*09537850SAkhilesh Sanikop PROPERTY FOLDER ${LIBGAV1_EXAMPLES_IDE_FOLDER}) 117*09537850SAkhilesh Sanikop endif() 118*09537850SAkhilesh Sanikop 119*09537850SAkhilesh Sanikop if(exe_OUTPUT_NAME) 120*09537850SAkhilesh Sanikop set_target_properties(${exe_NAME} PROPERTIES OUTPUT_NAME ${exe_OUTPUT_NAME}) 121*09537850SAkhilesh Sanikop endif() 122*09537850SAkhilesh Sanikop 123*09537850SAkhilesh Sanikop libgav1_process_intrinsics_sources(TARGET ${exe_NAME} SOURCES ${exe_SOURCES}) 124*09537850SAkhilesh Sanikop 125*09537850SAkhilesh Sanikop if(exe_DEFINES) 126*09537850SAkhilesh Sanikop target_compile_definitions(${exe_NAME} PRIVATE ${exe_DEFINES}) 127*09537850SAkhilesh Sanikop endif() 128*09537850SAkhilesh Sanikop 129*09537850SAkhilesh Sanikop if(exe_INCLUDES) 130*09537850SAkhilesh Sanikop target_include_directories(${exe_NAME} PRIVATE ${exe_INCLUDES}) 131*09537850SAkhilesh Sanikop endif() 132*09537850SAkhilesh Sanikop 133*09537850SAkhilesh Sanikop unset(exe_LIBGAV1_COMPILE_FLAGS) 134*09537850SAkhilesh Sanikop if(exe_TEST) 135*09537850SAkhilesh Sanikop list(FILTER exe_SOURCES INCLUDE REGEX "\\.c$") 136*09537850SAkhilesh Sanikop list(LENGTH exe_SOURCES exe_SOURCES_length) 137*09537850SAkhilesh Sanikop if(exe_SOURCES_length EQUAL 0) 138*09537850SAkhilesh Sanikop set(exe_LIBGAV1_COMPILE_FLAGS ${LIBGAV1_TEST_CXX_FLAGS}) 139*09537850SAkhilesh Sanikop else() 140*09537850SAkhilesh Sanikop set(exe_LIBGAV1_COMPILE_FLAGS ${LIBGAV1_TEST_C_FLAGS}) 141*09537850SAkhilesh Sanikop endif() 142*09537850SAkhilesh Sanikop else() 143*09537850SAkhilesh Sanikop set(exe_LIBGAV1_COMPILE_FLAGS ${LIBGAV1_CXX_FLAGS}) 144*09537850SAkhilesh Sanikop endif() 145*09537850SAkhilesh Sanikop 146*09537850SAkhilesh Sanikop if(exe_COMPILE_FLAGS OR exe_LIBGAV1_COMPILE_FLAGS) 147*09537850SAkhilesh Sanikop target_compile_options(${exe_NAME} 148*09537850SAkhilesh Sanikop PRIVATE ${exe_COMPILE_FLAGS} 149*09537850SAkhilesh Sanikop ${exe_LIBGAV1_COMPILE_FLAGS}) 150*09537850SAkhilesh Sanikop endif() 151*09537850SAkhilesh Sanikop 152*09537850SAkhilesh Sanikop if(exe_LINK_FLAGS OR LIBGAV1_EXE_LINKER_FLAGS) 153*09537850SAkhilesh Sanikop list(APPEND exe_LINK_FLAGS "${LIBGAV1_EXE_LINKER_FLAGS}") 154*09537850SAkhilesh Sanikop if(${CMAKE_VERSION} VERSION_LESS "3.13") 155*09537850SAkhilesh Sanikop # LINK_FLAGS is managed as a string. 156*09537850SAkhilesh Sanikop libgav1_set_and_stringify(SOURCE "${exe_LINK_FLAGS}" DEST exe_LINK_FLAGS) 157*09537850SAkhilesh Sanikop set_target_properties(${exe_NAME} 158*09537850SAkhilesh Sanikop PROPERTIES LINK_FLAGS "${exe_LINK_FLAGS}") 159*09537850SAkhilesh Sanikop else() 160*09537850SAkhilesh Sanikop target_link_options(${exe_NAME} PRIVATE ${exe_LINK_FLAGS}) 161*09537850SAkhilesh Sanikop endif() 162*09537850SAkhilesh Sanikop endif() 163*09537850SAkhilesh Sanikop 164*09537850SAkhilesh Sanikop if(exe_OBJLIB_DEPS) 165*09537850SAkhilesh Sanikop foreach(objlib_dep ${exe_OBJLIB_DEPS}) 166*09537850SAkhilesh Sanikop target_sources(${exe_NAME} PRIVATE $<TARGET_OBJECTS:${objlib_dep}>) 167*09537850SAkhilesh Sanikop endforeach() 168*09537850SAkhilesh Sanikop endif() 169*09537850SAkhilesh Sanikop 170*09537850SAkhilesh Sanikop if(CMAKE_THREAD_LIBS_INIT) 171*09537850SAkhilesh Sanikop list(APPEND exe_LIB_DEPS ${CMAKE_THREAD_LIBS_INIT}) 172*09537850SAkhilesh Sanikop endif() 173*09537850SAkhilesh Sanikop 174*09537850SAkhilesh Sanikop if(BUILD_SHARED_LIBS AND (MSVC OR WIN32)) 175*09537850SAkhilesh Sanikop target_compile_definitions(${exe_NAME} PRIVATE "LIBGAV1_BUILDING_DLL=0") 176*09537850SAkhilesh Sanikop endif() 177*09537850SAkhilesh Sanikop 178*09537850SAkhilesh Sanikop if(exe_LIB_DEPS) 179*09537850SAkhilesh Sanikop unset(exe_static) 180*09537850SAkhilesh Sanikop if("${CMAKE_EXE_LINKER_FLAGS} ${LIBGAV1_EXE_LINKER_FLAGS}" MATCHES "static") 181*09537850SAkhilesh Sanikop set(exe_static ON) 182*09537850SAkhilesh Sanikop endif() 183*09537850SAkhilesh Sanikop 184*09537850SAkhilesh Sanikop if(exe_static AND CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") 185*09537850SAkhilesh Sanikop # Third party dependencies can introduce dependencies on system and test 186*09537850SAkhilesh Sanikop # libraries. Since the target created here is an executable, and CMake 187*09537850SAkhilesh Sanikop # does not provide a method of controlling order of link dependencies, 188*09537850SAkhilesh Sanikop # wrap all of the dependencies of this target in start/end group flags to 189*09537850SAkhilesh Sanikop # ensure that dependencies of third party targets can be resolved when 190*09537850SAkhilesh Sanikop # those dependencies happen to be resolved by dependencies of the current 191*09537850SAkhilesh Sanikop # target. 192*09537850SAkhilesh Sanikop list(INSERT exe_LIB_DEPS 0 -Wl,--start-group) 193*09537850SAkhilesh Sanikop list(APPEND exe_LIB_DEPS -Wl,--end-group) 194*09537850SAkhilesh Sanikop endif() 195*09537850SAkhilesh Sanikop target_link_libraries(${exe_NAME} PRIVATE ${exe_LIB_DEPS}) 196*09537850SAkhilesh Sanikop endif() 197*09537850SAkhilesh Sanikopendmacro() 198*09537850SAkhilesh Sanikop 199*09537850SAkhilesh Sanikop# Creates a library target of the specified type. The target name is passed as a 200*09537850SAkhilesh Sanikop# parameter to the NAME argument, the type as a parameter to the TYPE argument, 201*09537850SAkhilesh Sanikop# and the sources passed as a parameter to the SOURCES argument: 202*09537850SAkhilesh Sanikop# libgav1_add_library(NAME <name> TYPE <type> SOURCES <sources> [optional args]) 203*09537850SAkhilesh Sanikop# 204*09537850SAkhilesh Sanikop# Optional args: 205*09537850SAkhilesh Sanikop# cmake-format: off 206*09537850SAkhilesh Sanikop# - OUTPUT_NAME: Override output file basename. Target basename defaults to 207*09537850SAkhilesh Sanikop# NAME. OUTPUT_NAME is ignored when BUILD_SHARED_LIBS is enabled and CMake 208*09537850SAkhilesh Sanikop# is generating a build for which MSVC or WIN32 are true. This is to avoid 209*09537850SAkhilesh Sanikop# output basename collisions with DLL import libraries. 210*09537850SAkhilesh Sanikop# - TEST: Flag. Presence means treat library as a test. 211*09537850SAkhilesh Sanikop# - DEFINES: List of preprocessor macro definitions. 212*09537850SAkhilesh Sanikop# - INCLUDES: list of include directories for the target. 213*09537850SAkhilesh Sanikop# - COMPILE_FLAGS: list of compiler flags for the target. 214*09537850SAkhilesh Sanikop# - LINK_FLAGS: List of linker flags for the target. 215*09537850SAkhilesh Sanikop# - OBJLIB_DEPS: List of CMake object library target dependencies. 216*09537850SAkhilesh Sanikop# - LIB_DEPS: List of CMake library dependencies. 217*09537850SAkhilesh Sanikop# - PUBLIC_INCLUDES: List of include paths to export to dependents. 218*09537850SAkhilesh Sanikop# cmake-format: on 219*09537850SAkhilesh Sanikop# 220*09537850SAkhilesh Sanikop# Sources passed to the macro are added to the lists tracking libgav1 sources: 221*09537850SAkhilesh Sanikop# cmake-format: off 222*09537850SAkhilesh Sanikop# - When TEST is specified sources are added to $libgav1_test_sources. 223*09537850SAkhilesh Sanikop# - Otherwise sources are added to $libgav1_sources. 224*09537850SAkhilesh Sanikop# cmake-format: on 225*09537850SAkhilesh Sanikop# 226*09537850SAkhilesh Sanikop# Targets passed to this macro are added to the lists tracking libgav1 targets: 227*09537850SAkhilesh Sanikop# cmake-format: off 228*09537850SAkhilesh Sanikop# - Targets are always added to $libgav1_targets. 229*09537850SAkhilesh Sanikop# - When the TEST flag is specified, targets are added to 230*09537850SAkhilesh Sanikop# $libgav1_test_targets. 231*09537850SAkhilesh Sanikop# - When TEST is not specified: 232*09537850SAkhilesh Sanikop# - Libraries of type SHARED are added to $libgav1_dylib_targets. 233*09537850SAkhilesh Sanikop# - Libraries of type OBJECT are added to $libgav1_objlib_targets. 234*09537850SAkhilesh Sanikop# - Libraries of type STATIC are added to $libgav1_lib_targets. 235*09537850SAkhilesh Sanikop# cmake-format: on 236*09537850SAkhilesh Sanikopmacro(libgav1_add_library) 237*09537850SAkhilesh Sanikop unset(lib_TEST) 238*09537850SAkhilesh Sanikop unset(lib_NAME) 239*09537850SAkhilesh Sanikop unset(lib_OUTPUT_NAME) 240*09537850SAkhilesh Sanikop unset(lib_TYPE) 241*09537850SAkhilesh Sanikop unset(lib_SOURCES) 242*09537850SAkhilesh Sanikop unset(lib_DEFINES) 243*09537850SAkhilesh Sanikop unset(lib_INCLUDES) 244*09537850SAkhilesh Sanikop unset(lib_COMPILE_FLAGS) 245*09537850SAkhilesh Sanikop unset(lib_LINK_FLAGS) 246*09537850SAkhilesh Sanikop unset(lib_OBJLIB_DEPS) 247*09537850SAkhilesh Sanikop unset(lib_LIB_DEPS) 248*09537850SAkhilesh Sanikop unset(lib_PUBLIC_INCLUDES) 249*09537850SAkhilesh Sanikop set(optional_args TEST) 250*09537850SAkhilesh Sanikop set(single_value_args NAME OUTPUT_NAME TYPE) 251*09537850SAkhilesh Sanikop set(multi_value_args SOURCES DEFINES INCLUDES COMPILE_FLAGS LINK_FLAGS 252*09537850SAkhilesh Sanikop OBJLIB_DEPS LIB_DEPS PUBLIC_INCLUDES) 253*09537850SAkhilesh Sanikop 254*09537850SAkhilesh Sanikop cmake_parse_arguments(lib "${optional_args}" "${single_value_args}" 255*09537850SAkhilesh Sanikop "${multi_value_args}" ${ARGN}) 256*09537850SAkhilesh Sanikop 257*09537850SAkhilesh Sanikop if(LIBGAV1_VERBOSE GREATER 1) 258*09537850SAkhilesh Sanikop message("--------- libgav1_add_library ---------\n" 259*09537850SAkhilesh Sanikop "lib_TEST=${lib_TEST}\n" 260*09537850SAkhilesh Sanikop "lib_NAME=${lib_NAME}\n" 261*09537850SAkhilesh Sanikop "lib_OUTPUT_NAME=${lib_OUTPUT_NAME}\n" 262*09537850SAkhilesh Sanikop "lib_TYPE=${lib_TYPE}\n" 263*09537850SAkhilesh Sanikop "lib_SOURCES=${lib_SOURCES}\n" 264*09537850SAkhilesh Sanikop "lib_DEFINES=${lib_DEFINES}\n" 265*09537850SAkhilesh Sanikop "lib_INCLUDES=${lib_INCLUDES}\n" 266*09537850SAkhilesh Sanikop "lib_COMPILE_FLAGS=${lib_COMPILE_FLAGS}\n" 267*09537850SAkhilesh Sanikop "lib_LINK_FLAGS=${lib_LINK_FLAGS}\n" 268*09537850SAkhilesh Sanikop "lib_OBJLIB_DEPS=${lib_OBJLIB_DEPS}\n" 269*09537850SAkhilesh Sanikop "lib_LIB_DEPS=${lib_LIB_DEPS}\n" 270*09537850SAkhilesh Sanikop "lib_PUBLIC_INCLUDES=${lib_PUBLIC_INCLUDES}\n" 271*09537850SAkhilesh Sanikop "---------------------------------------\n") 272*09537850SAkhilesh Sanikop endif() 273*09537850SAkhilesh Sanikop 274*09537850SAkhilesh Sanikop if(NOT (lib_NAME AND lib_TYPE AND lib_SOURCES)) 275*09537850SAkhilesh Sanikop message(FATAL_ERROR "libgav1_add_library: NAME, TYPE and SOURCES required.") 276*09537850SAkhilesh Sanikop endif() 277*09537850SAkhilesh Sanikop 278*09537850SAkhilesh Sanikop list(APPEND libgav1_targets ${lib_NAME}) 279*09537850SAkhilesh Sanikop if(lib_TEST) 280*09537850SAkhilesh Sanikop list(APPEND libgav1_test_targets ${lib_NAME}) 281*09537850SAkhilesh Sanikop list(APPEND libgav1_test_sources ${lib_SOURCES}) 282*09537850SAkhilesh Sanikop else() 283*09537850SAkhilesh Sanikop list(APPEND libgav1_sources ${lib_SOURCES}) 284*09537850SAkhilesh Sanikop if(lib_TYPE STREQUAL OBJECT) 285*09537850SAkhilesh Sanikop list(APPEND libgav1_objlib_targets ${lib_NAME}) 286*09537850SAkhilesh Sanikop elseif(lib_TYPE STREQUAL SHARED) 287*09537850SAkhilesh Sanikop list(APPEND libgav1_dylib_targets ${lib_NAME}) 288*09537850SAkhilesh Sanikop elseif(lib_TYPE STREQUAL STATIC) 289*09537850SAkhilesh Sanikop list(APPEND libgav1_lib_targets ${lib_NAME}) 290*09537850SAkhilesh Sanikop else() 291*09537850SAkhilesh Sanikop message(WARNING "libgav1_add_library: Unhandled type: ${lib_TYPE}") 292*09537850SAkhilesh Sanikop endif() 293*09537850SAkhilesh Sanikop endif() 294*09537850SAkhilesh Sanikop 295*09537850SAkhilesh Sanikop add_library(${lib_NAME} ${lib_TYPE} ${lib_SOURCES}) 296*09537850SAkhilesh Sanikop libgav1_process_intrinsics_sources(TARGET ${lib_NAME} SOURCES ${lib_SOURCES}) 297*09537850SAkhilesh Sanikop 298*09537850SAkhilesh Sanikop if(lib_OUTPUT_NAME) 299*09537850SAkhilesh Sanikop if(NOT (BUILD_SHARED_LIBS AND (MSVC OR WIN32))) 300*09537850SAkhilesh Sanikop set_target_properties(${lib_NAME} 301*09537850SAkhilesh Sanikop PROPERTIES OUTPUT_NAME ${lib_OUTPUT_NAME}) 302*09537850SAkhilesh Sanikop endif() 303*09537850SAkhilesh Sanikop endif() 304*09537850SAkhilesh Sanikop 305*09537850SAkhilesh Sanikop if(lib_DEFINES) 306*09537850SAkhilesh Sanikop target_compile_definitions(${lib_NAME} PRIVATE ${lib_DEFINES}) 307*09537850SAkhilesh Sanikop endif() 308*09537850SAkhilesh Sanikop 309*09537850SAkhilesh Sanikop if(lib_INCLUDES) 310*09537850SAkhilesh Sanikop target_include_directories(${lib_NAME} PRIVATE ${lib_INCLUDES}) 311*09537850SAkhilesh Sanikop endif() 312*09537850SAkhilesh Sanikop 313*09537850SAkhilesh Sanikop if(lib_PUBLIC_INCLUDES) 314*09537850SAkhilesh Sanikop target_include_directories(${lib_NAME} PUBLIC ${lib_PUBLIC_INCLUDES}) 315*09537850SAkhilesh Sanikop endif() 316*09537850SAkhilesh Sanikop 317*09537850SAkhilesh Sanikop if(lib_COMPILE_FLAGS OR LIBGAV1_CXX_FLAGS) 318*09537850SAkhilesh Sanikop target_compile_options(${lib_NAME} 319*09537850SAkhilesh Sanikop PRIVATE ${lib_COMPILE_FLAGS} ${LIBGAV1_CXX_FLAGS}) 320*09537850SAkhilesh Sanikop endif() 321*09537850SAkhilesh Sanikop 322*09537850SAkhilesh Sanikop if(lib_LINK_FLAGS) 323*09537850SAkhilesh Sanikop set_target_properties(${lib_NAME} PROPERTIES LINK_FLAGS ${lib_LINK_FLAGS}) 324*09537850SAkhilesh Sanikop endif() 325*09537850SAkhilesh Sanikop 326*09537850SAkhilesh Sanikop if(lib_OBJLIB_DEPS) 327*09537850SAkhilesh Sanikop foreach(objlib_dep ${lib_OBJLIB_DEPS}) 328*09537850SAkhilesh Sanikop target_sources(${lib_NAME} PRIVATE $<TARGET_OBJECTS:${objlib_dep}>) 329*09537850SAkhilesh Sanikop endforeach() 330*09537850SAkhilesh Sanikop endif() 331*09537850SAkhilesh Sanikop 332*09537850SAkhilesh Sanikop if(lib_LIB_DEPS) 333*09537850SAkhilesh Sanikop if(lib_TYPE STREQUAL STATIC) 334*09537850SAkhilesh Sanikop set(link_type PUBLIC) 335*09537850SAkhilesh Sanikop else() 336*09537850SAkhilesh Sanikop set(link_type PRIVATE) 337*09537850SAkhilesh Sanikop if(lib_TYPE STREQUAL SHARED AND CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") 338*09537850SAkhilesh Sanikop # The libgav1 shared object uses the static libgav1 as input to turn it 339*09537850SAkhilesh Sanikop # into a shared object. Include everything from the static library in 340*09537850SAkhilesh Sanikop # the shared object. 341*09537850SAkhilesh Sanikop if(APPLE) 342*09537850SAkhilesh Sanikop list(INSERT lib_LIB_DEPS 0 -Wl,-force_load) 343*09537850SAkhilesh Sanikop else() 344*09537850SAkhilesh Sanikop list(INSERT lib_LIB_DEPS 0 -Wl,--whole-archive) 345*09537850SAkhilesh Sanikop list(APPEND lib_LIB_DEPS -Wl,--no-whole-archive) 346*09537850SAkhilesh Sanikop endif() 347*09537850SAkhilesh Sanikop endif() 348*09537850SAkhilesh Sanikop endif() 349*09537850SAkhilesh Sanikop target_link_libraries(${lib_NAME} ${link_type} ${lib_LIB_DEPS}) 350*09537850SAkhilesh Sanikop endif() 351*09537850SAkhilesh Sanikop 352*09537850SAkhilesh Sanikop if(NOT MSVC AND lib_NAME MATCHES "^lib") 353*09537850SAkhilesh Sanikop # Non-MSVC generators prepend lib to static lib target file names. Libgav1 354*09537850SAkhilesh Sanikop # already includes lib in its name. Avoid naming output files liblib*. 355*09537850SAkhilesh Sanikop set_target_properties(${lib_NAME} PROPERTIES PREFIX "") 356*09537850SAkhilesh Sanikop endif() 357*09537850SAkhilesh Sanikop 358*09537850SAkhilesh Sanikop if(lib_TYPE STREQUAL SHARED AND NOT MSVC) 359*09537850SAkhilesh Sanikop set_target_properties(${lib_NAME} 360*09537850SAkhilesh Sanikop PROPERTIES VERSION ${LIBGAV1_SOVERSION} SOVERSION 361*09537850SAkhilesh Sanikop ${LIBGAV1_SOVERSION_MAJOR}) 362*09537850SAkhilesh Sanikop endif() 363*09537850SAkhilesh Sanikop 364*09537850SAkhilesh Sanikop if(BUILD_SHARED_LIBS AND (MSVC OR WIN32)) 365*09537850SAkhilesh Sanikop if(lib_TYPE STREQUAL SHARED) 366*09537850SAkhilesh Sanikop target_compile_definitions(${lib_NAME} PRIVATE "LIBGAV1_BUILDING_DLL=1") 367*09537850SAkhilesh Sanikop else() 368*09537850SAkhilesh Sanikop target_compile_definitions(${lib_NAME} PRIVATE "LIBGAV1_BUILDING_DLL=0") 369*09537850SAkhilesh Sanikop endif() 370*09537850SAkhilesh Sanikop endif() 371*09537850SAkhilesh Sanikop 372*09537850SAkhilesh Sanikop # Determine if $lib_NAME is a header only target. 373*09537850SAkhilesh Sanikop set(sources_list ${lib_SOURCES}) 374*09537850SAkhilesh Sanikop list(FILTER sources_list INCLUDE REGEX cc$) 375*09537850SAkhilesh Sanikop if(NOT sources_list) 376*09537850SAkhilesh Sanikop if(NOT XCODE) 377*09537850SAkhilesh Sanikop # This is a header only target. Tell CMake the link language. 378*09537850SAkhilesh Sanikop set_target_properties(${lib_NAME} PROPERTIES LINKER_LANGUAGE CXX) 379*09537850SAkhilesh Sanikop else() 380*09537850SAkhilesh Sanikop # The Xcode generator ignores LINKER_LANGUAGE. Add a dummy cc file. 381*09537850SAkhilesh Sanikop libgav1_create_dummy_source_file(TARGET ${lib_NAME} BASENAME ${lib_NAME}) 382*09537850SAkhilesh Sanikop endif() 383*09537850SAkhilesh Sanikop endif() 384*09537850SAkhilesh Sanikop 385*09537850SAkhilesh Sanikop if(lib_TEST) 386*09537850SAkhilesh Sanikop set_property(TARGET ${lib_NAME} PROPERTY FOLDER ${LIBGAV1_TESTS_IDE_FOLDER}) 387*09537850SAkhilesh Sanikop else() 388*09537850SAkhilesh Sanikop set(sources_list ${lib_SOURCES}) 389*09537850SAkhilesh Sanikop list(FILTER sources_list INCLUDE REGEX examples) 390*09537850SAkhilesh Sanikop if(sources_list) 391*09537850SAkhilesh Sanikop set_property(TARGET ${lib_NAME} 392*09537850SAkhilesh Sanikop PROPERTY FOLDER ${LIBGAV1_EXAMPLES_IDE_FOLDER}) 393*09537850SAkhilesh Sanikop else() 394*09537850SAkhilesh Sanikop set_property(TARGET ${lib_NAME} PROPERTY FOLDER ${LIBGAV1_IDE_FOLDER}) 395*09537850SAkhilesh Sanikop endif() 396*09537850SAkhilesh Sanikop endif() 397*09537850SAkhilesh Sanikopendmacro() 398