<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.openhitls</groupId>
    <artifactId>sdf4j-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>SDF4J Parent</name>
    <description>openHiTLS SDF4J Parent - Java binding for GM/T 0018-2023 SDF (密码设备应用接口)</description>
    <url>https://github.com/openhitls/sdf4j</url>

    <organization>
        <name>openHitls</name>
        <url>https://github.com/openhitls</url>
    </organization>

    <modules>
        <module>sdf4j</module>
        <module>sdf4j-jce</module>
        <module>examples</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>4.13.2</junit.version>
        <!-- CMake构建配置 -->
        <cmake.build.type>RelWithDebInfo</cmake.build.type>
        <cmake.generator>Unix Makefiles</cmake.generator>
        <!-- CMake额外选项 - 编译时可通过 -Dcmake.extra.options="-DFOO=bar" 指定 -->
        <!-- 例如: -Dcmake.extra.options="-DENABLE_SANITIZER=ON -DCMAKE_C_FLAGS=-fsanitize=address" -->
        <cmake.extra.options></cmake.extra.options>
        <!-- SDF库配置 - 编译时可通过 -Dsdf.library.name=xxx 指定 -->
        <!-- 默认库名称: sdf (对应 libsdf.so) -->
        <sdf.library.name>sdf</sdf.library.name>
        <!-- 默认库路径: 空(从系统路径查找) -->
        <sdf.library.path></sdf.library.path>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <!-- Java编译插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>

                <!-- 测试插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.2</version>
                    <configuration>
                        <argLine>-Djava.library.path=${project.basedir}/../sdf4j-core/target/native</argLine>
                        <forkCount>1</forkCount>
                        <reuseForks>false</reuseForks>
                        <!-- 使用系统类加载器 -->
                        <useSystemClassLoader>true</useSystemClassLoader>
                    </configuration>
                </plugin>

                <!-- JAR打包插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.2.0</version>
                </plugin>

                <!-- 源码打包插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.2.1</version>
                </plugin>

                <!-- Javadoc插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.3.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <!-- 构建配置文件 - 支持不同构建类型 -->
    <profiles>
        <!-- Debug模式:启用调试符号,禁用优化 -->
        <profile>
            <id>debug</id>
            <properties>
                <cmake.build.type>Debug</cmake.build.type>
            </properties>
        </profile>

        <!-- Release模式:启用优化,禁用调试符号 -->
        <profile>
            <id>release</id>
            <properties>
                <cmake.build.type>Release</cmake.build.type>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <version>3.4.1</version>
                        <executions>
                            <execution>
                                <id>forbid-debug-sanitizer-options-in-release</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>enforce</goal>
                                </goals>
                                <configuration>
                                    <rules>
                                        <requireProperty>
                                            <property>cmake.extra.options</property>
                                            <regex>^((?!(?i:fsanitize|asan|ubsan|msan|tsan|-O0|\s-g(\s|$))).)*$</regex>
                                            <message>Release profile forbids debug/sanitizer options in -Dcmake.extra.options. Use -Pdebug (or script/build_with_simulator.sh asan) for memory diagnostics.</message>
                                        </requireProperty>
                                    </rules>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- 默认模式:带调试符号的优化版本 -->
        <profile>
            <id>relwithdebinfo</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <cmake.build.type>RelWithDebInfo</cmake.build.type>
            </properties>
        </profile>

        <!-- 仅构建核心库,不构建示例 -->
        <profile>
            <id>core-only</id>
            <modules>
                <module>sdf4j</module>
            </modules>
        </profile>

        <!-- 仅运行示例(需要先构建核心库) -->
        <profile>
            <id>examples-only</id>
            <modules>
                <module>examples</module>
            </modules>
        </profile>
    </profiles>
</project>