-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
90 lines (80 loc) · 3.15 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
cmake_minimum_required(VERSION 3.25)
project(luaclasslib
VERSION 3.0.1
LANGUAGES C CXX)
set(LUACLASS_ENABLE_ASAN false CACHE BOOL "Enable address sanitizer for tests target.")
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(DOCTEST_NO_INSTALL ON)
### main project
set(LUACLASS_MAIN_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(LUACLASS_MAIN_PROJECT ON)
endif()
include(FindLua)
add_library(luaclass SHARED src/luaclasslib.c)
add_library(LuaClass::LuaClass ALIAS luaclass)
target_include_directories(luaclass PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
${LUA_INCLUDE_DIR})
target_link_libraries(luaclass ${LUA_LIBRARIES})
set_target_properties(luaclass PROPERTIES EXPORT_NAME LuaClass)
target_compile_options(luaclass PUBLIC
-fno-strict-aliasing -Wall -Wextra -Wunused -Wno-unused-function
$<$<CONFIG:Debug>:-g3 -ggdb3 -pedantic>
$<$<CONFIG:Release>:-O2 -Wfatal-errors>)
if(LUACLASS_MAIN_PROJECT)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/LuaClassConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LuaClass")
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/LuaClassConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(TARGETS luaclass
DESTINATION ${CMAKE_INSTALL_LIBDIR}
EXPORT LuaClassTargets)
install(FILES src/luaclasslib.h src/moonauxlib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT LuaClassTargets
FILE LuaClassTargets.cmake
NAMESPACE LuaClass::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LuaClass)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LuaClassConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/LuaClassConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LuaClass")
export(TARGETS luaclass
NAMESPACE LuaClass::
FILE ${CMAKE_CURRENT_BINARY_DIR}/LuaClassTargets.cmake)
install(FILES ${version_file} ${config_file}
DESTINATION ${cmake_dir}
COMPONENT ${projectname_target}Export)
endif()
enable_testing()
add_subdirectory(doctest)
include(doctest/scripts/cmake/doctest.cmake)
add_executable(tests
tests/classes/file.c
tests/classes/signal.c
tests/classes/blocking_signal.c
tests/classes/udata_derived.c
tests/classes/simple.c
tests/main.cpp
tests/basicfunctions.cpp
tests/cclass.cpp
tests/udataclass.cpp
tests/udataclass_inheritance.cpp
tests/methodinjection.cpp)
target_compile_features(tests PRIVATE cxx_std_17)
target_link_libraries(tests luaclass doctest)
doctest_discover_tests(tests)
file(GLOB asset_files ${CMAKE_SOURCE_DIR}/tests/assets/*)
add_custom_target(assets COMMAND ${CMAKE_COMMAND} -E copy_if_different
${asset_files} $<TARGET_FILE_DIR:tests>)
add_dependencies(tests assets)
if(LUACLASS_ENABLE_ASAN)
target_compile_options(tests PUBLIC -fsanitize=address)
target_link_options(tests PUBLIC -fsanitize=address)
endif()