From a9b4874729292cfcdedcfae3d7c9c5d9c6da0d0d Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 25 Oct 2024 22:21:06 -0400 Subject: [PATCH] test new shell cmd logic --- .github/workflows/ci.yml | 7 +++++++ CMakeLists.txt | 29 +++++++++++++++++++++++++---- cmake/ffmpeg/ffmpeg.cmake | 6 +++--- cmake/ffmpeg/nv_codec_headers.cmake | 5 +++-- cmake/ffmpeg/x264.cmake | 7 ++++--- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e9f6208..5f8acbd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -241,6 +241,13 @@ jobs: if: ${{ matrix.arch != 'x86_64' }} run: | TOOLCHAIN=${ROOT_PATH}/cmake/toolchains/${{ matrix.target }}.cmake + + # fail if file does not exist + if [ ! -f $TOOLCHAIN ]; then + echo "Toolchain file not found: $TOOLCHAIN" + exit 1 + fi + echo "CMAKE_TOOLCHAIN_FILE=$TOOLCHAIN" >> $GITHUB_ENV if [[ ${{ runner.os }} == 'Linux' ]]; then echo "CCPREFIX=/usr/bin/${{ matrix.target }}-" >> $GITHUB_ENV diff --git a/CMakeLists.txt b/CMakeLists.txt index 056366c8..0dbd3635 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ endif() # The shell command and prefix to use for running extra commands. if(NOT DEFINED BASH_EXECUTABLE) - find_program(BASH_EXECUTABLE NAMES zsh bash REQUIRED HINTS /bin /usr/bin /usr/local/bin C:/msys64/usr/bin) + find_program(BASH_EXECUTABLE NAMES zsh bash REQUIRED HINTS C:/msys64/usr/bin /bin /usr/bin /usr/local/bin) message(STATUS "Found bash: ${BASH_EXECUTABLE}") endif() @@ -49,20 +49,41 @@ if(NOT DEFINED SHELL_CMD_ARGS) endif() if(WIN32) - set(SHELL_CMD ${CMAKE_COMMAND} -E env MSYSTEM=${MSYSTEM} ${BASH_EXECUTABLE} ${SHELL_CMD_ARGS}) + # set(SHELL_CMD ${CMAKE_COMMAND} -E env MSYSTEM=${MSYSTEM} ${BASH_EXECUTABLE} ${SHELL_CMD_ARGS}) + # find_program(MSYS2_EXECUTABLE NAMES msys2_shell.cmd REQUIRED HINTS C:/msys64 D:/msys64) + find_file(MSYS2_EXECUTABLE NAMES msys2_shell.cmd REQUIRED HINTS D:/msys64 C:/msys64) + message(STATUS "Found MSYS2: ${MSYS2_EXECUTABLE}") + set(SHELL_CMD ${MSYS2_EXECUTABLE} -ucrt64 -defterm -here -no-start -shell bash -c) else() - set(SHELL_CMD ${CMAKE_COMMAND} -E env PATH=$ENV{PATH} ${BASH_EXECUTABLE} ${SHELL_CMD_ARGS}) + # set(SHELL_CMD ${CMAKE_COMMAND} -E env PATH=$ENV{PATH} ${BASH_EXECUTABLE} ${SHELL_CMD_ARGS}) + set(SHELL_CMD ${BASH_EXECUTABLE} -c) endif() message(STATUS "Using shell command: ${SHELL_CMD}") find_program(MAKE_EXECUTABLE - NAMES mingw32-make make gmake + NAMES make gmake # mingw32-make does not work for x264 + HINTS C:/msys64/usr/bin /bin /usr/bin /usr/local/bin NAMES_PER_DIR DOC "GNU Make" REQUIRED) message(STATUS "Found make: ${MAKE_EXECUTABLE}") +find_program(GCC_EXECUTABLE + NAMES gcc + HINTS C:/msys64/usr/bin /bin /usr/bin /usr/local/bin + NAMES_PER_DIR + DOC "GNU Compiler Collection" + REQUIRED) +message(STATUS "Found gcc: ${GCC_EXECUTABLE}") + +find_program(GXX_EXECUTABLE + NAMES g++ + HINTS C:/msys64/usr/bin /bin /usr/bin /usr/local/bin + NAMES_PER_DIR + DOC "GNU Compiler Collection" + REQUIRED) + # Custom target to use to ensure all dependencies are built add_custom_target(${CMAKE_PROJECT_NAME} COMMENT "Completed build-deps" diff --git a/cmake/ffmpeg/ffmpeg.cmake b/cmake/ffmpeg/ffmpeg.cmake index f41f74da..7f9e3225 100644 --- a/cmake/ffmpeg/ffmpeg.cmake +++ b/cmake/ffmpeg/ffmpeg.cmake @@ -87,7 +87,7 @@ endif() set(WORKING_DIR ${FFMPEG_GENERATED_SRC_PATH}) UNIX_PATH(WORKING_DIR_UNIX ${WORKING_DIR}) add_custom_target(ffmpeg ALL - COMMAND ${SHELL_CMD} "cd ${WORKING_DIR_UNIX} && ./configure \ + COMMAND ${SHELL_CMD} "./configure \ --prefix=${CMAKE_CURRENT_BINARY_DIR_UNIX}/FFmpeg \ --cc=${CMAKE_C_COMPILER} \ --cxx=${CMAKE_CXX_COMPILER} \ @@ -95,8 +95,8 @@ add_custom_target(ffmpeg ALL --ranlib=${CMAKE_RANLIB} \ --optflags=${CMAKE_C_FLAGS} \ ${FFMPEG_EXTRA_CONFIGURE}" - COMMAND ${SHELL_CMD} "cd ${WORKING_DIR_UNIX} && ${MAKE_EXECUTABLE}" - COMMAND ${SHELL_CMD} "cd ${WORKING_DIR_UNIX} && ${MAKE_EXECUTABLE} install" + COMMAND ${SHELL_CMD} "${MAKE_EXECUTABLE}" + COMMAND ${SHELL_CMD} "${MAKE_EXECUTABLE} install" WORKING_DIRECTORY ${WORKING_DIR} COMMENT "Configuring ffmpeg" COMMAND_EXPAND_LISTS diff --git a/cmake/ffmpeg/nv_codec_headers.cmake b/cmake/ffmpeg/nv_codec_headers.cmake index a1b71724..be51cca5 100644 --- a/cmake/ffmpeg/nv_codec_headers.cmake +++ b/cmake/ffmpeg/nv_codec_headers.cmake @@ -10,13 +10,14 @@ set(WORKING_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third-party/FFmpeg/nv-codec-headers UNIX_PATH(WORKING_DIR_UNIX ${WORKING_DIR}) UNIX_PATH(DEST_DIR_UNIX ${CMAKE_CURRENT_BINARY_DIR}) add_custom_target(nv-codec-headers ALL - COMMAND ${SHELL_CMD} "cd ${WORKING_DIR_UNIX} && ${MAKE_EXECUTABLE}" + COMMAND ${SHELL_CMD} "${MAKE_EXECUTABLE}" # this will install the headers to the CMAKE_CURRENT_BINARY_DIR/usr/local - COMMAND ${SHELL_CMD} "cd ${WORKING_DIR_UNIX} && DESTDIR=${DEST_DIR_UNIX} ${MAKE_EXECUTABLE} install" + COMMAND ${SHELL_CMD} "DESTDIR=${DEST_DIR_UNIX} ${MAKE_EXECUTABLE} install" WORKING_DIRECTORY ${WORKING_DIR} COMMENT "Building nv-codec-headers" COMMAND_EXPAND_LISTS USES_TERMINAL + BYPRODUCTS "usr/local/include/ffnvcodec" ) add_dependencies(${CMAKE_PROJECT_NAME} nv-codec-headers) install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/usr/local/include/ffnvcodec" diff --git a/cmake/ffmpeg/x264.cmake b/cmake/ffmpeg/x264.cmake index 902a4f11..2a9d5934 100644 --- a/cmake/ffmpeg/x264.cmake +++ b/cmake/ffmpeg/x264.cmake @@ -43,17 +43,18 @@ UNIX_PATH(CMAKE_CURRENT_BINARY_DIR_UNIX ${CMAKE_CURRENT_BINARY_DIR}) set(WORKING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party/FFmpeg/x264) UNIX_PATH(WORKING_DIR_UNIX ${WORKING_DIR}) add_custom_target(x264 ALL - COMMAND ${SHELL_CMD} "cd ${WORKING_DIR_UNIX} && ./configure \ + COMMAND ${SHELL_CMD} "CC=${GCC_EXECUTABLE} ./configure \ --prefix=${CMAKE_CURRENT_BINARY_DIR_UNIX}/x264 \ --disable-cli \ --enable-static \ ${FFMPEG_X264_EXTRA_CONFIGURE}" - COMMAND ${SHELL_CMD} "cd ${WORKING_DIR_UNIX} && ${MAKE_EXECUTABLE}" - COMMAND ${SHELL_CMD} "cd ${WORKING_DIR_UNIX} && ${MAKE_EXECUTABLE} install" + COMMAND ${SHELL_CMD} "${MAKE_EXECUTABLE}" + COMMAND ${SHELL_CMD} "${MAKE_EXECUTABLE} install" WORKING_DIRECTORY ${WORKING_DIR} COMMENT "Building x264" COMMAND_EXPAND_LISTS USES_TERMINAL + BYPRODUCTS "x264/lib/libx264.a" "x264/include/x264.h" "x264/include/x264_config.h" ) add_dependencies(${CMAKE_PROJECT_NAME} x264) set(X264_HEADER_FILES