cmake添加windows编译, main 输入文件名调整, constexpr使用string_view
This commit is contained in:
parent
15018f4079
commit
fcaba07e09
@ -68,7 +68,69 @@ IF(UNIX)
|
|||||||
)
|
)
|
||||||
|
|
||||||
ELSE(WIN32)
|
ELSE(WIN32)
|
||||||
|
set(ENV{http_proxy} "http://127.0.0.1:10809")
|
||||||
|
set(ENV{https_proxy} "http://127.0.0.1:10809")
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(SFML
|
||||||
|
GIT_REPOSITORY https://github.com/SFML/SFML.git
|
||||||
|
GIT_TAG 2.6.x
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(SFML)
|
||||||
|
|
||||||
|
#vcpkg
|
||||||
|
set(VCPKG_PACKAGE C:/document/lib/vcpkg/packages)
|
||||||
|
set(VCPKG_BUILDTREES_DIR C:/document/lib/vcpkg/buildtrees)
|
||||||
|
|
||||||
|
#ffmpeg
|
||||||
|
include_directories(${VCPKG_PACKAGE}/ffmpeg_x64-windows/include)
|
||||||
|
file(GLOB_RECURSE FFMPEG_LIBS ${VCPKG_PACKAGE}/ffmpeg_x64-windows/debug/lib/*.lib)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_N}
|
||||||
|
main.cc
|
||||||
|
${srcs}
|
||||||
|
)
|
||||||
|
target_link_libraries(${PROJECT_N} PRIVATE
|
||||||
|
sfml-system
|
||||||
|
sfml-window
|
||||||
|
sfml-graphics
|
||||||
|
sfml-network
|
||||||
|
sfml-audio
|
||||||
|
${FFMPEG_LIBS}
|
||||||
|
spdlog
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_N_T}
|
||||||
|
${srcs}
|
||||||
|
${tests}
|
||||||
|
)
|
||||||
|
target_link_libraries(${PROJECT_N_T} PRIVATE
|
||||||
|
sfml-system
|
||||||
|
sfml-window
|
||||||
|
sfml-graphics
|
||||||
|
sfml-network
|
||||||
|
sfml-audio
|
||||||
|
|
||||||
|
GTest::gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(run
|
||||||
|
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_N} ./img/ocean.jpg
|
||||||
|
DEPENDS ${PROJECT_N}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
COMMENT "Starting ${PROJECT_N}"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(run_test
|
||||||
|
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_N_T}
|
||||||
|
DEPENDS ${PROJECT_N_T}
|
||||||
|
WORKING_DIRECTORY ${PROJECT_CURRENT_BINARY_DIR}
|
||||||
|
COMMENT "Starting ${PROJECT_N_T}"
|
||||||
|
)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${PROJECT_N}
|
||||||
|
COMMENT "Copy OpenAL DLL"
|
||||||
|
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:${PROJECT_N}>
|
||||||
|
VERBATIM)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
gtest_discover_tests(${PROJECT_N_T})
|
gtest_discover_tests(${PROJECT_N_T})
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#ifndef UTILTOOL_H
|
#ifndef UTILTOOL_H
|
||||||
#define UTILTOOL_H
|
#define UTILTOOL_H
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
enum class MediaType{
|
enum class MediaType{
|
||||||
VIDEO,
|
VIDEO,
|
||||||
@ -14,9 +15,9 @@ enum class MediaType{
|
|||||||
class UtilTool
|
class UtilTool
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
constexpr static std::array<std::string, 2> ImageTypes{"jpg","png"};
|
constexpr static std::array<std::string_view, 2> ImageTypes{"jpg","png"};
|
||||||
constexpr static std::array<std::string, 1> VideoTypes{"mp4"};
|
constexpr static std::array<std::string_view, 1> VideoTypes{"mp4"};
|
||||||
constexpr static std::array<std::string, 1> AudioTypes{"mp3"};
|
constexpr static std::array<std::string_view, 1> AudioTypes{"mp3"};
|
||||||
static bool CheckFileIsImage(const std::string& filename);
|
static bool CheckFileIsImage(const std::string& filename);
|
||||||
static bool CheckFileIsAudio(const std::string& filename);
|
static bool CheckFileIsAudio(const std::string& filename);
|
||||||
static bool CheckFileIsVideo(const std::string& filename);
|
static bool CheckFileIsVideo(const std::string& filename);
|
||||||
|
11
main.cc
11
main.cc
@ -6,29 +6,30 @@
|
|||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include "UtilTool.h"
|
#include "UtilTool.h"
|
||||||
#include "mediaService.h"
|
#include "mediaService.h"
|
||||||
|
#include "SFML/Window/VideoMode.hpp"
|
||||||
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
using namespace std::string_view_literals;
|
||||||
constexpr int CLIENT_WIDTH = 800;
|
constexpr int CLIENT_WIDTH = 800;
|
||||||
constexpr int CLIENT_HEIGHT = 600;
|
constexpr int CLIENT_HEIGHT = 600;
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
|
auto filename = R"(C:/document/project/mp-sfml/img/ocean.mp4)"sv;
|
||||||
spdlog::info("Current WorkDir Is: {}",argv[0]);
|
spdlog::info("Current WorkDir Is: {}",argv[0]);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
argv[1] = R"(../img/ocean.mp4)";
|
|
||||||
#else
|
#else
|
||||||
|
filename = argv[1];
|
||||||
if(argc != 2){
|
if(argc != 2){
|
||||||
spdlog::error("Usage: mp filename ");
|
spdlog::error("Usage: mp filename ");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
spdlog::info("filename: {}", argv[1]);
|
spdlog::info("filename: {}", filename);
|
||||||
MediaService mediaService(argv[1], CLIENT_WIDTH, CLIENT_HEIGHT);
|
MediaService mediaService(filename.data(), CLIENT_WIDTH, CLIENT_HEIGHT);
|
||||||
std::shared_ptr<sf::RenderWindow> window = std::make_shared<sf::RenderWindow>(sf::VideoMode(CLIENT_WIDTH, CLIENT_HEIGHT), "mp");
|
std::shared_ptr<sf::RenderWindow> window = std::make_shared<sf::RenderWindow>(sf::VideoMode(CLIENT_WIDTH, CLIENT_HEIGHT), "mp");
|
||||||
mediaService.SetWindow(window);
|
mediaService.SetWindow(window);
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
while(running){
|
while(running){
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while(window->pollEvent(event)){
|
while(window->pollEvent(event)){
|
||||||
|
Loading…
Reference in New Issue
Block a user