Run makefile produced by cmake that is inside build and also run test

217 views
Skip to first unread message

Sunny Shakya

unread,
Sep 9, 2016, 11:55:42 AM9/9/16
to cmake-maven-project-users
I am using cmake-maven to build the cmake project that I have. The build works fine. But there are three issues I am facing.

  1. How to clean the build folder before each maven install?
  2. I also need to run make so that I can hook it up with Teamcity. Is there any way to run make as well from the build folder. Right now, I am using build.sh but I want to replace it with pom.xml. 

#!/bin/bash  
rm -fdr build
mkdir build
cd build
CC=gcc cmake ..
make
ctest -V

  3. I am not able to run test at all. It says "Cannot find file: /home/sshakya/coeTest/target/DartConfiguration.tcl". I also read previous posts and see that I have to put "include(CTest)" in top level CMakeLists.txt instead of enable_testing() but it didnot work.  I have test folder with googletest and here is the CMakeLists.txt content


cmake_minimum_required(VERSION 2.6.2)

project( googletest-distribution )

#enable_testing()
include(CTest)
option(BUILD_GTEST "Builds the googletest subproject" OFF)

#Note that googlemock target already builds googletest
option(BUILD_GMOCK "Builds the googlemock subproject" ON)

if(BUILD_GMOCK)
  add_subdirectory( googlemock )
elseif(BUILD_GTEST)
  add_subdirectory( googletest )
endif()

Here is the content of pom.xml

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ciena.bp</groupId>
    <artifactId>coe</artifactId>
    <version>0.0.4</version>
    <packaging>pom</packaging>

    <!--<parent>
      <groupId>com.ciena.bp</groupId>
      <artifactId>maven-parent-pom</artifactId>
      <version>0.0.3</version>
    </parent>  -->

<build>
<plugins>
<plugin>
 <groupId>com.googlecode.cmake-maven-project</groupId>
 <artifactId>cmake-maven-plugin</artifactId>
 <version>3.4.1-b1</version>
 <executions>
<execution>
 <id>cmake-generate</id>
 <goals>
<goal>generate</goal>
 </goals>
 <configuration>
<sourcePath>./</sourcePath>
<targetPath>./build</targetPath>
<generator>Unix Makefiles</generator>
<options>
 <option>-DBUILD_THIRDPARTY:bool=on</option> 
</options>
 </configuration>
</execution>
<execution>
 <id>cmake-test</id>
 <goals>
<goal>test</goal>
 </goals>
 <configuration>
<!-- "buildDirectory" is "targetPath" from the "generate" goal --> 
<buildDirectory>${project.build.directory}</buildDirectory>
<!-- Optional way to not fail the build on test failures -->
<!-- <testFailureIgnore>true</testFailureIgnore> -->
<!-- Optional way to skip just the ctest tests -->
<!-- <ctest.skip.tests>true</ctest.skip.tests> -->
<!-- Optional/standard way to skip all Maven tests -->
<!-- <maven.test.skip>true</maven.test.skip> -->
<!-- Optional way to configure number of threads tests should use -->
<!-- <threadCount>2</threadCount> -->
<!-- Optional dashboard configuration; used with CTestConfig.cmake -->
<!-- <dashboard>Experimental</dashboard> -->
 </configuration>
</execution>
 </executions>
</plugin>
</plugins>
</build>
</project>

Kevin S. Clarke

unread,
Oct 26, 2016, 6:07:51 PM10/26/16
to cmake-maven-project-users
Hi Sunny, sorry for the delay in responding. I somehow missed this when you first wrote it.  I imagine you've moved onto other things by now but I'll respond anyway.


On Friday, September 9, 2016 at 11:55:42 AM UTC-4, Sunny Shakya wrote:
I am using cmake-maven to build the cmake project that I have. The build works fine. But there are three issues I am facing.

  1. How to clean the build folder before each maven install?

`mvn clean` will remove the target folder where cmake will build to. It will remove all transient parts of the Maven build, though, not just the cmake generated stuff.
 
  2. I also need to run make so that I can hook it up with Teamcity. Is there any way to run make as well from the build folder. Right now, I am using build.sh but I want to replace it with pom.xml. 

#!/bin/bash  
rm -fdr build
mkdir build
cd build
CC=gcc cmake ..
make
ctest -V

You can run make directly from a Maven build with exec-maven-plugin (completely unrelated to cmake-maven-project). A sample configuration for that is:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>default</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <workingDirectory>${project.basedir}/${kakadu.version}/make</workingDirectory>
              <executable>make</executable>
              <arguments>
                <argument>-f</argument>
                <argument>${kakadu.makefile}</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>clean</id>
            <phase>clean</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <workingDirectory>${project.basedir}/${kakadu.version}/make</workingDirectory>
              <executable>make</executable>
              <arguments>
                <argument>-f</argument>
                <argument>${kakadu.makefile}</argument>
                <argument>clean</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

You'd swap in variables for your values there. Exec-maven-plugin can also run other types of shell commands (not specific to make) if there are other parts of a Bash script you're trying to replace but can't find Maven plugins to do the work that needs to be done.

Kevin
Reply all
Reply to author
Forward
0 new messages