-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
158 lines (147 loc) · 6.42 KB
/
CMakeLists.txt
File metadata and controls
158 lines (147 loc) · 6.42 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# MIT License
#
# Copyright (c) 2026 The OneLuaPro project authors.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ------------------------------------------------------------------------------
# CMake for numlu
# ------------------------------------------------------------------------------
# Setup with Visual Studio 17 2022 generator for x64
# ------------------------------------------------------------------------------
# Visual Studio is a mutlti-configuration generator
# https://stackoverflow.com/questions/24460486/
#
# Basic instructions for out-of-source build
# ------------------------------------------
# mkdir build && cd build
# cmake .. -G "Visual Studio 17 2022" -A x64
# cmake --build . --config Release
# cmake --install . --config Release
#
# Available architectures (-A ...) are: Win32, x64, ARM, ARM64
# ------------------------------------------------------------------------------
# General definitions
cmake_minimum_required(VERSION 3.31 FATAL_ERROR)
# ------------------------------------------------------------------------------
# find liblua installation and version info
if(NOT LUA_HINTS)
if(WIN32)
set(LUA_HINTS "c:/Apps")
endif()
endif()
find_package(liblua REQUIRED CONFIG HINTS ${LUA_HINTS})
if(liblua_FOUND)
message(STATUS "liblua version : ${liblua_VERSION}")
message(STATUS "liblua install prefix : ${LIBLUA_INSTALLDIR}")
message(STATUS "liblua include dir : ${LIBLUA_INCLUDEDIR}")
message(STATUS "liblua lib dir : ${LIBLUA_LIBDIR}")
else()
message(FATAL_ERROR "Unable to find liblua version ${liblua_VERSION}.")
endif()
# Note: liblua_VERSION is set by find_package() directly. LIBLUA_INSTALLDIR,
# LIBLUA_INCLUDEDIR and LIBLUA_LIBDIR are set by libluaConfigVersion.cmake in
# <prefix>/share/cmake/liblua.
# ------------------------------------------------------------------------------
set(MKL_INTERFACE "ilp64")
set(MKL_THREADING "intel_thread")
set(MKL_LINK "static")
find_package(MKL CONFIG REQUIRED)
# ------------------------------------------------------------------------------
# Installation prefix directory - automatically set from find_package()
# Needs to be defined before project definition statement - for whatever reason
if(NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${LIBLUA_INSTALLDIR})
endif()
# ------------------------------------------------------------------------------
# Project defintion
project(numlu C)
# ------------------------------------------------------------------------------
# Other settings
set(CMAKE_VERBOSE_MAKEFILE ON)
# ------------------------------------------------------------------------------
# Setup GNU-alike installatin directories
include (GNUInstallDirs)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(INSTALL_LIBDIR
${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries")
set(INSTALL_BINDIR
${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDEDIR
${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for header files")
set(INSTALL_DOCDIR
${CMAKE_INSTALL_DOCDIR} CACHE PATH "Installation directory for documentation")
set(INSTALL_MANDIR
${CMAKE_INSTALL_MANDIR} CACHE PATH "Installation directory for manpages")
set(INSTALL_DATAROOTDIR
${CMAKE_INSTALL_DATAROOTDIR} CACHE PATH "Installation directory for data")
# Lua-specific installation dirs
set(INSTALL_TOP_CDIR
${INSTALL_LIBDIR}/lua/${liblua_VERSION_MAJOR}.${liblua_VERSION_MINOR})
set(INSTALL_TOP_LDIR
${INSTALL_DATAROOTDIR}/lua/${liblua_VERSION_MAJOR}.${liblua_VERSION_MINOR})
# ------------------------------------------------------------------------------
# Report to user
message(STATUS "C compiler flags: ${CMAKE_C_FLAGS}")
# ------------------------------------------------------------------------------
# numlu core DLL
add_library(numlu SHARED)
# setup lua include directory
target_include_directories(numlu PRIVATE ${LIBLUA_INCLUDEDIR})
# plattform-independend sources
target_sources(numlu PRIVATE
src/numlu_dtype.h src/numlu_dtype.c
src/numlu_ndarray.h src/numlu_ndarray.c
src/numlu.c)
# setup platform-specific sources, compile and linker options
if(WIN32 AND NOT MinGW)
# Important definitions for DLL and symbol export
target_compile_definitions(numlu PRIVATE
LUA_BUILD_AS_DLL LUA_LIB
# _WINDLL _WIN32 _CRT_SECURE_NO_WARNINGS
)
# We silently assume all libs are available with headers and static lib
target_link_directories(numlu PRIVATE
${LIBLUA_LIBDIR}
)
target_link_libraries(numlu PRIVATE liblua)
target_link_libraries(numlu PUBLIC MKL::MKL)
else()
message(FATAL_ERROR "Not yet fully implemented.")
endif()
# Install
install(TARGETS numlu RUNTIME DESTINATION ${INSTALL_TOP_CDIR})
# # ------------------------------------------------------------------------------
# # Create docs with ldoc from CMAKE_INSTALL_PREFIX
# set(LDOC_EXE "${CMAKE_INSTALL_PREFIX}/bin/ldoc.exe")
# set(DOC_INST_DIR "${CMAKE_CURRENT_BINARY_DIR}/gen-docs")
# add_custom_target(docs
# COMMENT "Generate documentation ..."
# WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
# COMMAND ${LDOC_EXE} . -d "${DOC_INST_DIR}"
# )
# add_dependencies(numlu docs)
# # ------------------------------------------------------------------------------
# # Install
# install(
# DIRECTORY ${DOC_INST_DIR}/
# DESTINATION ${INSTALL_DOCDIR}
# )