Skip to content

Commit b60fc07

Browse files
authored
Merge pull request #1 from certik/cmake
Initial project structure
2 parents 23c8ec4 + 0ca8bb1 commit b60fc07

File tree

7 files changed

+156
-0
lines changed

7 files changed

+156
-0
lines changed

CMakeLists.txt

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
enable_language(C Fortran)
3+
project(symengine.f90)
4+
5+
set(CMAKE_PREFIX_PATH ${SymEngine_DIR} ${CMAKE_PREFIX_PATH})
6+
find_package(SymEngine 0.3.0 REQUIRED CONFIG
7+
PATH_SUFFIXES lib/cmake/symengine cmake/symengine CMake/)
8+
message("SymEngine_DIR : " ${SymEngine_DIR})
9+
set(CMAKE_BUILD_TYPE ${SYMENGINE_BUILD_TYPE})
10+
set(CMAKE_CXX_FLAGS_RELEASE ${SYMENGINE_CXX_FLAGS_RELEASE})
11+
set(CMAKE_CXX_FLAGS_DEBUG ${SYMENGINE_CXX_FLAGS_DEBUG})
12+
include_directories(${SYMENGINE_INCLUDE_DIRS})
13+
14+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
15+
16+
if (MINGW AND ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8"))
17+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DMS_WIN64")
18+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DMS_WIN64")
19+
endif()
20+
21+
if (MINGW AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
22+
try_compile(CHECK_PYTHON_HYPOT "${CMAKE_CURRENT_BINARY_DIR}/" "${CMAKE_SOURCE_DIR}/cmake/check_python_hypot.cpp")
23+
if (NOT ${CHECK_PYTHON_HYPOT})
24+
# include cmath before all headers
25+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -include cmath")
26+
endif()
27+
endif()
28+
29+
if(SYMENGINE_MPC_LIBRARIES)
30+
set(HAVE_SYMENGINE_MPC True)
31+
else()
32+
set(HAVE_SYMENGINE_MPC False)
33+
endif()
34+
35+
if(SYMENGINE_MPFR_LIBRARIES)
36+
set(HAVE_SYMENGINE_MPFR True)
37+
else()
38+
set(HAVE_SYMENGINE_MPFR False)
39+
endif()
40+
41+
if(SYMENGINE_PIRANHA_INCLUDE_DIRS)
42+
set(HAVE_SYMENGINE_PIRANHA True)
43+
else()
44+
set(HAVE_SYMENGINE_PIRANHA False)
45+
endif()
46+
47+
if(SYMENGINE_FLINT_LIBRARIES)
48+
set(HAVE_SYMENGINE_FLINT True)
49+
else()
50+
set(HAVE_SYMENGINE_FLINT False)
51+
endif()
52+
53+
if(SYMENGINE_LLVM_COMPONENTS)
54+
set(HAVE_SYMENGINE_LLVM True)
55+
else()
56+
set(HAVE_SYMENGINE_LLVM False)
57+
endif()
58+
59+
message("CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}")
60+
message("CMAKE_CXX_FLAGS_RELEASE : ${CMAKE_CXX_FLAGS_RELEASE}")
61+
message("CMAKE_CXX_FLAGS_DEBUG : ${CMAKE_CXX_FLAGS_DEBUG}")
62+
message("HAVE_SYMENGINE_MPFR : ${HAVE_SYMENGINE_MPFR}")
63+
message("HAVE_SYMENGINE_MPC : ${HAVE_SYMENGINE_MPC}")
64+
message("HAVE_SYMENGINE_PIRANHA : ${HAVE_SYMENGINE_PIRANHA}")
65+
message("HAVE_SYMENGINE_FLINT : ${HAVE_SYMENGINE_FLINT}")
66+
message("HAVE_SYMENGINE_LLVM : ${HAVE_SYMENGINE_LLVM}")
67+
68+
enable_testing()
69+
70+
add_subdirectory(src)

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# symengine.f90
2+
23
Fortran wrappers of SymEngine
4+
5+
## Installation
6+
7+
Install SymEngine:
8+
9+
cmake -DCMAKE_INSTALL_PREFIX=/some/path .
10+
make
11+
make install
12+
13+
Install SymEngine.f90:
14+
15+
cmake -DCMAKE_PREFIX_PATH=/some/path .
16+
make
17+
make install

src/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(SRC
2+
wrapper.c
3+
basic.f90
4+
)
5+
6+
add_library(symengine_f90 ${SRC})
7+
target_link_libraries(symengine_f90 ${SYMENGINE_LIBRARIES})
8+
9+
add_subdirectory(tests)

src/basic.f90

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module basic
2+
use iso_c_binding, only: c_int
3+
implicit none
4+
5+
interface
6+
subroutine f_c(i) bind(c, name="f")
7+
import :: c_int
8+
integer(c_int), value, intent(in) :: i
9+
end subroutine
10+
end interface
11+
12+
contains
13+
14+
subroutine f(i)
15+
integer, intent(in) :: i
16+
call f_c(i)
17+
end subroutine
18+
19+
end module

src/tests/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include_directories(${PROJECT_BINARY_DIR}/src)
2+
3+
macro(ADDTEST name)
4+
add_executable(${name} ${name}.f90)
5+
target_link_libraries(${name} symengine_f90)
6+
add_test(${name} ${PROJECT_BINARY_DIR}/${name})
7+
endmacro(ADDTEST)
8+
9+
project(tests)
10+
11+
ADDTEST(test_basic)

src/tests/test_basic.f90

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
program test_basic
2+
use basic, only: f
3+
implicit none
4+
5+
call f(1)
6+
call f(2)
7+
call f(3)
8+
9+
end program

src/wrapper.c

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <symengine/cwrapper.h>
2+
3+
void f(int i)
4+
{
5+
char *s;
6+
basic x, y, e, n;
7+
basic_new_stack(x);
8+
basic_new_stack(y);
9+
basic_new_stack(e);
10+
basic_new_stack(n);
11+
symbol_set(x, "x");
12+
symbol_set(y, "y");
13+
integer_set_si(n, i);
14+
basic_mul(e, n, x);
15+
basic_add(e, e, y);
16+
s = basic_str(e);
17+
printf("Result: %s\n", s);
18+
basic_str_free(s);
19+
basic_free_stack(x);
20+
basic_free_stack(y);
21+
basic_free_stack(e);
22+
basic_free_stack(n);
23+
}

0 commit comments

Comments
 (0)