<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
  -->
<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>

  <parent>
    <groupId>org.apache.plc4x</groupId>
    <artifactId>plc4x-tools</artifactId>
    <version>0.6.0</version>
  </parent>

  <artifactId>plc4x-tools-boost</artifactId>
  <packaging>pom</packaging>

  <name>Tools: Boost</name>
  <description>Building of the Boost library.</description>

  <!-- Disabled for now as C++ support is currently not installed in Apache SonarQube -->
  <!--properties>
    <sonar.language>c++</sonar.language>
  </properties-->

  <build>
    <plugins>
      <!-- First download the cmake binaries and sources for building the boost library -->
      <plugin>
        <groupId>com.googlecode.maven-download-plugin</groupId>
        <artifactId>download-maven-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
          <execution>
            <id>get-boost</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>wget</goal>
            </goals>
            <configuration>
              <url>${boost.url}</url>
              <unpack>true</unpack>
              <outputDirectory>${project.build.directory}</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!--
        Then execute two boost build phases:

        1) bootstrap the boost build
        2) Perform the actual boost build and install
      -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <id>bootstrap-boost</id>
            <phase>process-sources</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>${boost.bootstrap.executable}</executable>
              <arguments>
                <!-- Use clang instead of gcc as this requires far less memory -->
                <argument>--with-toolset=clang</argument>
              </arguments>
              <workingDirectory>${project.build.directory}/boost_${boost.version.underline}</workingDirectory>
            </configuration>
          </execution>
          <execution>
            <id>compile-boost</id>
            <phase>process-sources</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>${boost.build.executable}</executable>
              <arguments>
                <!-- Have the build install the built libraries -->
                <argument>install</argument>
                <!-- Tell it where to install the libraries and header files -->
                <argument>--prefix=${project.build.directory}/lib/boost</argument>
                <!-- List of modules to build -->
                <argument>--with-system</argument>
                <argument>--with-thread</argument>
                <argument>--with-date_time</argument>
                <argument>--with-regex</argument>
                <argument>--with-log</argument>
                <!-- On Windows machines the build failed, if this was not explicitly set -->
                <argument>address-model=64</argument>
                <!-- On Linux machines the build failed, if this is not set -->
                <argument>cxxflags=-fPIC</argument>
              </arguments>
              <workingDirectory>${project.build.directory}/boost_${boost.version.underline}</workingDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Build a zip artifact containing the boost library -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.1</version>
        <executions>
          <execution>
            <id>package-boost-library</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <finalName>${project.artifactId}-${project.version}</finalName>
              <descriptors>
                <descriptor>src/assembly/bundle.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>