Skip to content

Commit 6230cbf

Browse files
Merge pull request #17 from SaridakisStamatisChristos/codex/organize-public-and-private-headers
Refactor public headers and add version metadata
2 parents 9fe08bd + e1e1596 commit 6230cbf

22 files changed

+120
-50
lines changed

CMakeLists.txt

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
cmake_minimum_required(VERSION 3.15)
2-
project(thermal_simd_dispatcher C)
2+
project(thermal_simd_dispatcher VERSION 0.1.0 LANGUAGES C)
33
set(CMAKE_C_STANDARD 11)
44

55
set(THERMAL_SIMD_DISPATCHER_CPU_FLAGS "-msse4.1" CACHE STRING "CPU-specific compiler flags for thermal_simd")
66

7-
add_library(thermal_simd_core STATIC
7+
include(CTest)
8+
9+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/thermal/simd)
10+
configure_file(
11+
${CMAKE_CURRENT_SOURCE_DIR}/include/thermal/simd/version.h.in
12+
${CMAKE_CURRENT_BINARY_DIR}/include/thermal/simd/version.h
13+
@ONLY
14+
)
15+
16+
set(THERMAL_SIMD_CORE_SOURCES
817
src/config_parser.c
918
src/statistics.c
1019
src/thermal_config.c
@@ -13,28 +22,66 @@ add_library(thermal_simd_core STATIC
1322
src/thermal_perf.c
1423
src/thermal_signals.c
1524
)
16-
target_include_directories(thermal_simd_core PUBLIC src)
25+
26+
add_library(thermal_simd_core STATIC ${THERMAL_SIMD_CORE_SOURCES})
27+
target_include_directories(thermal_simd_core
28+
PUBLIC
29+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
30+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
31+
$<INSTALL_INTERFACE:include>
32+
PRIVATE
33+
${CMAKE_CURRENT_SOURCE_DIR}/src
34+
)
1735

1836
add_executable(thermal_simd src/thermal_simd.c)
1937
target_compile_options(thermal_simd PRIVATE -O2 -pthread -fPIC -mno-avx ${THERMAL_SIMD_DISPATCHER_CPU_FLAGS})
2038
target_link_libraries(thermal_simd PRIVATE thermal_simd_core pthread)
2139

22-
enable_testing()
23-
24-
add_executable(test_config_parser tests/test_config_parser.c)
25-
target_link_libraries(test_config_parser PRIVATE thermal_simd_core)
26-
target_compile_options(test_config_parser PRIVATE -Wall -Wextra)
27-
add_test(NAME config_parser COMMAND test_config_parser)
28-
29-
add_executable(test_statistics tests/test_statistics.c)
30-
target_link_libraries(test_statistics PRIVATE thermal_simd_core)
31-
target_compile_options(test_statistics PRIVATE -Wall -Wextra)
32-
add_test(NAME statistics COMMAND test_statistics)
33-
34-
add_executable(test_thermal_simd
35-
tests/test_thermal_simd.c
36-
src/thermal_simd.c)
37-
target_compile_definitions(test_thermal_simd PRIVATE TSD_ENABLE_TESTS)
38-
target_link_libraries(test_thermal_simd PRIVATE thermal_simd_core pthread)
39-
target_compile_options(test_thermal_simd PRIVATE -Wall -Wextra -O1 -pthread -fPIC)
40-
add_test(NAME thermal_simd COMMAND test_thermal_simd)
40+
if(BUILD_TESTING)
41+
add_library(thermal_simd_core_tests STATIC ${THERMAL_SIMD_CORE_SOURCES})
42+
target_include_directories(thermal_simd_core_tests
43+
PUBLIC
44+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
45+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
46+
PRIVATE
47+
${CMAKE_CURRENT_SOURCE_DIR}/src
48+
)
49+
target_compile_definitions(thermal_simd_core_tests PRIVATE TSD_ENABLE_TESTS)
50+
51+
add_executable(test_config_parser tests/test_config_parser.c)
52+
target_link_libraries(test_config_parser PRIVATE thermal_simd_core_tests)
53+
target_compile_options(test_config_parser PRIVATE -Wall -Wextra)
54+
add_test(NAME config_parser COMMAND test_config_parser)
55+
56+
add_executable(test_statistics tests/test_statistics.c)
57+
target_link_libraries(test_statistics PRIVATE thermal_simd_core_tests)
58+
target_compile_options(test_statistics PRIVATE -Wall -Wextra)
59+
add_test(NAME statistics COMMAND test_statistics)
60+
61+
add_executable(test_thermal_simd
62+
tests/test_thermal_simd.c
63+
src/thermal_simd.c)
64+
target_compile_definitions(test_thermal_simd PRIVATE TSD_ENABLE_TESTS)
65+
target_link_libraries(test_thermal_simd PRIVATE thermal_simd_core_tests pthread)
66+
target_compile_options(test_thermal_simd PRIVATE -Wall -Wextra -O1 -pthread -fPIC)
67+
target_include_directories(test_thermal_simd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
68+
add_test(NAME thermal_simd COMMAND test_thermal_simd)
69+
endif()
70+
71+
install(TARGETS thermal_simd_core
72+
EXPORT thermal_simd_dispatcherTargets
73+
ARCHIVE DESTINATION lib
74+
LIBRARY DESTINATION lib
75+
RUNTIME DESTINATION bin)
76+
77+
install(DIRECTORY include/
78+
DESTINATION include
79+
FILES_MATCHING PATTERN "*.h"
80+
PATTERN "*.in" EXCLUDE)
81+
82+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/thermal/simd/version.h
83+
DESTINATION include/thermal/simd)
84+
85+
install(EXPORT thermal_simd_dispatcherTargets
86+
NAMESPACE thermal::
87+
DESTINATION lib/cmake/thermal_simd_dispatcher)
File renamed without changes.

include/thermal/simd/simd_width.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef TSD_SIMD_WIDTH_H
2+
#define TSD_SIMD_WIDTH_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
typedef enum {
9+
SIMD_SSE41 = 0,
10+
SIMD_AVX2,
11+
SIMD_AVX512
12+
} simd_width_t;
13+
14+
#ifdef __cplusplus
15+
}
16+
#endif
17+
18+
#endif /* TSD_SIMD_WIDTH_H */
File renamed without changes.
File renamed without changes.

src/thermal_cpu.h renamed to include/thermal/simd/thermal_cpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#include <stdint.h>
55

6-
#include "thermal_config.h"
7-
#include "thermal_simd_internal.h"
6+
#include <thermal/simd/simd_width.h>
7+
#include <thermal/simd/thermal_config.h>
88

99
extern uint8_t g_tsd_avx_available;
1010

src/thermal_perf.h renamed to include/thermal/simd/thermal_perf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <stddef.h>
66
#include <stdint.h>
77

8-
#include "thermal_config.h"
8+
#include <thermal/simd/thermal_config.h>
99

1010
#ifdef __cplusplus
1111
extern "C" {
File renamed without changes.

src/thermal_trampoline.h renamed to include/thermal/simd/thermal_trampoline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stddef.h>
77
#include <stdint.h>
88

9-
#include "thermal_simd_internal.h"
9+
#include <thermal/simd/simd_width.h>
1010

1111
typedef struct {
1212
uint8_t code[16];

include/thermal/simd/version.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef TSD_VERSION_H
2+
#define TSD_VERSION_H
3+
4+
#define THERMAL_SIMD_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
5+
#define THERMAL_SIMD_VERSION_MINOR @PROJECT_VERSION_MINOR@
6+
#define THERMAL_SIMD_VERSION_PATCH @PROJECT_VERSION_PATCH@
7+
#define THERMAL_SIMD_VERSION "@PROJECT_VERSION@"
8+
9+
#endif /* TSD_VERSION_H */

0 commit comments

Comments
 (0)