Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake compatibility for MinGW #2

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
cmake_minimum_required(VERSION 3.15)
project(video-metadata VERSION 1.0)


add_subdirectory(proto) # video-metadata-proto

set(LIB_SOURCES
src/vmeta_session.c
src/vmeta_frame.c
src/vmeta_json.c
src/vmeta_json_proto.c
src/vmeta_csv.c
src/vmeta_frame_proto.c
src/vmeta_frame_v1.c
src/vmeta_frame_v2.c
src/vmeta_frame_v3.c
src/vmeta_utils.c
)

add_library(${PROJECT_NAME} SHARED ${LIB_SOURCES})

# checks if set up rpath exists for install
if(COMMAND set_up_rpath)
set_up_rpath()
else()
message("Set up rpath not defined!")
endif()

target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
set_target_properties(${PROJECT_NAME} PROPERTIES
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_compile_definitions(${PROJECT_NAME} PRIVATE "VMETA_API_EXPORTS")
target_compile_options(${PROJECT_NAME} PRIVATE "-fvisibility=hidden")

find_package(json-c CONFIG REQUIRED)

target_link_libraries(${PROJECT_NAME}
PUBLIC
video-metadata-proto
PRIVATE
json-c::json-c
ulog
futils
mp4
protobuf-c
)

# to get all header files correctly
set(${PROJECT_NAME}-headers
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/
)
install(
DIRECTORY ${${PROJECT_NAME}-headers} DESTINATION include/${PROJECT_NAME}
)

if(WIN32)
install(CODE "file(GLOB dll_files \"${CMAKE_CURRENT_BINARY_DIR}/*.dll\")")
install(CODE "file(INSTALL DESTINATION \"\$\{CMAKE_INSTALL_PREFIX\}/bin\" TYPE SHARED_LIBRARY FILES \$\{dll_files\})")
else()
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
LIBRARIES $<TARGET_FILE:video-metadata>
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
POST_EXCLUDE_REGEXES "^/lib" "^/usr/lib"
)
foreach(_file ${_r_deps})
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
TYPE SHARED_LIBRARY
FOLLOW_SYMLINK_CHAIN
FILES "${_file}"
)
endforeach()
]])
endif()

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
PUBLIC_HEADER DESTINATION include
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
6 changes: 5 additions & 1 deletion include/video-metadata/vmeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
#define _VMETA_H_

#include <stdint.h>
#include <unistd.h>
#ifndef _MSC_VER
# include <unistd.h>
#else /* !_MSC_VER */
# include <io.h>
#endif /* !_MSC_VER */

#ifdef __cplusplus
extern "C" {
Expand Down
99 changes: 99 additions & 0 deletions proto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
cmake_minimum_required(VERSION 3.20)
project(video-metadata-proto VERSION 1.0)

add_library(${PROJECT_NAME}-generated INTERFACE)
find_package(Protobuf REQUIRED)

list(APPEND INCLUDE_PATH ${CMAKE_BINARY_DIR} ${Protobuf_INCLUDE_DIR})


if(NOT DEFINED Protobuf_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Unable to locate protoc-c executable please set with -DPROTOBUF_PROTOCC!")
else()
get_filename_component(Protobuf_PROTOC_EXECUTABLE_PATH ${Protobuf_INCLUDE_DIR} DIRECTORY)
set(Protobuf_PROTOC_GEN_C_EXECUTABLE_PATH ${Protobuf_PROTOC_EXECUTABLE_PATH}/tools/protobuf-c)
set(Protobuf_PROTOC_GEN_C_EXECUTABLE ${Protobuf_PROTOC_GEN_C_EXECUTABLE_PATH}/protoc-gen-c${CMAKE_EXECUTABLE_SUFFIX})
if(CMAKE_BUILD_TYPE MATCHES "Debug")
list(FIND Protobuf_LIBRARY debug lib_index)
else()
list(FIND Protobuf_LIBRARY optimized lib_index)
endif()
math(EXPR lib_index "${lib_index} + 1")
list(GET Protobuf_LIBRARY ${lib_index} Protobuf_LIBRARY_USE)
get_filename_component(Protobuf_LIBRARY_DIRECTORY ${Protobuf_LIBRARY_USE} DIRECTORY)

message(STATUS
"Using the following binary \"${Protobuf_PROTOC_EXECUTABLE}\" to create vmeta")
message(STATUS
"Using the following protobuf-c plugin \"${Protobuf_PROTOC_GEN_C_EXECUTABLE}\"")
message(STATUS
"Using the following protobuf-c library \"${Protobuf_LIBRARY_DIRECTORY}\"")

# Proto files
set(vmeta_protos
${CMAKE_CURRENT_SOURCE_DIR}/vmeta.proto
)

# Generated sources
set(vmeta_protos_srcs
${CMAKE_BINARY_DIR}/vmeta.pb-c.c
)
set(vmeta_protos_hdrs
${CMAKE_BINARY_DIR}/vmeta.pb-c.h
)


add_custom_command(
OUTPUT ${vmeta_protos_srcs} ${vmeta_protos_hdrs}
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --c_out ${CMAKE_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} --plugin "protoc-gen-c=${Protobuf_PROTOC_GEN_C_EXECUTABLE}"
${vmeta_protos}
)

add_library(${PROJECT_NAME} SHARED ${vmeta_protos_srcs})
set_target_properties(${PROJECT_NAME} PROPERTIES
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
)
target_link_directories(${PROJECT_NAME} PUBLIC ${Protobuf_LIBRARY_DIRECTORY})
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${INCLUDE_PATH}>"
)

target_link_libraries(${PROJECT_NAME} PRIVATE
${PROJECT_NAME}-generated
protobuf-c)

install(FILES ${vmeta_protos_hdrs} DESTINATION include)
file(GLOB protobuf_c_hdrs "${Protobuf_INCLUDE_DIR}/protobuf-c/*.h")
install(FILES ${protobuf_c_hdrs} DESTINATION include/protobuf-c)

if(WIN32)
install(CODE "file(GLOB dll_files \"${CMAKE_CURRENT_BINARY_DIR}/*.dll\")")
install(CODE "file(INSTALL DESTINATION \"\$\{CMAKE_INSTALL_PREFIX\}/bin\" TYPE SHARED_LIBRARY FILES \$\{dll_files\})")
else()
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
LIBRARIES $<TARGET_FILE:video-metadata>
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
POST_EXCLUDE_REGEXES "^/lib" "^/usr/lib"
)
foreach(_file ${_r_deps})
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
TYPE SHARED_LIBRARY
FOLLOW_SYMLINK_CHAIN
FILES "${_file}"
)
endforeach()
]])
endif()

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

endif()