<?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

      https://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.tsfile</groupId>
        <artifactId>tsfile-parent</artifactId>
        <version>2.4.0</version>
    </parent>
    <artifactId>tsfile-cpp</artifactId>
    <packaging>pom</packaging>
    <name>TsFile: C++</name>
    <properties>
        <!-- Tell Sonar where to find the sources -->
        <sonar.sources>common,examples,tsfile</sonar.sources>
        <sonar.cfamily.build-wrapper-output>${project.build.directory}/build-wrapper-output</sonar.cfamily.build-wrapper-output>
        <coverage.enabled>OFF</coverage.enabled>
        <build.type>Release</build.type>
        <enable.asan>OFF</enable.asan>
        <build.test>ON</build.test>
        <enable.snappy>ON</enable.snappy>
        <enable.lz4>ON</enable.lz4>
        <enable.lzokay>ON</enable.lzokay>
        <enable.zlib>ON</enable.zlib>
        <enable.antlr4>ON</enable.antlr4>
        <enable.simd>ON</enable.simd>
    </properties>
    <build>
        <sourceDirectory>${project.basedir}</sourceDirectory>
        <plugins>
            <!--
                Do the actual build.
            -->
            <plugin>
                <groupId>com.googlecode.cmake-maven-project</groupId>
                <artifactId>cmake-maven-plugin</artifactId>
                <executions>
                    <!-- Generate the configuration for the main compilation -->
                    <!--execution>
                      <id>cmake-generate-compile</id>
                      <phase>compile</phase>
                      <goals>
                        <goal>generate</goal>
                      </goals>
                    </execution>
                    <!- Compile the main code ->
                    <execution>
                      <id>cmake-execute-compile</id>
                      <phase>compile</phase>
                      <goals>
                        <goal>compile</goal>
                      </goals>
                    </execution-->
                    <!-- Generate the configuration for the test compilation -->
                    <execution>
                        <id>cmake-generate-test-compile</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <options>
                                <option>-DBUILD_PHASE=test-compile</option>
                                <option>-DCOV_ENABLED=${coverage.enabled}</option>
                                <option>-DCMAKE_BUILD_TYPE=${build.type}</option>
                                <option>-DENABLE_ASAN=${enable.asan}</option>
                                <option>-DBUILD_TEST=${build.test}</option>
                                <option>-DENABLE_ANTLR4=${enable.antlr4}</option>
                                <option>-DENABLE_SNAPPY=${enable.snappy}</option>
                                <option>-DENABLE_LZ4=${enable.lz4}</option>
                                <option>-DENABLE_LZOKAY=${enable.lzokay}</option>
                                <option>-DENABLE_ZLIB=${enable.zlib}</option>
                                <option>-DENABLE_SIMD=${enable.simd}</option>
                                <!--
                                    The Visual Studio generator additionally
                                    needs -DCMAKE_GENERATOR_PLATFORM (and
                                    optionally -DCMAKE_GENERATOR_TOOLSET). Those
                                    options are appended by the cpp-msvc /
                                    cpp-msvc-toolset profiles below rather than
                                    listed here: an empty <option/> element is
                                    deserialized as null, which makes the cmake
                                    plugin's generate goal throw an NPE.
                                -->
                            </options>
                            <sourcePath/>
                            <targetPath/>
                        </configuration>
                    </execution>
                    <!-- Compile the test code -->
                    <execution>
                        <id>cmake-execute-test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <!--
                                Build configuration for multi-config generators
                                (Visual Studio). Ignored by single-config
                                generators such as the Makefile generators.
                            -->
                            <config>${build.type}</config>
                        </configuration>
                    </execution>
                    <!-- Execute the tests -->
                    <execution>
                        <id>cmake-run-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <buildDirectory>${project.build.directory}/build/test</buildDirectory>
                            <!-- Test configuration for multi-config generators (Visual Studio). -->
                            <config>${build.type}</config>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <!--
                        Actually the path to the CMakeList.txt file which then again
                        tells to tool where to find the sources.
                    -->
                    <sourcePath>${project.basedir}</sourcePath>
                    <!--
                        Path to where the build configuration is generated
                        (This directory is then used in the compile step to actually perform the build)
                    -->
                    <targetPath>${project.build.directory}/build</targetPath>
                    <!--
                        Name of the generator the compile step will be executing.
                    -->
                    <generator>${cmake.generator}</generator>
                    <!-- The directory where the "generate" step generated the build configuration -->
                    <projectDirectory>${project.build.directory}/build</projectDirectory>
                </configuration>
            </plugin>
            <!-- Overwrite test config-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <!-- rename the cmake binary and generate a script that adds the sonar build-wrapper -->
                    <execution>
                        <id>sync-project-version</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>${project.basedir}/VersionUpdater.groovy</source>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.groovy</groupId>
                        <artifactId>groovy</artifactId>
                        <version>${groovy.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>jenkins-build</id>
            <!-- This is needed by the groovy hack script -->
            <properties>
                <cmake.root>${project.build.directory}/dependency/cmake/bin</cmake.root>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.googlecode.maven-download-plugin</groupId>
                        <artifactId>download-maven-plugin</artifactId>
                        <executions>
                            <!-- Get the build-wrapper from our sonarcloud server -->
                            <execution>
                                <id>get-build-wrapper</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>wget</goal>
                                </goals>
                                <configuration>
                                    <skipCache>true</skipCache>
                                    <url>https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip</url>
                                    <unpack>true</unpack>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <skipCache>true</skipCache>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>with-code-coverage</id>
            <properties>
                <coverage.enabled>ON</coverage.enabled>
            </properties>
        </profile>
        <!--
            MSVC (Visual Studio generator) needs the target platform passed at
            generate time. Activated by -Dcpp.toolchain=msvc, matching the
            root pom cpp-msvc profile that switches cmake.generator. The option
            is appended to the cmake-generate-test-compile execution so it is
            only present for MSVC builds (an empty <option/> would be null).
        -->
        <profile>
            <id>cpp-msvc</id>
            <activation>
                <property>
                    <name>cpp.toolchain</name>
                    <value>msvc</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.googlecode.cmake-maven-project</groupId>
                        <artifactId>cmake-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>cmake-generate-test-compile</id>
                                <configuration>
                                    <options combine.children="append">
                                        <option>-DCMAKE_GENERATOR_PLATFORM=${msvc.platform}</option>
                                    </options>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!--
            Pins the MSVC toolset when -Dmsvc.toolset is supplied (e.g.
            -Dmsvc.toolset=v141 to build with the VS 2017 compiler). Self-
            activating on the presence of the property, so it composes with
            cpp-msvc regardless of how that profile was activated. Without the
            property CMake uses the generator's default toolset.
        -->
        <profile>
            <id>cpp-msvc-toolset</id>
            <activation>
                <property>
                    <name>msvc.toolset</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.googlecode.cmake-maven-project</groupId>
                        <artifactId>cmake-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>cmake-generate-test-compile</id>
                                <configuration>
                                    <options combine.children="append">
                                        <option>-DCMAKE_GENERATOR_TOOLSET=${msvc.toolset}</option>
                                    </options>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>.java-9-and-above</id>
            <activation>
                <jdk>[9,)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.diffplug.spotless</groupId>
                        <artifactId>spotless-maven-plugin</artifactId>
                        <version>2.44.3</version>
                        <configuration>
                            <cpp>
                                <includes>
                                    <!-- You have to set the target manually -->
                                    <include>bench_mark/**/*.h</include>
                                    <include>bench_mark/**/*.cc</include>
                                    <include>examples/**/*.h</include>
                                    <include>examples/**/*.c</include>
                                    <include>examples/**/*.cc</include>
                                    <include>src/**/*.h</include>
                                    <include>src/**/*.c</include>
                                    <include>src/**/*.cc</include>
                                    <include>test/**/*.h</include>
                                    <include>test/**/*.c</include>
                                    <include>test/**/*.cc</include>
                                </includes>
                                <clangFormat>
                                    <!--pathToExe>/path/to/buf</pathToExe-->
                                    <!-- optional: if clang-format isn't in your path -->
                                    <version>${clang.format.version}</version>
                                    <style>file</style>
                                    <!-- optional: can be LLVM, Google, Chromium, Mozilla, WebKit -->
                                </clangFormat>
                            </cpp>
                            <lineEndings>UNIX</lineEndings>
                            <skip>${spotless.skip}</skip>
                        </configuration>
                        <executions>
                            <execution>
                                <id>spotless-check</id>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                                <phase>validate</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
