-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcam.camke
140 lines (116 loc) · 4.33 KB
/
cam.camke
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
136
137
138
139
#
# C/C++ archive camke config utils
# Test on windows 7 x64 cmake 3.10.0
#
# the latest https://github.com/Mingyiz/cam/releases/download/tools/cam.camke
#
#
set( CAM_TOOLS_CMAKE_VERSION 0.0.1 )
if( MSVC )
set( __VS "(15 2017|14 2015|12 2013|10 2010|9 2008|8 2005)")
string(REGEX MATCH "Visual Studio ${__VS} Win64" __matched ${CMAKE_GENERATOR})
if( __matched )
set( CAM_TARGET_ARCH x86_64 )
else()
set( CAM_TARGET_ARCH x86 )
endif()
endif()
set(CAM_TOOLS_URL https://github.com/Mingyiz/cam/releases/download/tools )
if( $ENV{CAM_TOOLS_URL})
set(CAM_TOOLS_URL $ENV{CAM_TOOLS_URL})
endif()
#
# group source files in Visual Studio
#
macro(cam_project_group source_files sgbd_cur_dir)
if(MSVC)
foreach(sgbd_file ${${source_files}})
string(REGEX REPLACE ${sgbd_cur_dir}/\(.*\) \\1 sgbd_fpath ${sgbd_file})
string(REGEX REPLACE "\(.*\)/.*" \\1 sgbd_group_name ${sgbd_fpath})
string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup)
string(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name})
if(sgbd_nogroup)
set(sgbd_group_name "\\")
endif(sgbd_nogroup)
source_group(${sgbd_group_name} FILES ${sgbd_file})
endforeach(sgbd_file)
endif()
endmacro(cam_project_group)
#
#
# find pkg-config, if not found try download it
#
macro(cam_find_pkgconfig version )
find_package(PkgConfig ${version} )
if( NOT PKG_CONFIG_FOUND )
set( _version 0.29.2)
if( MSVC )
set( _basename "pkg-config-${_version}-windows")
set( _tarname "${_basename}.tar.gz")
set( _hash e247a276562398946507abde0a8bcb1f)
set( _url ${CAM_TOOLS_URL}/${_tarname})
set( _filename "${CMAKE_CURRENT_BINARY_DIR}/build-tools/.cache/${_tarname}")
message(STATUS "Downloading pkg-config binary ...")
file( DOWNLOAD ${_url} ${_filename}
SHOW_PROGRESS
INACTIVITY_TIMEOUT 60 # seconds
EXPECTED_HASH MD5=${_hash} )
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${_filename}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
RESULT_VARIABLE __result )
if(NOT __result EQUAL 0)
message(FATAL_ERROR "error ${__result}")
endif()
set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/${_basename}/pkg-config")
endif()
endif()
find_package(PkgConfig ${version} REQUIRED )
endmacro(cam_find_pkgconfig)
#
# gstreamer helper
#
macro(cam_find_gstreamer version )
pkg_check_modules(_GSTREAMER QUIET gstreamer-1.0>=${version})
if( NOT _GSTREAMER_NOT_FOUND)
if( CAM_TARGET_ARCH STREQUAL x86 )
if( $ENV{GSTREAMER_1_0_ROOT_X86})
set( _pkgconfigdir "${GSTREAMER_1_0_ROOT_X86}/lib/pkgconfig")
else()
set( _pkgconfigdir "c:/gstreamer/1.0/x86/lib/pkgconfig")
endif()
elseif( CAM_TARGET_ARCH STREQUAL x86_64)
if( $ENV{GSTREAMER_1_0_ROOT_X86_64})
set( _pkgconfigdir "${GSTREAMER_1_0_ROOT_X86_64}/lib/pkgconfig")
else()
set( _pkgconfigdir "c:/gstreamer/1.0/x86_64/lib/pkgconfig")
endif()
else()
message(FATAL_ERROR "unknow target arch ${CAM_TARGET_ARCH} at ${CMAKE_GENERATOR}")
endif()
file(TO_CMAKE_PATH "${_pkgconfigdir}" _pkgconfigdir)
if( $ENV{PKG_CONFIG_PATH} )
if( MSVC )
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH};${_pkgconfigdir}")
else()
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${_pkgconfigdir}")
endif()
else()
set(ENV{PKG_CONFIG_PATH} ${_pkgconfigdir})
endif()
pkg_check_modules(_GSTREAMER REQUIRED gstreamer-1.0>=${version})
endif()
endmacro(cam_find_gstreamer)
#
# compiler flags
#
macro(cam_compiler_flags )
if(MSVC)
ADD_DEFINITIONS( -D_CRT_SECURE_NO_DEPRECATE )
ADD_DEFINITIONS( -D_CRT_NONSTDC_NO_DEPRECATE )
ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endmacro(cam_compiler_flags)