Skip to content

Commit 571f9b0

Browse files
committed
add another cmake test
Signed-off-by: Jade Abraham <[email protected]>
1 parent 043aa93 commit 571f9b0

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

test/cmake/linkWithC.notest

Whitespace-only changes.

test/cmake/linkWithC/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.21.1)
2+
3+
find_package(chpl REQUIRED)
4+
5+
project(linkWithC LANGUAGES CHPL C)
6+
message(STATUS "Using chpl: ${CMAKE_CHPL_COMPILER}")
7+
8+
9+
add_executable(main)
10+
target_sources(main PRIVATE main.chpl src/adder.c)
11+
set_target_properties(main PROPERTIES LINKER_LANGUAGE CHPL)
12+
13+
# used by C compiler
14+
target_include_directories(main PRIVATE include)
15+
# used by Chapel compiler
16+
target_link_options(main PRIVATE -I${CMAKE_SOURCE_DIR}/include)
17+
18+
install(TARGETS main DESTINATION ".")

test/cmake/linkWithC/include/adder.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef MY_ADDER_H
2+
#define MY_ADDER_H
3+
4+
int add(int a, int b);
5+
6+
#endif

test/cmake/linkWithC/main.chpl

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use CTypes;
2+
require "adder.h";
3+
extern proc add(a: c_int, b: c_int): c_int;
4+
proc main() {
5+
writeln("Hello, world!");
6+
writeln("1 + 2 = ", add(1, 2));
7+
}

test/cmake/linkWithC/src/adder.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <adder.h>
2+
3+
int add(int a, int b) {
4+
return a + b;
5+
}

0 commit comments

Comments
 (0)