forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
97 lines (80 loc) · 3.04 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_SOURCE_DIR}/cmake/UserOverride.cmake)
project(lfortran C CXX)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release
CACHE STRING "Build type (Debug, Release)" FORCE)
endif ()
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR
CMAKE_BUILD_TYPE STREQUAL "Release"))
message("${CMAKE_BUILD_TYPE}")
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of: Debug, Release (current value: '${CMAKE_BUILD_TYPE}')")
endif ()
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17
CACHE STRING "C++ standard" FORCE)
endif ()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# In Debug mode we enable assertions
set(WITH_LFORTRAN_ASSERT_DEFAULT yes)
else()
set(WITH_LFORTRAN_ASSERT_DEFAULT no)
endif()
# LFORTRAN_ASSERT
set(WITH_LFORTRAN_ASSERT ${WITH_LFORTRAN_ASSERT_DEFAULT}
CACHE BOOL "Enable LFORTRAN_ASSERT macro")
# LLVM
set(WITH_LLVM no CACHE BOOL "Build with LLVM support")
if (WITH_LLVM)
set(LFORTRAN_LLVM_COMPONENTS core support mcjit orcjit native asmparser asmprinter)
find_package(LLVM REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
llvm_map_components_to_libnames(llvm_libs ${LFORTRAN_LLVM_COMPONENTS})
unset(LFORTRAN_LLVM_COMPONENTS)
add_library(p::llvm INTERFACE IMPORTED)
set_property(TARGET p::llvm PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${LLVM_INCLUDE_DIRS})
#set_property(TARGET p::llvm PROPERTY INTERFACE_COMPILE_DEFINITIONS
# ${LLVM_DEFINITIONS})
#set_property(TARGET p::llvm PROPERTY INTERFACE_COMPILE_OPTIONS
# ${LLVM_DEFINITIONS})
set_property(TARGET p::llvm PROPERTY INTERFACE_LINK_LIBRARIES
${llvm_libs})
endif()
# JSON
set(WITH_JSON no CACHE BOOL "Build with JSON support")
if (WITH_JSON)
find_package(RapidJSON REQUIRED)
endif()
# Python
set(WITH_PYTHON no CACHE BOOL "Build with Python wrappers")
if (WITH_PYTHON)
cmake_minimum_required(VERSION 3.12.4 FATAL_ERROR)
find_package(Python REQUIRED COMPONENTS Interpreter Development)
endif()
enable_testing()
message("\n")
message("Configuration results")
message("---------------------")
message("C compiler : ${CMAKE_C_COMPILER}")
message("C++ compiler : ${CMAKE_CXX_COMPILER}")
message("Build type: ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("C compiler flags : ${CMAKE_C_FLAGS_DEBUG}")
message("C++ compiler flags : ${CMAKE_CXX_FLAGS_DEBUG}")
else ()
message("C compiler flags : ${CMAKE_C_FLAGS_RELEASE}")
message("C++ compiler flags : ${CMAKE_CXX_FLAGS_RELEASE}")
endif ()
message("Installation prefix: ${CMAKE_INSTALL_PREFIX}")
message("WITH_LFORTRAN_ASSERT: ${WITH_LFORTRAN_ASSERT}")
message("WITH_LLVM: ${WITH_LLVM}")
message("WITH_JSON: ${WITH_JSON}")
message("WITH_PYTHON: ${WITH_PYTHON}")
add_subdirectory(src)
if (WITH_PYTHON)
add_subdirectory(lfortran/parser)
endif()