-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
107 lines (99 loc) · 4.65 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
# Concoct CMake Configuration
cmake_minimum_required(VERSION 3.1...3.5)
set(PROJECT concoct)
set(HASH_MAP_TEST hash_map_test)
set(INTERPRET_TEST interpret_test)
set(OBJECT_TEST object_test)
set(STACK_TEST stack_test)
set(INTERPRET_TEST interpret_test)
set(UNIT_TESTS unit_tests)
project(${PROJECT})
if(WIN32)
include_directories(include)
else()
include_directories(include lib/linenoise)
endif()
file(GLOB SOURCES src/*.c src/vm/*.c)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(HASH_MAP_TEST_SOURCES src/debug.c src/hash_map.c src/seconds.c src/tests/hash_map_test.c)
set(INTERPRET_TEST_SOURCES src/debug.c src/hash_map.c src/memory.c src/seconds.c src/stack.c
src/types.c src/vm/instructions.c src/vm/opcodes.c src/vm/vm.c src/tests/interpret_test.c)
set(OBJECT_TEST_SOURCES src/debug.c src/memory.c src/seconds.c src/types.c src/tests/object_test.c)
set(STACK_TEST_SOURCES src/debug.c src/hash_map.c src/memory.c src/seconds.c src/stack.c
src/types.c src/vm/instructions.c src/tests/stack_test.c)
set(UNIT_TESTS_SOURCES src/debug.c src/memory.c src/seconds.c src/types.c src/tests/unit_tests.c)
if(MSVC)
set(CMAKE_C_FLAGS "/W4 /WX /D_CRT_SECURE_NO_WARNINGS")
else()
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -O0")
endif()
if(NOT WIN32)
add_library(linenoise STATIC lib/linenoise/linenoise.c lib/linenoise/linenoise.h)
endif()
add_executable(${PROJECT} ${SOURCES})
add_executable(${HASH_MAP_TEST} ${HASH_MAP_TEST_SOURCES})
add_executable(${INTERPRET_TEST} ${INTERPRET_TEST_SOURCES})
add_executable(${OBJECT_TEST} ${OBJECT_TEST_SOURCES})
add_executable(${STACK_TEST} ${STACK_TEST_SOURCES})
add_executable(${UNIT_TESTS} ${UNIT_TESTS_SOURCES})
# Set default build type
if(NOT CMAKE_BUILD_TYPE)
message("Setting default build type to: Debug")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
# Populate git revision, git hash, build time, build date, and build type variables for improved version information
find_package(Git)
execute_process(COMMAND "${GIT_EXECUTABLE}" rev-list --count HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_REV ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_HASH ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
string(TIMESTAMP BUILD_TIME "%H:%M")
string(TIMESTAMP BUILD_DATE "%m-%d-%Y")
set(BUILD_TYPE "${CMAKE_BUILD_TYPE}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/version.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/include/version.h" @ONLY)
# Check for math library availability
include(CheckFunctionExists)
if(NOT ROUND_FUNCTION_EXISTS AND NOT NEED_LINKING_AGAINST_LIBM)
CHECK_FUNCTION_EXISTS(round ROUND_FUNCTION_EXISTS)
if(NOT ROUND_FUNCTION_EXISTS)
unset(ROUND_FUNCTION_EXISTS CACHE)
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
CHECK_FUNCTION_EXISTS(round ROUND_FUNCTION_EXISTS)
if(ROUND_FUNCTION_EXISTS)
set(NEED_LINKING_AGAINST_LIBM True CACHE BOOL "" FORCE)
else()
message(FATAL_ERROR "round() function is not available!")
endif()
endif()
endif()
if(NEED_LINKING_AGAINST_LIBM)
target_link_libraries(${PROJECT} m linenoise)
target_link_libraries(${HASH_MAP_TEST} m)
target_link_libraries(${INTERPRET_TEST} m)
target_link_libraries(${OBJECT_TEST} m)
target_link_libraries(${STACK_TEST} m)
target_link_libraries(${UNIT_TESTS} m)
else()
if(WIN32)
target_link_libraries(${PROJECT})
else()
target_link_libraries(${PROJECT} linenoise)
endif()
target_link_libraries(${HASH_MAP_TEST})
target_link_libraries(${INTERPRET_TEST})
target_link_libraries(${OBJECT_TEST})
target_link_libraries(${STACK_TEST})
target_link_libraries(${UNIT_TESTS})
endif()
# Strip binary for release builds
if(CMAKE_BUILD_TYPE STREQUAL Release)
add_custom_command(TARGET ${PROJECT} POST_BUILD COMMAND ${CMAKE_STRIP} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT})
add_custom_command(TARGET ${HASH_MAP_TEST} POST_BUILD COMMAND ${CMAKE_STRIP} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${HASH_MAP_TEST})
add_custom_command(TARGET ${INTERPRET_TEST} POST_BUILD COMMAND ${CMAKE_STRIP} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${INTERPRET_TEST})
add_custom_command(TARGET ${OBJECT_TEST} POST_BUILD COMMAND ${CMAKE_STRIP} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${OBJECT_TEST})
add_custom_command(TARGET ${STACK_TEST} POST_BUILD COMMAND ${CMAKE_STRIP} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${STACK_TEST})
add_custom_command(TARGET ${UNIT_TESTS} POST_BUILD COMMAND ${CMAKE_STRIP} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${UNIT_TESTS})
endif()
message("Thank you for using Concoct!")