Skip to content

Commit

Permalink
Switch to CMake for native mac build
Browse files Browse the repository at this point in the history
    - Added build docs
    - Hopefully works on M1

Closes GH-7
  • Loading branch information
LavenderSnek committed Jul 4, 2024
1 parent 23ec85f commit a0ac780
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 71 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ out/
target/
*.iml
*.ppf
cmake-build-*/

# Misc.
*.class
Expand All @@ -24,7 +25,7 @@ nb-configuration.xml

# native
*.xcodeproj/
src/main/headers/
src/main/native/headers/

# Windows
Thumbs.db
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ShimejiEE Cross Platform

https://github.com/LavenderSnek/ShimejiEE-cross-platform

The releases aren't updated frequently, so build it from source for the latest release.
The releases aren't updated frequently, [build from source](docs/building.md) for the latest version.

This project is a fork of [Kilkakon's shimeji version](http://kilkakon.com/shimeji) and incorporates the work from [nonowarn's shimeji4mac](https://github.com/nonowarn/shimeji4mac)

Expand Down Expand Up @@ -35,6 +35,10 @@ Installation
Credits
-------

- LavenderSnek
- macOS maintainer (this fork)
- [Github page](https://github.com/LavenderSnek/ShimejiEE-cross-platform)

- Kilkakon
- Current maintainer. Added sounds, affordances, and japanese conf compatibility.
- [Homepage](http://kilkakon.com/shimeji)
Expand Down
65 changes: 65 additions & 0 deletions docs/building.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

Building
========

This doc covers building through command line.
IDE setup should be relatively straightforward, though I have had occasional issues with setting `JAVA_HOME` properly for cmake.

Common TLDR Guide
-----------------
Try this before wasting your time reading the rest of this docs.

- Make sure `JAVA_HOME` is JDK 17
- Run `mvn clean package`
- Fix anything it complains about (i.e. missing tools)
- Try again

The final shimeji folder will be in `target/ShimejiEE`

To skip native build, disable the `cmake` profile in maven

macOS
-----

This guide uses [Homebrew](https://brew.sh/) to install dependencies.

### Install Dependencies

```shell
# java
brew install maven
brew install openjdk@17

# symlink java (see https://formulae.brew.sh/formula/openjdk@17)
sudo ln -sfn $HOMEBREW_PREFIX/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

# native (if you'll be building the JNI libs)
brew install cmake
brew install ninja
```

### Setup Java

Make sure that `JAVA_HOME` is set to the correct version.
If you symlinked java in the previous step here's a nice shortcut ([more info](https://stackoverflow.com/questions/21964709/)).

```shell
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
```

### Build

The following command cleans any build files and builds ShimejiEE along with the native libraries for macOS.
```shell
mvn clean package
```

If you want to skip building native libs, use this command.
```shell
mvn clean package -P '!cmake'
```

### Run
```shell
java -jar target/ShimejiEE/ShimejiEE.jar
```
33 changes: 0 additions & 33 deletions docs/settings-reference.md

This file was deleted.

1 change: 0 additions & 1 deletion ext-resources/lib/readme.txt

This file was deleted.

86 changes: 76 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.main>com.group_finity.mascot.Main</project.main>
<project.finalShimejiOut>${project.build.directory}/${project.name}</project.finalShimejiOut>
<project.headerDir>src/main/native/headers</project.headerDir>
</properties>

<dependencies>
Expand All @@ -37,31 +38,95 @@
</dependency>
</dependencies>

<!-- Native Build -->
<profiles>
<profile>
<id>mac</id>
<activation><os><family>mac</family></os></activation>
<properties>
<project.nativeBaseDir>src/main/native/macjni</project.nativeBaseDir>
<project.nativeBuildDir>${project.build.directory}/cmake-build-macjni</project.nativeBuildDir>
</properties>
</profile>

<!-- Cmake Common -->
<profile>
<id>cmake</id>
<activation><os><family>mac</family></os></activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>cmake</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>bash</executable>
<arguments>
<argument>-c</argument>
<argument>
cmake \
-G Ninja \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${project.finalShimejiOut}/lib \
-S ${project.nativeBaseDir} \
-B ${project.nativeBuildDir};
cmake --build ${project.nativeBuildDir}
</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>


<!-- Common build -->
<build>
<plugins>
<!-- tests -->
<!-- Clean headers -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<filesets>
<fileset>
<directory>${project.headerDir}</directory>
</fileset>
</filesets>
</configuration>
</plugin>

<!-- Run tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
<version>3.3.0</version>
</plugin>

<!-- jni header generation -->
<!-- Compile with header generation -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.13.0</version>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>src/main/headers</arg>
<arg>${project.headerDir}</arg>
</compilerArgs>
</configuration>
</plugin>

<!-- Copy external resources to build folder -->
<!-- Copy external resources -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-ext-resources</id>
Expand All @@ -87,11 +152,11 @@
</execution>
</executions>
</plugin>

<!-- create shaded jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -123,6 +188,7 @@
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
50 changes: 50 additions & 0 deletions src/main/native/macjni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

cmake_minimum_required(VERSION 3.24)

set(CMAKE_OSX_ARCHITECTURES arm64 x86_64)
set(ONLY_ACTIVE_ARCH NO)

enable_language(OBJC)

project(ShimejiMacJni)

add_library(ShimejiMacJni SHARED)

# disable ARC
target_compile_options(ShimejiMacJni PUBLIC -fno-objc-arc)

# JNI
find_package(Java 17 REQUIRED COMPONENTS Development)
find_package(JNI REQUIRED)
target_include_directories(ShimejiMacJni PUBLIC ${JNI_INCLUDE_DIRS})

# Cocoa
find_library(COCOA_LIB Cocoa)
target_link_libraries(ShimejiMacJni ${COCOA_LIB})

# sources
target_include_directories(ShimejiMacJni PUBLIC src)
target_include_directories(ShimejiMacJni PUBLIC ../headers)

target_sources(ShimejiMacJni PRIVATE
src/JdkCode.m
src/JdkCode.h
src/JniHelper.m
src/JniHelper.h

src/rendering/MacJniNativeImage.m
src/rendering/MacJniShimejiWindow.m
src/rendering/ShimejiWindow.m
src/rendering/ShimejiWindow.h

src/environment/MacJniEnvironment.m
src/environment/ShimejiEnvironment.m
src/environment/ShimejiEnvironment.h

src/menu/MacJniMenu.m
src/menu/JniMenuListener.m
src/menu/JniMenuListener.h
src/menu/MacJniMenuItem.m
src/menu/MacJniMenuItem.h
)

25 changes: 0 additions & 25 deletions src/main/native/macjni/project.yml

This file was deleted.

0 comments on commit a0ac780

Please sign in to comment.