-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0001-Add-CMake-script.patch
134 lines (130 loc) · 4.02 KB
/
0001-Add-CMake-script.patch
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
From 630ade3e42798085195f99e407f446cc3afa8909 Mon Sep 17 00:00:00 2001
From: Julien Schueller <[email protected]>
Date: Fri, 16 Feb 2024 18:13:02 +0100
Subject: [PATCH 1/5] Add CMake script
---
CMakeLists.txt | 74 ++++++++++++++++++++++++++++++++++++++++++++
config.h.cmake.in | 16 ++++++++++
src/common/stddecl.h | 5 +++
3 files changed, 95 insertions(+)
create mode 100644 CMakeLists.txt
create mode 100644 config.h.cmake.in
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..06d1d7e
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,74 @@
+cmake_minimum_required (VERSION 3.13)
+
+set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
+
+project (cuba C)
+
+option (BUILD_SHARED_LIBS "shared/static" ON)
+option (ENABLE_FORK "sampling parallelization using fork syscall" ON)
+
+include (GNUInstallDirs)
+
+include (CheckIncludeFile)
+check_include_file(alloca.h HAVE_ALLOCA_H)
+
+include(CheckTypeSize)
+check_type_size("long double" HAVE_LONG_DOUBLE)
+
+include(CheckFunctionExists)
+if (ENABLE_FORK)
+ check_function_exists(fork HAVE_FORK)
+endif ()
+check_function_exists (shmget HAVE_SHMGET)
+if (UNIX)
+ find_library(MATH_LIBRARY NAMES m)
+endif ()
+
+if (MATH_LIBRARY)
+ set(CMAKE_REQUIRED_LIBRARIES ${MATH_LIBRARY})
+endif ()
+check_function_exists(erf HAVE_ERF)
+check_function_exists(powl HAVE_POWL)
+
+if (MSVC)
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267 /wd4996")
+endif ()
+
+configure_file(config.h.cmake.in config.h)
+
+add_library(cuba src/common/Fork.c src/common/Global.c src/common/Data.c)
+target_include_directories(cuba PRIVATE src/common ${CMAKE_CURRENT_BINARY_DIR})
+target_compile_definitions(cuba PRIVATE HAVE_CONFIG_H NOUNDERSCORE REALSIZE=8)
+if (MATH_LIBRARY)
+ target_link_libraries(cuba PRIVATE ${MATH_LIBRARY})
+endif ()
+
+set_property(TARGET cuba PROPERTY POSITION_INDEPENDENT_CODE ON)
+set_property(TARGET cuba PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
+set_property(TARGET cuba PROPERTY SOVERSION 0)
+
+set(VARIANTS Vegas Suave Cuhre Divonne)
+foreach(VARIANT ${VARIANTS})
+ string(TOLOWER "${VARIANT}" variant)
+ add_library(cuba_${variant} OBJECT src/${variant}/${VARIANT}.c)
+ target_include_directories(cuba_${variant} PRIVATE src/common src/${variant} ${CMAKE_CURRENT_BINARY_DIR})
+ set_property(TARGET cuba_${variant} PROPERTY POSITION_INDEPENDENT_CODE ON)
+ target_compile_definitions(cuba_${variant} PRIVATE HAVE_CONFIG_H NOUNDERSCORE REALSIZE=8)
+ if (WIN32)
+ target_compile_definitions(cuba_${variant} PRIVATE _CRT_SECURE_NO_WARNINGS)
+ endif ()
+ target_link_libraries(cuba PRIVATE cuba_${variant})
+endforeach()
+
+install(TARGETS cuba LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(FILES cuba.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
+add_executable(demo_c demo/demo-c.c)
+target_link_libraries(demo_c PRIVATE cuba)
+if (UNIX)
+ target_link_libraries(demo_c PRIVATE m)
+endif ()
+target_include_directories(demo_c PRIVATE .)
+
+enable_testing()
+add_test(NAME demo_c COMMAND demo_c)
diff --git a/config.h.cmake.in b/config.h.cmake.in
new file mode 100644
index 0000000..1a23b15
--- /dev/null
+++ b/config.h.cmake.in
@@ -0,0 +1,16 @@
+/* config.h. Generated from config.h.cmake.in by cmake. */
+
+/* Define to 1 if you have the `fork' function. */
+#cmakedefine HAVE_FORK
+
+/* Define to 1 if you have the `powl' function. */
+#cmakedefine HAVE_POWL
+
+/* Define to 1 if the type `long double' works and has more range or precision than `double'. */
+#cmakedefine HAVE_LONG_DOUBLE
+
+/* Define to 1 if you have `alloca', as a function or macro. */
+#cmakedefine HAVE_ALLOCA_H
+
+/* Define to 1 if you have the `shmget' function. */
+#cmakedefine HAVE_SHMGET
diff --git a/src/common/stddecl.h b/src/common/stddecl.h
index 7ff4f73..6d279fc 100644
--- a/src/common/stddecl.h
+++ b/src/common/stddecl.h
@@ -16,6 +16,11 @@
#define _SVID_SOURCE
#define _DEFAULT_SOURCE
+// added by cmake
+#ifdef NDEBUG
+#undef NDEBUG
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
--
2.34.1