1
0
mirror of synced 2024-11-12 02:00:52 +01:00

build: Cleaned up cmake build structure (#399)

* build: Cleanup build process, move main application to /main folder

* build: Try fixing MacOS bundling

* build: Fixed swapped parameters

* build: One imhex -> main too much

* build: Move resources to a better location

* build: Try to fix macos bundle creation

* build: More bundle fixes

* build: Fixed syntax

* build: Another try

* build: Added macos debugging stuff

* build: Fix bundle path

* build: Removed duplicated adding of Frameworks folder to rpath

* build: Removed debugging
This commit is contained in:
WerWolv 2022-01-15 00:14:12 +01:00 committed by GitHub
parent b34b4c2362
commit d8219ad971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 179 additions and 174 deletions

View File

@ -30,8 +30,8 @@ jobs:
with:
path: |
~/.ccache
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ github.run_id }}
restore-keys: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
- name: ⬇️ Install dependencies
run: |

View File

@ -9,106 +9,7 @@ env:
jobs:
linux:
runs-on: ubuntu-20.04
name: 🐧 Ubuntu 20.04
steps:
- name: 🧰 Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: recursive
- name: 📜 Restore cache
uses: actions/cache@v2
with:
path: |
~/.ccache
.flatpak-builder
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
- name: ⬇️ Install dependencies
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt update
sudo bash dist/get_deps_debian.sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
sh rustup-init.sh -y --default-toolchain none
rm rustup-init.sh
$HOME/.cargo/bin/rustup install nightly
$HOME/.cargo/bin/rustup target add x86_64-unknown-linux-gnu
$HOME/.cargo/bin/rustup default nightly
- name: 🛠️ Build
run: |
mkdir -p build
cd build
CC=gcc-10 CXX=g++-10 cmake \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX="$PWD/install" \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_FLAGS="-fuse-ld=lld" \
-DCMAKE_CXX_FLAGS="-fuse-ld=lld" \
-DRUST_PATH="$HOME/.cargo/bin/" \
..
make -j 4 install
- name: 📦 Bundle Flatpak
run: |
sudo apt install flatpak flatpak-builder
flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak --user install -y flathub org.freedesktop.Platform//20.08
flatpak --user install -y flathub org.freedesktop.Sdk//20.08
flatpak-builder --jobs=4 --repo=imhex _flatpak dist/net.werwolv.ImHex.yaml --ccache --keep-build-dirs
flatpak build-bundle imhex imhex.flatpak net.werwolv.ImHex stable
- name: 📦 Bundle DEB
run: |
dpkg-deb --build build/install
mv build/install.deb imhex.deb
- name: 📦 Bundle AppImage
run: |
dist/AppImage/package.sh build
mv build/ImHex-x86_64.AppImage imhex.AppImage
- name: ⬆️ Upload ELF
uses: actions/upload-artifact@v2
with:
name: Linux ELF
path: |
build/install/*
- name: ⬆️ Upload Flatpak
uses: actions/upload-artifact@v2
with:
name: Linux Flatpak
path: |
imhex.flatpak
- name: ⬆️ Upload .deb
uses: actions/upload-artifact@v2
with:
name: Linux DEB
path: |
imhex.deb
- name: ⬆️ Upload AppImage
uses: actions/upload-artifact@v2
with:
name: Linux AppImage
path: |
imhex.AppImage
# Windows build
win:
runs-on: windows-latest
name: 🟦 Windows MINGW64
@ -164,8 +65,7 @@ jobs:
with:
path: ${{ steps.prep-ccache.outputs.dir }}
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
- name: 🛠️ Build
run: |
@ -203,6 +103,7 @@ jobs:
path: |
build/*.msi
# MacOS build
macos:
runs-on: macos-11.0
name: 🍎 macOS 11.0
@ -224,8 +125,7 @@ jobs:
path: |
~/.ccache
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
- name: 🛠️ Build
run: |
@ -241,8 +141,6 @@ jobs:
-DCREATE_PACKAGE=ON \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_FLAGS="-fuse-ld=lld" \
-DCMAKE_CXX_FLAGS="-fuse-ld=lld" \
..
make -j4 package
@ -251,3 +149,103 @@ jobs:
with:
name: macOS DMG
path: build/*.dmg
# Linux build
linux:
runs-on: ubuntu-20.04
name: 🐧 Ubuntu 20.04
steps:
- name: 🧰 Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: recursive
- name: 📜 Restore cache
uses: actions/cache@v2
with:
path: |
~/.ccache
.flatpak-builder
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
- name: ⬇️ Install dependencies
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt update
sudo bash dist/get_deps_debian.sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
sh rustup-init.sh -y --default-toolchain none
rm rustup-init.sh
$HOME/.cargo/bin/rustup install nightly
$HOME/.cargo/bin/rustup target add x86_64-unknown-linux-gnu
$HOME/.cargo/bin/rustup default nightly
- name: 🛠️ Build
run: |
mkdir -p build
cd build
CC=gcc-10 CXX=g++-10 cmake \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX="$PWD/install" \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_FLAGS="-fuse-ld=lld" \
-DCMAKE_CXX_FLAGS="-fuse-ld=lld" \
-DRUST_PATH="$HOME/.cargo/bin/" \
..
make -j 4 install
- name: 📦 Bundle Flatpak
run: |
sudo apt install flatpak flatpak-builder
flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak --user install -y flathub org.freedesktop.Platform//20.08
flatpak --user install -y flathub org.freedesktop.Sdk//20.08
flatpak-builder --jobs=4 --repo=imhex _flatpak dist/net.werwolv.ImHex.yaml --ccache --keep-build-dirs
flatpak build-bundle imhex imhex.flatpak net.werwolv.ImHex stable
- name: 📦 Bundle DEB
run: |
dpkg-deb --build build/install
mv build/install.deb imhex.deb
- name: 📦 Bundle AppImage
run: |
dist/AppImage/package.sh build
mv build/ImHex-x86_64.AppImage imhex.AppImage
- name: ⬆️ Upload ELF
uses: actions/upload-artifact@v2
with:
name: Linux ELF
path: |
build/install/*
- name: ⬆️ Upload Flatpak
uses: actions/upload-artifact@v2
with:
name: Linux Flatpak
path: |
imhex.flatpak
- name: ⬆️ Upload .deb
uses: actions/upload-artifact@v2
with:
name: Linux DEB
path: |
imhex.deb
- name: ⬆️ Upload AppImage
uses: actions/upload-artifact@v2
with:
name: Linux AppImage
path: |
imhex.AppImage

View File

@ -27,8 +27,8 @@ jobs:
with:
path: |
~/.ccache
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ github.run_id }}
restore-keys: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-
key: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: ${{ runner.os }}-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
- name: ⬇️ Install dependencies
run: |

View File

@ -9,53 +9,30 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
set(IMHEX_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR})
include("${CMAKE_SOURCE_DIR}/cmake/build_helpers.cmake")
# List plugin names here. Project name must match folder name
set(PLUGINS
builtin
windows
# example_cpp
# example_rust
)
detectOS()
detectArch()
# Make sure project is configured correctly
setDefaultBuiltTypeIfUnset()
detectBadClone()
# Add bundled dependencies
# List plugin names here. Project name must match folder name
set(PLUGINS
builtin
windows
)
# Add various defines
detectOS()
detectArch()
addVersionDefines()
configurePackingResources()
# Add ImHex sources
add_subdirectory(plugins/libimhex)
add_subdirectory(main)
add_custom_target(imhex ALL DEPENDS main)
# Add include directories
include_directories(include)
# Add unit tests
enable_testing()
add_subdirectory(tests EXCLUDE_FROM_ALL)
addVersionDefines()
configurePackageCreation()
add_executable(imhex ${application_type}
source/main.cpp
source/window/window.cpp
source/window/win_window.cpp
source/window/macos_window.cpp
source/window/linux_window.cpp
source/init/splash_window.cpp
source/init/tasks.cpp
source/helpers/plugin_manager.cpp
${imhex_icon}
)
set_target_properties(imhex PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(imhex PROPERTIES POSITION_INDEPENDENT_CODE ON)
if (WIN32)
target_link_libraries(imhex PUBLIC dl libimhex wsock32 ws2_32 Dwmapi.lib)
else ()
target_link_libraries(imhex PUBLIC dl libimhex pthread)
endif ()
# Configure packaging
createPackage()

View File

@ -87,7 +87,7 @@ macro(detectArch)
endmacro()
macro(configurePackageCreation)
macro(configurePackingResources)
option (CREATE_PACKAGE "Create a package with CPack" OFF)
if (APPLE)
@ -96,7 +96,7 @@ macro(configurePackageCreation)
if (WIN32)
set(application_type)
set(imhex_icon "${CMAKE_SOURCE_DIR}/res/resource.rc")
set(IMHEX_ICON "${CMAKE_SOURCE_DIR}/resources/resource.rc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-subsystem,windows")
@ -105,19 +105,19 @@ macro(configurePackageCreation)
set(CPACK_PACKAGE_NAME "ImHex")
set(CPACK_PACKAGE_VENDOR "WerWolv")
set(CPACK_WIX_UPGRADE_GUID "05000E99-9659-42FD-A1CF-05C554B39285")
set(CPACK_WIX_PRODUCT_ICON "${PROJECT_SOURCE_DIR}/res/icon.ico")
set(CPACK_WIX_PRODUCT_ICON "${PROJECT_SOURCE_DIR}/resources/icon.ico")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "ImHex")
set_property(INSTALL "$<TARGET_FILE_NAME:imhex>"
set_property(INSTALL "$<TARGET_FILE_NAME:main>"
PROPERTY CPACK_START_MENU_SHORTCUTS "ImHex"
)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/res/LICENSE.rtf")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/resources/LICENSE.rtf")
endif()
elseif (APPLE)
set (imhex_icon "${CMAKE_SOURCE_DIR}/res/mac/AppIcon.icns")
set (IMHEX_ICON "${CMAKE_SOURCE_DIR}/resources/AppIcon.icns")
if (CREATE_BUNDLE)
set(application_type MACOSX_BUNDLE)
set_source_files_properties(${imhex_icon} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_source_files_properties(${IMHEX_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set(MACOSX_BUNDLE_ICON_FILE "AppIcon.icns")
set(MACOSX_BUNDLE_INFO_STRING "WerWolv")
set(MACOSX_BUNDLE_BUNDLE_NAME "ImHex")
@ -157,7 +157,7 @@ macro(createPackage)
install(TARGETS ${plugin} RUNTIME DESTINATION ${PLUGINS_INSTALL_LOCATION})
elseif (APPLE)
if (CREATE_BUNDLE)
set_target_properties(${plugin} PROPERTIES LIBRARY_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:imhex>/${PLUGINS_INSTALL_LOCATION})
set_target_properties(${plugin} PROPERTIES LIBRARY_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:main>/${PLUGINS_INSTALL_LOCATION})
else ()
set_target_properties(${plugin} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins)
endif ()
@ -183,7 +183,7 @@ macro(createPackage)
INSTALL(CODE "LIST(APPEND DEP_FOLDERS \${PY_PARENT})")
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES $<TARGET_FILE:builtin> $<TARGET_FILE:libimhex> $<TARGET_FILE:imhex>
EXECUTABLES $<TARGET_FILE:builtin> $<TARGET_FILE:libimhex> $<TARGET_FILE:main>
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
CONFLICTING_DEPENDENCIES_PREFIX _c_deps
@ -211,27 +211,27 @@ macro(createPackage)
configure_file(${CMAKE_SOURCE_DIR}/dist/DEBIAN/control.in ${CMAKE_BINARY_DIR}/DEBIAN/control)
install(FILES ${CMAKE_BINARY_DIR}/DEBIAN/control DESTINATION ${CMAKE_INSTALL_PREFIX}/DEBIAN)
install(FILES ${CMAKE_SOURCE_DIR}/dist/imhex.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/share/applications)
install(FILES ${CMAKE_SOURCE_DIR}/res/icon.png DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/share/pixmaps RENAME imhex.png)
install(FILES ${CMAKE_SOURCE_DIR}/resources/icon.png DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/share/pixmaps RENAME imhex.png)
endif()
if (CREATE_BUNDLE)
include(PostprocessBundle)
# Fix rpath
add_custom_command(TARGET imhex POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/" $<TARGET_FILE:imhex>)
add_custom_command(TARGET imhex POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/" $<TARGET_FILE:main>)
# FIXME: Remove this once we move/integrate the plugins directory.
add_custom_target(build-time-make-plugins-directory ALL COMMAND ${CMAKE_COMMAND} -E make_directory "${bundle_path}/Contents/MacOS/plugins")
# Update library references to make the bundle portable
postprocess_bundle(imhex)
postprocess_bundle(imhex main)
# Enforce DragNDrop packaging.
set(CPACK_GENERATOR "DragNDrop")
install(TARGETS imhex BUNDLE DESTINATION .)
install(TARGETS main BUNDLE DESTINATION .)
else()
install(TARGETS imhex RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS main RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

View File

@ -13,9 +13,9 @@
if(CMAKE_GENERATOR)
# Being called as include(PostprocessBundle), so define a helper function.
set(_POSTPROCESS_BUNDLE_MODULE_LOCATION "${CMAKE_CURRENT_LIST_FILE}")
function(postprocess_bundle target)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -DBUNDLE_PATH="$<TARGET_FILE_DIR:${target}>/../.." -DCODE_SIGN_CERTIFICATE_ID="${CODE_SIGN_CERTIFICATE_ID}"
function(postprocess_bundle out_target in_target)
add_custom_command(TARGET ${out_target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -DBUNDLE_PATH="$<TARGET_FILE_DIR:${in_target}>/../.." -DCODE_SIGN_CERTIFICATE_ID="${CODE_SIGN_CERTIFICATE_ID}"
-P "${_POSTPROCESS_BUNDLE_MODULE_LOCATION}"
)
endfunction()
@ -58,5 +58,4 @@ if (CODE_SIGN_CERTIFICATE_ID)
endif()
# Add a necessary rpath to the imhex binary
get_bundle_main_executable("${BUNDLE_PATH}" IMHEX_EXECUTABLE)
execute_process(COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath @executable_path/../Frameworks/ "${IMHEX_EXECUTABLE}")
get_bundle_main_executable("${BUNDLE_PATH}" IMHEX_EXECUTABLE)

View File

@ -1,3 +1,3 @@
set (CPACK_BUNDLE_NAME "ImHex")
set (CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/res/mac/AppIcon.icns" )
set (CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/resources/AppIcon.icns" )
set (CPACK_BUNDLE_PLIST "${CMAKE_BINARY_DIR}/ImHex.app/Contents/Info.plist")

2
dist/Brewfile vendored
View File

@ -1,4 +1,4 @@
brew "glfw3"
brew "glfw"
brew "mbedtls"
brew "nlohmann-json"
brew "cmake"

2
external/libromfs vendored

@ -1 +1 @@
Subproject commit 63edca64c7b68a835e5a574cbede114b1541c380
Subproject commit 5b79535ee0fa53da7ffbaef4f37842651f7d2e65

31
main/CMakeLists.txt Normal file
View File

@ -0,0 +1,31 @@
project(main)
add_executable(main ${application_type}
source/main.cpp
source/window/window.cpp
source/window/win_window.cpp
source/window/macos_window.cpp
source/window/linux_window.cpp
source/init/splash_window.cpp
source/init/tasks.cpp
source/helpers/plugin_manager.cpp
${IMHEX_ICON}
)
target_include_directories(main PUBLIC include)
set_target_properties(main PROPERTIES
OUTPUT_NAME "imhex"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..
CXX_VISIBILITY_PRESET hidden
POSITION_INDEPENDENT_CODE ON)
if (WIN32)
target_link_libraries(main PUBLIC dl libimhex wsock32 ws2_32 Dwmapi.lib)
else ()
target_link_libraries(main PUBLIC dl libimhex pthread)
endif ()

View File

@ -13,7 +13,7 @@ set_target_properties(microtar PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/nativefiledialog ${CMAKE_CURRENT_BINARY_DIR}/external/nativefiledialog EXCLUDE_FROM_ALL)
set_target_properties(nfd PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(LIBROMFS_RESOURCE_LOCATION ${IMHEX_BASE_FOLDER}/res/resources)
set(LIBROMFS_RESOURCE_LOCATION ${IMHEX_BASE_FOLDER}/resources/romfs)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/libromfs ${CMAKE_CURRENT_BINARY_DIR}/external/libromfs EXCLUDE_FROM_ALL)
set_target_properties(libromfs PROPERTIES POSITION_INDEPENDENT_CODE ON)

View File

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB