我有一些带有预处理程序指令的fortran源。我通常在Makefile中使用ifort -cpp -DOPT1 -DOPT2 ...
对其进行编译。现在,我尝试更改为cmake,并使用target_compile_definitions(target PUBLIC OPT1)
添加这些选项。但是当我运行编译时,该命令仅显示ifort -DOPT1 -DOPT2 ...
,因此失败。
我已阅读到某些编译器默认情况下设置了此标志,例如gfortran:
-cpp -nocpp Enable preprocessing. The preprocessor is automatically invoked if the file extension is .fpp, .FPP, .F, .FOR, .FTN, .F90, .F95, .F03 or .F08. Use this option to manually enable preprocessing of any kind of Fortran file.
但看起来似乎不是ifort的明显情况:
-cpp Runs the Fortran preprocessor on source files prior to compilation (same as the -fpp option).
我在cmake中错过了添加该标记的选项吗?如果没有,使用cmake命令手动添加它的正确方法是什么?
谢谢!
答案 0 :(得分:1)
如果您有 CMake 3.18 或更高版本,请使用 Fortran_PREPROCESS
属性:
public static void main(String[] args) throws IOException, InterruptedException {
long startTime = System.currentTimeMillis();
List<String> ips = FileUtils.readLines(new File("ip.txt"), "utf-8");
if (!ips.isEmpty()) {
ExecutorService executorService = Executors.newFixedThreadPool(100);
for (String ip : ips) {
executorService.execute(() -> {
if ("nmap".equals(args[0])) {
checkPortNmap(ip);
} else {
checkPort(ip);
}
});
}
executorService.shutdown();
executorService.awaitTermination(60, TimeUnit.SECONDS);
while (!executorService.isTerminated()) {
}
}
System.out.println(args[0] + "\t" + TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
}
public static String checkPort(String ip) {
System.out.println("SOCK: " + ip);
String message = "ok";
try {
try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress(ip, 22), 6000);
}
} catch (IOException ex) {
message = ex.getMessage();
}
return message;
}
private static void checkPortNmap(String ip) {
ProcessBuilder processBuilder = new ProcessBuilder().redirectErrorStream(true);
processBuilder.command("bash", "-c", "nmap -Pn -sS -p22 " + ip);
if (showProcess(processBuilder)) {
System.out.println("IP: " + ip);
}
}
private static boolean showProcess(ProcessBuilder processBuilder) {
try {
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String read;
while ((read = reader.readLine()) != null) {
System.out.println(read);
if (read.contains("open")) {
return true;
}
}
} catch (IOException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
return false;
}