forked from dargueta/unicorn-lua
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
109 lines (88 loc) · 3 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
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(UnicornLua VERSION 0.1 LANGUAGES CXX)
include("${PROJECT_SOURCE_DIR}/configuration.cmake")
option(BUILD_DOCS "Build documentation" ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#find_package(Python3 REQUIRED)
if(NOT USE_VIRTUALENV)
find_package(Lua REQUIRED)
find_program(
LUA_EXE
NAMES lua
DOC "The Lua interpreter"
)
find_program(
LUAROCKS_EXE
NAMES luarocks
DOC "Luarocks installation program"
)
endif()
execute_process(
COMMAND ${LUAROCKS_EXE} path --lr-path
OUTPUT_VARIABLE LUAROCKS_LPATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LUAROCKS_EXE} path --lr-cpath
OUTPUT_VARIABLE LUAROCKS_CPATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
get_filename_component(LUAROCKS_BIN_DIR "${LUAROCKS_EXE}" DIRECTORY)
set(BUSTED_EXE "${LUAROCKS_BIN_DIR}/busted")
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Define dependencies ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
# These might be set by the user.
if(NOT DEFINED UNICORN_LIBRARY)
find_library(UNICORN_LIBRARY NAMES unicorn libunicorn)
endif()
if(NOT DEFINED UNICORN_HEADERS_PATH)
find_path(UNICORN_HEADERS_PATH unicorn/unicorn.h)
endif()
if (UNICORN_HEADERS_PATH STREQUAL "UNICORN_HEADERS_PATH-NOTFOUND")
message(FATAL_ERROR "Unicorn doesn't appear to be installed, or the headers are in a non-standard location.")
endif()
# Lua looks for C libraries with the file extension `.dll` on Windows, and `.so` on all
# other platforms. Since the OSX extension is `.dylib` we can't use CMAKE_SHARED_LIBRARY_SUFFIX
# so we have to override it ourselves.
if(CMAKE_HOST_WIN32)
set(LUA_CLIB_EXTENSION ".dll")
else()
set(LUA_CLIB_EXTENSION ".so")
endif()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Define targets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
enable_testing()
add_subdirectory("src" "${CMAKE_CURRENT_BINARY_DIR}/lib") # Library code
add_subdirectory("tests/c" "${CMAKE_CURRENT_BINARY_DIR}/tests_c") # Tests with C++ code
add_subdirectory("tests/lua" "${CMAKE_CURRENT_BINARY_DIR}/tests_lua") # Tests with Lua code
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/templates/Makefile.in"
"${CMAKE_CURRENT_BINARY_DIR}/Makefile.in"
@ONLY
)
file(GENERATE
OUTPUT "${PROJECT_SOURCE_DIR}/Makefile.in"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/Makefile.in"
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/templates/platform.h"
"${PROJECT_SOURCE_DIR}/include/unicornlua/platform.h"
@ONLY
)
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/templates/Doxyfile.in"
"${CMAKE_CURRENT_BINARY_DIR}/Doxyfile"
@ONLY
)
add_custom_target(
docs
COMMAND ${DOXYGEN_EXECUTABLE}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
else()
message("Doxygen needs to be installed to generate the documentation.")
endif()