-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·127 lines (97 loc) · 3.75 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
add_subdirectory(cNARS)
# set cmake version
cmake_minimum_required(VERSION 3.25)
# Exclude all targets of cNARS except for narsese
get_property(CNARS_TARGETS DIRECTORY cNARS PROPERTY BUILDSYSTEM_TARGETS)
foreach(target IN LISTS CNARS_TARGETS)
if(NOT ${target} STREQUAL "narsese")
set_target_properties(${target} PROPERTIES EXCLUDE_FROM_ALL ON)
endif()
endforeach()
# C++ settings
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_SH "CMAKE_SH-NOTFOUND")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_BUILD_TYPE Debug)
# set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
# target_compile_definitions(narsese PRIVATE DEBUG)
project(SLM) # Sequential Learning Model
find_package(fmt)
# Add Boost header files and Python header files
include_directories(
${Boost_INCLUDE_DIRS}
)
include_directories(
"${PROJECT_SOURCE_DIR}/cNARS"
"${PROJECT_SOURCE_DIR}/cpp"
${pybind11_INCLUDE_DIR}
${pybind11_INCLUDE_DIRS}
)
# message(SOURCES_NARSESE=${SOURCES_NARSESE})
file(GLOB SOURCES_SEQUENTIAL_GROUP
cpp/src/*.cpp
)
pybind11_add_module(SequentialGroup ${SOURCES_SEQUENTIAL_GROUP} cNARS/Narsese.cpp ${SOURCES_NARSESE} ${SOURCES_UTILS} ${SOURCES_PARSER} ${SOURCES_CONFIG} ${SOURCES_INTERPRETER})
target_include_directories(SequentialGroup PUBLIC
"cNARS"
"cNARS/Narsese"
"cNARS/Narsese/Parser"
"cNARS/Interpreter"
"cNARS/utils"
)
find_package(Boost 1.45.0 COMPONENTS spirit)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(SequentialGroup ${Boost_LIBRARIES})
target_link_libraries(SequentialGroup PRIVATE fmt::fmt)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# message("================")
# set(PACKAGE_NAME ".")
# libraries
set(SLM_PACKAGE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
file(WRITE "${SLM_PACKAGE_DIR}/__init__.py" "")
function(add_module MODULE_NAME)
if(ARGC GREATER_EQUAL 2)
list(GET ${ARGV} 2 MODULE_SOURCE)
endif()
message("-------- add module --------")
message("name: ${MODULE_NAME}")
if(DEFINED ${MODULE_SOURCE})
message("path: ${MODULE_SOURCE}")
set(SLM_MODULE "SLM_${MODULE_NAME}")
else()
set(SLM_MODULE "${MODULE_NAME}")
endif()
message(${SLM_MODULE})
if(DEFINED MODULE_SOURCE)
add_library(${SLM_MODULE} MODULE ${MODULE_SOURCE})
target_link_libraries(${SLM_MODULE} SLM)
endif()
set_target_properties(${SLM_MODULE} PROPERTIES PREFIX "")
set_target_properties(${SLM_MODULE} PROPERTIES OUTPUT_NAME "${MODULE_NAME}")
# set_target_properties(${SLM_MODULE} PROPERTIES SUFFIX ".so")
set(file_root "${SLM_PACKAGE_DIR}/${MODULE_NAME}")
# set(file_root "${SLM_PACKAGE_DIR}")
set_target_properties(${SLM_MODULE} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${file_root})
file(WRITE "${SLM_PACKAGE_DIR}/${MODULE_NAME}/__init__.py" "from .${MODULE_NAME} import *\n")
endfunction()
add_module(SequentialGroup)
add_module(narsese)
target_link_libraries(SequentialGroup PRIVATE fmt::fmt)
target_include_directories(SequentialGroup PRIVATE ${fmt_INCLUDE_DIRS})
message("================")
# generate stub files
message(PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR})
# message(PACKAGE_NAME=${PACKAGE_NAME})
add_custom_target(GENERATE_PYI ALL
COMMENT "Trying to generate .pyi files ..."
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND pwd
# COMMAND python generate_stub.py -p ${PACKAGE_NAME}
COMMAND python generate_stub.py -p "narsese"
COMMAND python generate_stub.py -p "SequentialGroup"
)
add_dependencies(SequentialGroup narsese)
add_dependencies(GENERATE_PYI SequentialGroup)
# list(REMOVE_ITEM all_targets GENERATE_PYI)
# add_dependencies(GENERATE_PYI all_targets)