<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.github.umjammer</groupId>
  <artifactId>vavi-image-jpegxl</artifactId>
  <version>0.0.7</version>
  <url>https://github.com/umjammer/vavi-image-jpegxl</url>
  <properties>
    <jnaerator.version>0.12</jnaerator.version>
    <native.prefix>/usr/local</native.prefix>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.junit</groupId>
        <artifactId>junit-bom</artifactId>
        <version>5.11.4</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.github.umjammer</groupId>
      <artifactId>vavi-image</artifactId>
      <version>1.0.13</version>
    </dependency>
    <dependency>
      <groupId>net.java.dev.jna</groupId>
      <artifactId>jna</artifactId>
      <version>5.17.0</version>
    </dependency>
    <dependency>
      <groupId>org.scijava</groupId>
      <artifactId>native-lib-loader</artifactId>
      <version>2.5.0</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-commons</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <version>1.7.36</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
    </repository>
  </repositories>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.12.1</version>
        <configuration>
          <release>17</release>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.2.5</version>
        <configuration>
          <argLine>-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties
            -Djava.library.path=${project.build.testOutputDirectory}
            -Djna.library.path=@{native.prefix}/lib</argLine>
          <trimStackTrace>false</trimStackTrace>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>mac arm64</id>
      <activation>
        <os>
          <family>mac</family>
          <arch>aarch64</arch>
        </os>
      </activation>
      <properties>
        <native.arch>arm64</native.arch>
        <native.prefix>/opt/homebrew</native.prefix>
      </properties>
    </profile>
    <profile>
      <id>local (not on jitpack)</id>
      <activation>
        <os>
          <family>mac</family>
        </os>
        <property>
          <name>env.JITPACK</name>
          <value>!true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.12.1</version>
            <executions>
              <execution>
                <id>javah</id>
                <phase>compile</phase>
                <goals>
                  <goal>compile</goal>
                </goals>
                <configuration>
                  <compilerArgs>
                    <arg>-h</arg>
                    <arg>${project.build.directory}/native</arg>
                    <arg>-d</arg>
                    <arg>${project.build.directory}/native/classes</arg>
                  </compilerArgs>
                  <includes>
                    <include>org/jpeg/jpegxl/wrapper/DecoderJni.java</include>
                  </includes>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
              <execution>
                <id>javah</id>
                <phase>compile</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <mkdir dir="${project.build.outputDirectory}/natives/osx_${native.arch}" />
                  </target>
                  <failOnError>true</failOnError>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>native-maven-plugin</artifactId>
            <version>1.0-alpha-11</version>
            <extensions>true</extensions>
            <executions>
              <execution>
                <id>dylib</id>
                <phase>compile</phase>
                <goals>
                  <goal>compile</goal>
                  <goal>link</goal>
                </goals>
                <configuration>
                  <linkerEndOptions>
                    <linkerEndOption>-o ${project.build.outputDirectory}/natives/osx_${native.arch}/libjxlwrapper.dylib</linkerEndOption>
                  </linkerEndOptions>
                </configuration>
              </execution>
            </executions>
            <configuration>
              <javahOS>darwin</javahOS>
              <compilerProvider>generic</compilerProvider>
              <compilerStartOptions>
                <compilerStartOption>-g -Wall -O2 -fomit-frame-pointer -fPIC -std=c++11</compilerStartOption>
                <compilerStartOption>-arch ${native.arch}
                  -I${java.home}/include
                  -I${java.home}/include/darwin
                  -I${native.prefix}/include
                  -I${project.build.directory}/native</compilerStartOption>
              </compilerStartOptions>
              <sources>
                <source>
                  <directory>src/main/native</directory>
                  <fileNames>
                    <fileName>decoder_jni.cc</fileName>
                    <fileName>decoder_jni_onload.cc</fileName>
                  </fileNames>
                </source>
              </sources>
              <linkerStartOptions>
                <linkerStartOption>-dynamiclib -arch ${native.arch} -v
                  -L${native.prefix}/lib -lc++ -ljxl -ljxl_threads</linkerStartOption>
              </linkerStartOptions>
              <linkerFinalName />
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>on jitpack</id>
      <activation>
        <property>
          <name>env.JITPACK</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
              <execution>
                <id>assets-download</id>
                <phase>compile</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <mkdir dir="${project.build.outputDirectory}/natives/osx_arm64" />
                    <get usetimestamp="true" src="${project.url}/releases/download/${project.version}/libjxlwrapper.dylib" dest="${project.build.outputDirectory}/natives/osx_arm64" />
                  </target>
                  <failOnError>true</failOnError>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>jnaerator</id>
      <build>
        <plugins>
          <plugin>
            <groupId>com.nativelibs4java</groupId>
            <artifactId>maven-jnaerator-plugin</artifactId>
            <version>${jnaerator.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>generate</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <javaOutputDirectory>${project.build.sourceDirectory}</javaOutputDirectory>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
