Mercurial > vec
comparison CMakeLists.txt @ 17:41dd962abdd1
*: allow compiling vec in a C++ translation unit
this is stupid, but whatever
author | Paper <paper@tflc.us> |
---|---|
date | Wed, 20 Nov 2024 12:02:15 -0500 |
parents | e05c257c6a23 |
children | e26874655738 |
comparison
equal
deleted
inserted
replaced
16:9da2aba90c87 | 17:41dd962abdd1 |
---|---|
1 cmake_minimum_required(VERSION 3.5) | 1 cmake_minimum_required(VERSION 3.23) |
2 | 2 |
3 project(vec VERSION 2.0.0 DESCRIPTION "a tiny C99 SIMD vector library") | 3 project(vec VERSION 2.0.0 DESCRIPTION "a tiny C99 SIMD vector library") |
4 | 4 |
5 add_library(vec SHARED src/vec.c) | 5 add_library(vec SHARED src/vec.c) |
6 | |
7 target_sources(vec PUBLIC | |
8 $<INSTALL_INTERFACE:vec/vec.h> | |
9 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/vec/vec.h> | |
10 $<INSTALL_INTERFACE:vec/impl/integer.h> | |
11 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/vec/impl/integer.h> | |
12 ) | |
6 | 13 |
7 include(CheckCCompilerFlag) | 14 include(CheckCCompilerFlag) |
8 | 15 |
9 if(MSVC) | 16 if(MSVC) |
10 # TODO ? | 17 # TODO ? |
33 if(COMPILER_HAS_AVX512F) | 40 if(COMPILER_HAS_AVX512F) |
34 target_compile_options(vec PRIVATE "-mavx512f") | 41 target_compile_options(vec PRIVATE "-mavx512f") |
35 endif() | 42 endif() |
36 endif() | 43 endif() |
37 | 44 |
45 ######################################################################### | |
46 # integer types | |
38 | 47 |
39 set_target_properties(vec PROPERTIES PUBLIC_HEADER include/vec/vec.h C_STANDARD 99) | 48 include(CheckTypeSize) |
40 | 49 |
41 target_include_directories(vec PRIVATE include) | 50 check_type_size("int16_t" INT16_T_SIZE LANGUAGE C) |
51 check_type_size("uint16_t" UINT16_T_SIZE LANGUAGE C) | |
52 check_type_size("u_int16_t" U_INT16_T_SIZE LANGUAGE C) | |
53 check_type_size("int32_t" INT32_T_SIZE LANGUAGE C) | |
54 check_type_size("uint32_t" UINT32_T_SIZE LANGUAGE C) | |
55 check_type_size("u_int32_t" U_INT32_T_SIZE LANGUAGE C) | |
56 check_type_size("int64_t" INT64_T_SIZE LANGUAGE C) | |
57 check_type_size("uint64_t" UINT64_T_SIZE LANGUAGE C) | |
58 check_type_size("u_int64_t" U_INT64_T_SIZE LANGUAGE C) | |
59 check_type_size("short" SHORT_SIZE LANGUAGE C) | |
60 check_type_size("int" INT_SIZE LANGUAGE C) | |
61 check_type_size("long" LONG_SIZE LANGUAGE C) | |
62 check_type_size("long long" LONG_LONG_SIZE LANGUAGE C) | |
63 check_type_size("uintptr_t" UINTPTR_T_SIZE LANGUAGE C) | |
64 | |
65 if(INT16_T_SIZE EQUAL 2) | |
66 set(SIZE16 "int16_t") | |
67 elseif(SHORT_SIZE EQUAL 2) | |
68 set(SIZE16 "short") | |
69 elseif(INT_SIZE EQUAL 2) | |
70 set(SIZE16 "int") | |
71 endif() | |
72 | |
73 if(UINT16_T_SIZE EQUAL 2) | |
74 set(USIZE16 "uint16_t") | |
75 elseif(U_INT16_T_SIZE EQUAL 2) | |
76 set(USIZE16 "u_int16_t") | |
77 elseif(SHORT_SIZE EQUAL 2) | |
78 set(USIZE16 "unsigned short") | |
79 elseif(INT_SIZE EQUAL 2) | |
80 set(USIZE16 "unsigned int") | |
81 endif() | |
82 | |
83 if(INT32_T_SIZE EQUAL 4) | |
84 set(SIZE32 "int32_t") | |
85 elseif(SHORT_SIZE EQUAL 4) | |
86 set(SIZE32 "short") | |
87 elseif(INT_SIZE EQUAL 4) | |
88 set(SIZE32 "int") | |
89 elseif(LONG_SIZE EQUAL 4) | |
90 set(SIZE32 "long") | |
91 endif() | |
92 | |
93 if(UINT32_T_SIZE EQUAL 4) | |
94 set(USIZE32 "uint32_t") | |
95 elseif(U_INT32_T_SIZE EQUAL 4) | |
96 set(USIZE32 "u_int32_t") | |
97 elseif(SHORT_SIZE EQUAL 4) | |
98 set(USIZE32 "unsigned short") | |
99 elseif(INT_SIZE EQUAL 4) | |
100 set(USIZE32 "unsigned int") | |
101 elseif(LONG_SIZE EQUAL 4) | |
102 set(USIZE32 "unsigned long") | |
103 endif() | |
104 | |
105 if(INT64_T_SIZE EQUAL 8) | |
106 set(SIZE64 "int64_t") | |
107 elseif(SHORT_SIZE EQUAL 8) | |
108 set(SIZE64 "short") | |
109 elseif(INT_SIZE EQUAL 8) | |
110 set(SIZE64 "int") | |
111 elseif(LONG_SIZE EQUAL 8) | |
112 set(SIZE64 "long") | |
113 elseif(LONG_LONG_SIZE EQUAL 8) | |
114 set(SIZE64 "long long") | |
115 endif() | |
116 | |
117 if(UINT64_T_SIZE EQUAL 8) | |
118 set(USIZE64 "uint64_t") | |
119 elseif(U_INT64_T_SIZE EQUAL 8) | |
120 set(USIZE64 "u_int64_t") | |
121 elseif(SHORT_SIZE EQUAL 8) | |
122 set(USIZE64 "unsigned short") | |
123 elseif(INT_SIZE EQUAL 8) | |
124 set(USIZE64 "unsigned int") | |
125 elseif(LONG_SIZE EQUAL 8) | |
126 set(USIZE64 "unsigned long") | |
127 elseif(LONG_LONG_SIZE EQUAL 8) | |
128 set(USIZE64 "unsigned long long") | |
129 endif() | |
130 | |
131 if(CMAKE_SIZEOF_VOID_P EQUAL UINTPTR_T_SIZE) | |
132 set(USIZEPTR "uintptr_t") | |
133 elseif(CMAKE_SIZEOF_VOID_P EQUAL 1) | |
134 set(USIZEPTR "unsigned char") | |
135 elseif(CMAKE_SIZEOF_VOID_P EQUAL 2) | |
136 set(USIZEPTR "${USIZE16}") | |
137 elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) | |
138 set(USIZEPTR "${USIZE32}") | |
139 elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) | |
140 set(USIZEPTR "${USIZE64}") | |
141 endif() | |
142 | |
143 configure_file(include/vec/impl/integer.h.in include/vec/impl/integer.h @ONLY) | |
144 | |
145 target_compile_definitions(vec PRIVATE "VEC_HAVE_IMPL_INTEGER_H") | |
146 | |
147 ######################################################################### | |
148 | |
149 target_compile_features(vec PRIVATE $<IF:$<COMPILE_FEATURES:c_std_11>,c_std_11,c_std_99>) | |
150 target_include_directories(vec PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR}/include/vec") | |
42 | 151 |
43 # Installing | 152 # Installing |
44 | 153 |
45 include(GNUInstallDirs) | 154 include(GNUInstallDirs) |
46 | 155 |
47 install(TARGETS vec | 156 install(TARGETS vec LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
48 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | 157 |
49 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | 158 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/vec/vec.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/vec") |
159 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/vec/impl/integer.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/vec/impl") | |
50 | 160 |
51 # pkg-config | 161 # pkg-config |
52 configure_file(vec.pc.in vec.pc @ONLY) | 162 configure_file(vec.pc.in vec.pc @ONLY) |
53 install(FILES ${CMAKE_BINARY_DIR}/vec.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) | 163 install(FILES ${CMAKE_BINARY_DIR}/vec.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) |