-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
78 lines (60 loc) · 2.63 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
cmake_minimum_required(VERSION 3.22)
project(nature C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_VERBOSE_MAKEFILE OFF)
include(cmake/cross.cmake)
file(READ "VERSION" PROJECT_VERSION)
# 打印当前的项目版本
message("nature version: ${PROJECT_VERSION}")
message("cmake workdir: ${CMAKE_CURRENT_BINARY_DIR}")
string(TIMESTAMP BUILD_TIME "%Y-%m-%d")
message("build time: ${BUILD_TIME}")
# 设置 release 模式下的优化等级
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(BUILD_TYPE "release")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(BUILD_TYPE "release")
endif ()
# 设置 debug 模式下编译输出
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(BUILD_TYPE "debug")
# add_compile_definitions(NATURE_DEBUG)
add_compile_definitions(DEBUG_LIR)
add_compile_definitions(DEBUG_ASM)
add_compile_definitions(DEBUG_PARSER)
# add_compile_definitions(DEBUG_INTERVAL)
# add_compile_definitions(DEBUG_MACHO)
add_compile_definitions(ASSERT_ERROR)
# set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O2")
message("cmake type is debug")
endif ()
configure_file("${PROJECT_SOURCE_DIR}/config/config.h.in" "${PROJECT_SOURCE_DIR}/config/config.h")
aux_source_directory(${PROJECT_SOURCE_DIR}/cmd CMD)
file(GLOB_RECURSE SRC ${PROJECT_SOURCE_DIR}/src/*.c)
aux_source_directory(${PROJECT_SOURCE_DIR}/utils UTILS)
aux_source_directory(${PROJECT_SOURCE_DIR}/utils/ymal UTILS)
# include 搜索路径, 有了这个就不需要在 add_executable 中声明 .h 文件了
include_directories(./include)
include_directories(.)
add_executable(nature main.c ${SRC} ${CMD} ${UTILS})
target_link_libraries(nature m) # 链接数学计算库
# custom golang build package
set(PACKAGE_BINARY_NAME npkg)
set(GOBIN /usr/local/go/bin/go)
set(PACKAGE_BINARY_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_BINARY_NAME})
enable_testing()
add_subdirectory(tests)
add_subdirectory(runtime EXCLUDE_FROM_ALL)
add_custom_target(${PACKAGE_BINARY_NAME} ALL
COMMAND GOOS=${CMAKE_SYSTEM_NAME} GOARCH=${CMAKE_SYSTEM_PROCESSOR} ${GOBIN} build -o ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_BINARY_NAME} ${PROJECT_SOURCE_DIR}/package/main.go
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/package
COMMENT "package manager npkg"
)
#--------------------------------- install ---------------------------------
install(TARGETS nature DESTINATION nature/bin)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_BINARY_NAME} DESTINATION nature/bin)
install(DIRECTORY lib/ DESTINATION nature/lib)
install(DIRECTORY std/ DESTINATION nature/std)
install(FILES LICENSE DESTINATION nature/)
install(FILES VERSION DESTINATION nature/)
include(cmake/cpack.cmake)