Skip to content

Commit

Permalink
Support macOS in CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqr committed Jul 12, 2021
1 parent 86f1cd4 commit 639da32
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 24 deletions.
31 changes: 14 additions & 17 deletions .github/workflows/gha-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, macos-10.15]
build_suite: [autoconf]
build_suite: [autoconf, cmake]
with_coveralls: [no]
include:
# Do one build with cmake instead of autoconf
- os: ubuntu-20.04
build_suite: cmake
with_coveralls: no
# And run one build with gcov and coveralls
# (Does currently not work, but neither did it in travis)
#- os: ubuntu-20.04
# build_suite: autoconf
# with_coveralls: yes
# Run one build with gcov and coveralls
# (Does currently not work, but neither did it in travis)
#include:
# - os: ubuntu-20.04
# build_suite: autoconf
# with_coveralls: yes
runs-on: ${{ matrix.os }}

steps:
Expand Down Expand Up @@ -89,13 +85,14 @@ jobs:
run: |
if [ "x${{ matrix.build_suite }}" = "xautoconf" ] ; then
./autogen.sh
conf_success=0
./configure --enable-debug || conf_success=1
[ "$conf_success" -eq 0 ] || (cat config.log; exit 1)
./configure --enable-debug || (cat config.log; exit 1)
else
mkdir build-dir
cd build-dir
cmake -DCMAKE_CXX_FLAGS='-Wall -Wextra -Wno-unused-parameter -pedantic' -DCMAKE_C_FLAGS='-Wall -Wextra -Wno-unused-parameter' -DWITH_STARTUPLOG=ON -DWITH_TEST=ON ..
if (echo "${{ matrix.os }}" | grep -qE '^macos-') ; then
CMAKE_PLATFORM_OPTIONS='-DICU_INCLUDE_DIR=/usr/local/opt/icu4c/include -DICU_UC_LIBRARY_RELEASE=/usr/local/opt/icu4c/lib/libicuuc.dylib -DICU_IN_LIBRARY_RELEASE=/usr/local/opt/icu4c/lib/libicui18n.dylib'
fi
cmake -DCMAKE_CXX_FLAGS='-Wall -Wextra -Wno-unused-parameter -pedantic' -DCMAKE_C_FLAGS='-Wall -Wextra -Wno-unused-parameter' -DWITH_STARTUPLOG=ON -DWITH_TEST=ON $CMAKE_PLATFORM_OPTIONS .. || (cat CMakeFiles/CMakeOutput.log CMakeFiles/CMakeError.log; exit 1)
fi
- name: build
Expand All @@ -116,13 +113,13 @@ jobs:
> /dev/null
- name: package
if: ${{ startsWith( matrix.os, 'macos-' ) }}
if: ${{ startsWith( matrix.os, 'macos-' ) && matrix.build_suite == 'autoconf' }}
run: |
make osx-dmg
mv *.dmg aegisub-macos-GHA.dmg
- name: upload artifact
if: ${{ startsWith( matrix.os, 'macos-' ) }}
if: ${{ startsWith( matrix.os, 'macos-' ) && matrix.build_suite == 'autoconf' }}
uses: actions/upload-artifact@v2
with:
name: aegisub-macos-GHA
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if(UNIX)
add_executable(aegisub-lua EXCLUDE_FROM_ALL
automation/tests/aegisub.cpp
)
target_link_libraries(aegisub-lua PRIVATE libaegisub luabins luajit "Boost::locale")
target_link_libraries(aegisub-lua PRIVATE libaegisub luabins luajit "Boost::locale" "ICU::in")
add_custom_target(test-automation
COMMAND sh -c "$(luarocks path); ${PROJECT_BINARY_DIR}/aegisub-lua tests/busted.lua -p moon tests/modules"
VERBATIM
Expand Down
53 changes: 50 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0074 NEW)
include(CheckIncludeFiles)

project(Aegisub)

Expand All @@ -12,6 +13,7 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

## Build bundled LuaJIT with aegisub specific patches
add_executable(luajit-minilua vendor/luajit/src/host/minilua.c)
if(NOT WIN32)
target_link_libraries(luajit-minilua m)
Expand All @@ -32,6 +34,13 @@ if(WIN32)
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src
)
endif()
elseif(APPLE)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/gen/buildvm_arch.h"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/gen"
COMMAND luajit-minilua ../dynasm/dynasm.lua -D P64 -D JIT -D FFI -D FPU -D HFABI -D VER= -o "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/gen/buildvm_arch.h" vm_x64.dasc
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src
)
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_custom_command(
Expand Down Expand Up @@ -61,7 +70,12 @@ add_executable(luajit-buildvm
)
target_compile_definitions(luajit-buildvm PRIVATE LUAJIT_ENABLE_LUA52COMPAT)
target_include_directories(luajit-buildvm PRIVATE vendor/luajit/src "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/gen")
if(UNIX)
if(APPLE)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/lj_vm.s"
COMMAND luajit-buildvm -m machasm -o "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/lj_vm.s"
)
elseif(UNIX)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/lj_vm.s"
COMMAND luajit-buildvm -m elfasm -o "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/lj_vm.s"
Expand Down Expand Up @@ -186,9 +200,14 @@ else()
set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/vendor/luajit/src/lj_vm.s" PROPERTY LANGUAGE C)
target_link_libraries(luajit ${CMAKE_DL_LIBS})
endif()
if(APPLE)
target_compile_definitions(luajit-buildvm PRIVATE LUAJIT_ENABLE_GC64)
target_compile_definitions(luajit PRIVATE LUAJIT_ENABLE_GC64)
endif()

add_subdirectory(vendor/luabins)

## libaegisub
add_library(libaegisub STATIC
libaegisub/common/parser.cpp
libaegisub/ass/dialogue_parser.cpp
Expand Down Expand Up @@ -238,6 +257,7 @@ add_library(libaegisub STATIC
libaegisub/common/ycbcr_conv.cpp
libaegisub/common/dispatch.cpp
)
target_compile_features(libaegisub PUBLIC cxx_std_11)
if(UNIX)
target_sources(libaegisub PRIVATE
libaegisub/unix/access.cpp
Expand All @@ -262,10 +282,22 @@ elseif(WIN32)
libaegisub/windows/util_win.cpp
)
endif()
if(APPLE)
target_sources(libaegisub PRIVATE
libaegisub/osx/dispatch.mm
libaegisub/osx/spellchecker.mm
libaegisub/osx/util.mm
)
endif()
set_target_properties(libaegisub PROPERTIES PREFIX "")
target_compile_definitions(libaegisub PRIVATE CMAKE_BUILD)
target_include_directories(libaegisub PUBLIC "libaegisub/include")
target_precompile_headers(libaegisub PRIVATE "libaegisub/lagi_pre.h")
if(APPLE)
# CMake on macOS currently does not support pch with objc, so use the old way
target_compile_options(libaegisub PRIVATE -include "${PROJECT_SOURCE_DIR}/libaegisub/lagi_pre.h")
else()
target_precompile_headers(libaegisub PRIVATE "libaegisub/lagi_pre.h")
endif()
target_link_libraries(libaegisub PRIVATE luajit luabins)

add_custom_command(
Expand All @@ -283,6 +315,7 @@ add_custom_command(

add_subdirectory("vendor/csri")

## Aegisub
add_executable(Aegisub WIN32
"${CMAKE_CURRENT_BINARY_DIR}/src/libresrc/bitmap.h"
"${CMAKE_CURRENT_BINARY_DIR}/src/libresrc/default_config.h"
Expand Down Expand Up @@ -454,7 +487,12 @@ add_executable(Aegisub WIN32
target_link_libraries(Aegisub PRIVATE ${CMAKE_DL_LIBS} libaegisub luajit)
target_compile_definitions(Aegisub PRIVATE CMAKE_BUILD)
target_include_directories(Aegisub PRIVATE "src/libresrc" "${CMAKE_CURRENT_BINARY_DIR}/src/libresrc")
target_precompile_headers(Aegisub PRIVATE "src/agi_pre.h")
if(APPLE)
# CMake on macOS currently does not support pch with objc, so use the old way
target_compile_options(Aegisub PRIVATE -include "${PROJECT_SOURCE_DIR}/src/agi_pre.h")
else()
target_precompile_headers(Aegisub PRIVATE "src/agi_pre.h")
endif()

if(WIN32)
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/build/git_version.h")
Expand Down Expand Up @@ -490,12 +528,17 @@ if(MSVC)
#target_sources(Aegisub PRIVATE src/res/res.rc src/res/strings.rc src/crash_writer_minidump.cpp)
target_sources(Aegisub PRIVATE src/res/res.rc src/res/strings.rc src/crash_writer.cpp src/dpi_aware.manifest)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Aegisub)
elseif(APPLE)
target_include_directories(Aegisub PRIVATE src) # For src/retina_helper.h
target_sources(Aegisub PRIVATE src/crash_writer.cpp src/osx/osx_utils.mm src/osx/retina_helper.mm)
else()
target_sources(Aegisub PRIVATE src/crash_writer.cpp)
endif()

if(WIN32)
target_sources(Aegisub PRIVATE src/font_file_lister_gdi.cpp)
elseif(APPLE)
target_sources(Aegisub PRIVATE src/font_file_lister_coretext.mm)
else()
find_package(Fontconfig REQUIRED)
target_link_libraries(Aegisub PRIVATE "Fontconfig::Fontconfig")
Expand All @@ -513,6 +556,10 @@ target_link_libraries(Aegisub PRIVATE "Boost::headers" "Boost::container" "Boost

find_package(OpenGL REQUIRED)
target_link_libraries(Aegisub PRIVATE "OpenGL::GL")
check_include_files(OpenGL/gl.h HAVE_OPENGL_GL_H)
if(HAVE_OPENGL_GL_H)
target_compile_definitions(Aegisub PRIVATE "HAVE_OPENGL_GL_H")
endif()

find_package(Iconv REQUIRED)
target_link_libraries(libaegisub PRIVATE "Iconv::Iconv")
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.com/wangqr/Aegisub.svg?branch=dev)](https://travis-ci.com/wangqr/Aegisub)
[![Build Status](https://github.com/wangqr/Aegisub/actions/workflows/gha-ci.yml/badge.svg)](https://github.com/wangqr/Aegisub/actions/workflows/gha-ci.yml)

# Aegisub

Expand Down Expand Up @@ -50,9 +50,9 @@ cd Aegisub
make
```

### CMake (for Windows and linux)
### CMake (for Windows, linux and macOS)

This fork also provides CMake build. The CMake project will only build Aegisub itself, without the translation.
This fork also provides CMake build. The CMake project will only build Aegisub itself, without the translation. Currently only x86 and x64 are supported due to limited support for building LuaJIT using CMake.

You still need to install the dependencies above. To enable AviSynth+ support, it is also needed. Installing dependencies on Windows can be tricky, as Windows doesn't have a good package manager. Refer to [the Wiki page](https://github.com/wangqr/Aegisub/wiki/Compile-guide-for-Windows-(CMake,-MSVC)) on how to get all dependencies on Windows.

Expand Down

0 comments on commit 639da32

Please sign in to comment.