#!/bin/bash
tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" EXIT
cd "$tmpdir"

cat >"CMakeLists.txt" <<EOF
cmake_minimum_required(VERSION 3.1)
project(test_tinyobjloader)

find_package(tinyobjloader REQUIRED)

add_executable(test_float test.cpp)
target_link_libraries(test_float tinyobjloader::tinyobjloader)
target_compile_definitions(test_float PRIVATE EXPECTED_TYPE=float)

add_executable(test_double test.cpp)
target_link_libraries(test_double tinyobjloader::tinyobjloader_double)
target_compile_definitions(test_double PRIVATE EXPECTED_TYPE=double)
EOF

cat >"test.cpp" << EOF
#include <tiny_obj_loader.h>
#include <type_traits>

int main (int argc, char** argv)
{
	tinyobj::attrib_t attrib;
	std::vector<tinyobj::shape_t> shapes;
	std::vector<tinyobj::material_t> materials;
	std::string warn;
	std::string err;

	static_assert(std::is_same<tinyobj::real_t, EXPECTED_TYPE>::value, "wrong floating point preision");

	bool ok = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, "some.obj");
	return 0;
}
EOF
echo '$' cmake .
cmake .
echo '$' make VERBOSE=ON
make VERBOSE=ON

