Make CMake's output executable optional.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / general / cmake / CMakeBuildTaskAction.java
blobd11b7b3b0c971b7d799c1968a8d163621e57d689
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.plugin.general.cmake;
12 import java.io.FileNotFoundException;
13 import java.io.IOException;
14 import java.nio.file.Files;
15 import java.nio.file.Path;
16 import java.util.concurrent.TimeUnit;
17 import org.gradle.api.Action;
18 import org.gradle.api.Task;
19 import org.gradle.api.logging.LogLevel;
21 /**
22 * Actual build task for CMake projects.
24 * @since 2024/03/15
26 public class CMakeBuildTaskAction
27 implements Action<Task>
29 /**
30 * {@inheritDoc}
31 * @since 2024/03/15
33 @Override
34 public void execute(Task __task)
36 CMakeBuildTask from = (CMakeBuildTask)__task;
38 Path cmakeSource = from.cmakeSource;
39 Path cmakeBuild = from.cmakeBuild;
41 try
43 // Make sure the output build directory exists
44 Files.createDirectories(cmakeBuild);
46 // Configure CMake first
47 CMakeUtils.cmakeExecute(__task.getLogger(),
48 "configure",
49 cmakeBuild,
50 "-S", cmakeSource.toAbsolutePath().toString(),
51 "-B", cmakeBuild.toAbsolutePath().toString());
53 // Then perform the actual build
54 CMakeUtils.cmakeExecute(__task.getLogger(),
55 "build",
56 cmakeBuild,
57 "--build", cmakeBuild.toAbsolutePath().toString(),
58 "-t", from.cmakeRule);
60 // Was the output file even created?
61 if (from.cmakeOutFile != null && !Files.exists(from.cmakeOutFile))
62 throw new FileNotFoundException(
63 "Could not find output library: " +
64 from.cmakeOutFile);
66 catch (IOException __e)
68 throw new RuntimeException("CMake Build Failed.", __e);