Mercurial > vec
diff 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 |
line wrap: on
line diff
--- a/CMakeLists.txt Wed Nov 20 04:16:56 2024 -0500 +++ b/CMakeLists.txt Wed Nov 20 12:02:15 2024 -0500 @@ -1,9 +1,16 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.23) project(vec VERSION 2.0.0 DESCRIPTION "a tiny C99 SIMD vector library") add_library(vec SHARED src/vec.c) +target_sources(vec PUBLIC + $<INSTALL_INTERFACE:vec/vec.h> + $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/vec/vec.h> + $<INSTALL_INTERFACE:vec/impl/integer.h> + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/vec/impl/integer.h> +) + include(CheckCCompilerFlag) if(MSVC) @@ -35,18 +42,121 @@ endif() endif() +######################################################################### +# integer types -set_target_properties(vec PROPERTIES PUBLIC_HEADER include/vec/vec.h C_STANDARD 99) +include(CheckTypeSize) + +check_type_size("int16_t" INT16_T_SIZE LANGUAGE C) +check_type_size("uint16_t" UINT16_T_SIZE LANGUAGE C) +check_type_size("u_int16_t" U_INT16_T_SIZE LANGUAGE C) +check_type_size("int32_t" INT32_T_SIZE LANGUAGE C) +check_type_size("uint32_t" UINT32_T_SIZE LANGUAGE C) +check_type_size("u_int32_t" U_INT32_T_SIZE LANGUAGE C) +check_type_size("int64_t" INT64_T_SIZE LANGUAGE C) +check_type_size("uint64_t" UINT64_T_SIZE LANGUAGE C) +check_type_size("u_int64_t" U_INT64_T_SIZE LANGUAGE C) +check_type_size("short" SHORT_SIZE LANGUAGE C) +check_type_size("int" INT_SIZE LANGUAGE C) +check_type_size("long" LONG_SIZE LANGUAGE C) +check_type_size("long long" LONG_LONG_SIZE LANGUAGE C) +check_type_size("uintptr_t" UINTPTR_T_SIZE LANGUAGE C) + +if(INT16_T_SIZE EQUAL 2) + set(SIZE16 "int16_t") +elseif(SHORT_SIZE EQUAL 2) + set(SIZE16 "short") +elseif(INT_SIZE EQUAL 2) + set(SIZE16 "int") +endif() + +if(UINT16_T_SIZE EQUAL 2) + set(USIZE16 "uint16_t") +elseif(U_INT16_T_SIZE EQUAL 2) + set(USIZE16 "u_int16_t") +elseif(SHORT_SIZE EQUAL 2) + set(USIZE16 "unsigned short") +elseif(INT_SIZE EQUAL 2) + set(USIZE16 "unsigned int") +endif() + +if(INT32_T_SIZE EQUAL 4) + set(SIZE32 "int32_t") +elseif(SHORT_SIZE EQUAL 4) + set(SIZE32 "short") +elseif(INT_SIZE EQUAL 4) + set(SIZE32 "int") +elseif(LONG_SIZE EQUAL 4) + set(SIZE32 "long") +endif() -target_include_directories(vec PRIVATE include) +if(UINT32_T_SIZE EQUAL 4) + set(USIZE32 "uint32_t") +elseif(U_INT32_T_SIZE EQUAL 4) + set(USIZE32 "u_int32_t") +elseif(SHORT_SIZE EQUAL 4) + set(USIZE32 "unsigned short") +elseif(INT_SIZE EQUAL 4) + set(USIZE32 "unsigned int") +elseif(LONG_SIZE EQUAL 4) + set(USIZE32 "unsigned long") +endif() + +if(INT64_T_SIZE EQUAL 8) + set(SIZE64 "int64_t") +elseif(SHORT_SIZE EQUAL 8) + set(SIZE64 "short") +elseif(INT_SIZE EQUAL 8) + set(SIZE64 "int") +elseif(LONG_SIZE EQUAL 8) + set(SIZE64 "long") +elseif(LONG_LONG_SIZE EQUAL 8) + set(SIZE64 "long long") +endif() + +if(UINT64_T_SIZE EQUAL 8) + set(USIZE64 "uint64_t") +elseif(U_INT64_T_SIZE EQUAL 8) + set(USIZE64 "u_int64_t") +elseif(SHORT_SIZE EQUAL 8) + set(USIZE64 "unsigned short") +elseif(INT_SIZE EQUAL 8) + set(USIZE64 "unsigned int") +elseif(LONG_SIZE EQUAL 8) + set(USIZE64 "unsigned long") +elseif(LONG_LONG_SIZE EQUAL 8) + set(USIZE64 "unsigned long long") +endif() + +if(CMAKE_SIZEOF_VOID_P EQUAL UINTPTR_T_SIZE) + set(USIZEPTR "uintptr_t") +elseif(CMAKE_SIZEOF_VOID_P EQUAL 1) + set(USIZEPTR "unsigned char") +elseif(CMAKE_SIZEOF_VOID_P EQUAL 2) + set(USIZEPTR "${USIZE16}") +elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(USIZEPTR "${USIZE32}") +elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(USIZEPTR "${USIZE64}") +endif() + +configure_file(include/vec/impl/integer.h.in include/vec/impl/integer.h @ONLY) + +target_compile_definitions(vec PRIVATE "VEC_HAVE_IMPL_INTEGER_H") + +######################################################################### + +target_compile_features(vec PRIVATE $<IF:$<COMPILE_FEATURES:c_std_11>,c_std_11,c_std_99>) +target_include_directories(vec PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR}/include/vec") # Installing include(GNUInstallDirs) -install(TARGETS vec - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(TARGETS vec LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/vec/vec.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/vec") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/vec/impl/integer.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/vec/impl") # pkg-config configure_file(vec.pc.in vec.pc @ONLY)