Apply @rcurtin modification to check STB version

Signed-off-by: Omar Shrit <omar@shrit.me>
This commit is contained in:
Omar Shrit
2022-04-16 16:20:14 +01:00
parent 8868c12060
commit eefb010434
13 changed files with 113 additions and 113 deletions
-37
View File
@@ -1,37 +0,0 @@
# Author: Omar Shrit
#[=======================================================================[.rst:
TestForSTB
--------------
Test to verify if the last version of STB that contains static
functions is available in the system
check if the compiler supports the standard ANSI sstream header
::
CMAKE_HAS_STATIC_STB - defined by the results
#]=======================================================================]
if(NOT DEFINED CMAKE_HAS_STATIC_STB)
message(CHECK_START "Check for stb")
try_compile(CMAKE_HAS_STATIC_STB stb/main.cpp
OUTPUT_VARIABLE OUTPUT)
if (CMAKE_HAS_ANSI_STRING_STREAM)
message(CHECK_PASS "found")
set (CMAKE_NO_ANSI_STRING_STREAM 0 CACHE INTERNAL
"Does the compiler support sstream")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the CXX compiler has sstream passed with "
"the following output:\n${OUTPUT}\n\n")
else ()
message(CHECK_FAIL "not found")
set (CMAKE_NO_ANSI_STRING_STREAM 1 CACHE INTERNAL
"Does the compiler support sstream")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the CXX compiler has sstream failed with "
"the following output:\n${OUTPUT}\n\n")
endif ()
endif()
+42
View File
@@ -0,0 +1,42 @@
# Author: Omar Shrit
#[=======================================================================[.rst:
TestForSTB
----------
Test to verify if the available version of STB contains a working static
implementation that can be used from multiple translation units.
::
CMAKE_HAS_WORKING_STATIC_STB - defined by the results
#]=======================================================================]
if(NOT DEFINED CMAKE_HAS_WORKING_STATIC_STB)
message(STATUS "Check that STB static implementation mode links correctly...")
try_compile(CMAKE_HAS_WORKING_STATIC_STB
${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/
SOURCES
${CMAKE_SOURCE_DIR}/CMake/stb/main.cpp
${CMAKE_SOURCE_DIR}/CMake/stb/a.cpp
${CMAKE_SOURCE_DIR}/CMake/stb/b.cpp
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${STB_IMAGE_INCLUDE_DIR}"
OUTPUT_VARIABLE out)
if (CMAKE_HAS_WORKING_STATIC_STB)
message(STATUS "Check that STB static implementation mode links "
"correctly... success")
set(CMAKE_HAS_WORKING_STATIC_STB 1 CACHE INTERNAL
"Does STB static implementation mode link correctly")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if STB's static implementation can link correctly passed "
"with the following output:\n${out}\n\n")
else ()
message(STATUS "Check that STB static implementation mode links "
"correctly... fail")
set(CMAKE_HAS_WORKING_STATIC_STB 0 CACHE INTERNAL
"Does STB static implementation mode link correctly")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if STB's static implementation can link correctly failed "
"with the following output:\n${out}\n\n")
endif ()
endif()
-21
View File
@@ -1,21 +0,0 @@
cmake_minimum_required(VERSION 3.9)
project(CheckSTB)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(alib SHARED alib.hpp alib.cpp)
add_library(blib SHARED blib.hpp blib.cpp)
#set(alib "alib.so")
#set(blib "libblib.so")
add_executable(CheckSTB
main.cpp
)
target_link_libraries(CheckSTB
alib
blib
)
+15
View File
@@ -0,0 +1,15 @@
#include "a.hpp"
// Include the static implementation of all STB functions.
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_STATIC
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image.h>
#include <stb_image_write.h>
void A::A()
{
// Do nothing, just to check if the STB library is a working version.
}
+10
View File
@@ -0,0 +1,10 @@
#ifndef A_HPP
#define A_HPP
namespace A {
void A();
}
#endif
-8
View File
@@ -1,8 +0,0 @@
#include "alib.hpp"
void Alib::A()
{
//Do nothing, just to check if the STB library has the good version.
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef ALIB_HPP
#define ALIB_HPP
#define STB_IMAGE_WRITE_STATIC
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>
namespace Alib {
void A();
}
#endif
+15
View File
@@ -0,0 +1,15 @@
#include "b.hpp"
// Include the static implementation of all STB functions.
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_STATIC
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image.h>
#include <stb_image_write.h>
void B::B()
{
// Do nothing, just to check if the STB library is a working version.
}
+10
View File
@@ -0,0 +1,10 @@
#ifndef B_HPP
#define B_HPP
namespace B {
void B();
}
#endif
-8
View File
@@ -1,8 +0,0 @@
#include "blib.hpp"
void Blib::B()
{
//Do nothing, just to check if the STB library has the good version.
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef BLIB_HPP
#define BLIB_HPP
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
namespace Blib {
void B();
}
#endif
+12 -7
View File
@@ -1,11 +1,16 @@
#include "alib.hpp"
#include "blib.hpp"
// The purpose of this file is to include STB's implementation in two separate
// translation units. One is a.cpp, and one is b.cpp. This file simply
// includes both of those, so that when we get to the linking phase, we will
// have to link both translation units.
//
// Some versions of STB fail to correctly define some functions as
// static---which will cause a linking failure. Thus, if this fails to
// compile, then mlpack's use of STB will fail.
#include "a.hpp"
#include "b.hpp"
int main()
{
Alib::A();
Blib::B();
A::A();
B::B();
}
+9
View File
@@ -325,6 +325,15 @@ if (STB_IMAGE_FOUND)
add_definitions(-DHAS_STB)
set(STB_AVAILABLE "1")
set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} "${STB_IMAGE_INCLUDE_DIR}")
# Make sure that we can link STB in multiple translation units.
include(CMake/TestStaticSTB.cmake)
if (NOT CMAKE_HAS_WORKING_STATIC_STB)
message(FATAL_ERROR "STB implementations's static mode cannot link across "
"multiple translation units! Try upgrading your STB implementation, "
"or using the auto-downloader (set DOWNLOAD_DEPENDENCIES=ON in the "
"CMake configuration command.")
endif ()
endif()
# Find ensmallen.