Commit 0190794d authored by Davis King's avatar Davis King

Added some code that will cause people who make a standalone dlib build and

then take the compiled library file but ignore the config.h file to get a
linker error telling them they have been naughty.  Instead, they should either
use `make install` or `cmake --build . --target install` which will copy the
correct files, or even better, don't install/build dlib as a standalone
library.  Instead, use it the way shown in examples/CMakeLists.txt.
parent 048f40dc
......@@ -739,6 +739,10 @@ if (NOT TARGET dlib)
# contents of dlib/config.h once it's installed. But for in project
# builds, there is no real config.h so they are public in the above case.
target_compile_options(dlib PRIVATE ${active_preprocessor_switches})
# Do this so that dlib/config.h won't set DLIB_NOT_CONFIGURED. This will then allow
# the code in dlib/threads_kernel_shared.cpp to emit a linker error for users who
# don't use the configured config.h file generated by cmake.
target_compile_options(dlib PRIVATE -DDLIB__CMAKE_GENERATED_A_CONFIG_H_FILE)
endif()
......
......@@ -23,3 +23,9 @@
// #define DLIB_USE_BLAS
// #define DLIB_USE_LAPACK
// #define DLIB_USE_CUDA
#ifndef DLIB__CMAKE_GENERATED_A_CONFIG_H_FILE
#define DLIB_NOT_CONFIGURED
#endif
......@@ -8,16 +8,32 @@
#include "../platform.h"
#include <iostream>
extern "C"
{
// The point of this block of code is to cause a link time error that will prevent a user
// from compiling part of their application with DLIB_ASSERT enabled and part with them
// disabled since doing that would be a violation of C++'s one definition rule.
extern "C"
{
#ifdef ENABLE_ASSERTS
int USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives;
#else
int USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_;
#endif
// The point of this block of code is to cause a link time error if someone builds dlib via
// cmake as a separately installable library, and therefore generates a dlib/config.h from
// cmake, but then proceeds to use the default unconfigured dlib/config.h from version
// control. It should be obvious why this is bad, if it isn't you need to read a book
// about C++. Moreover, it can only happen if someone manually copies files around and
// messes things up. If instead they run `make install` or `cmake --build . --target
// install` things will be setup correctly, which is what they should do. To summarize: DO
// NOT BUILD A STANDALONE DLIB AND THEN GO CHERRY PICKING FILES FROM THE BUILD FOLDER AND
// MIXING THEM WITH THE SOURCE FROM GITHUB. USE CMAKE'S INSTALL SCRIPTS TO INSTALL DLIB.
// Or even better, don't install dlib at all and instead build your program as shown in
// examples/CMakeLists.txt
#ifdef DLIB_NOT_CONFIGURED
int USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_build_configuration;
#endif
}
#ifndef DLIB_THREAD_POOL_TIMEOUT
......
......@@ -44,6 +44,28 @@ extern "C"
inline int dlib_check_consistent_assert_usage() { USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_ = 0; return 0; }
#endif
const int DLIB_NO_WARN_UNUSED dlib_check_assert_helper_variable = dlib_check_consistent_assert_usage();
// The point of this block of code is to cause a link time error if someone builds dlib via
// cmake as a separately installable library, and therefore generates a dlib/config.h from
// cmake, but then proceeds to use the default unconfigured dlib/config.h from version
// control. It should be obvious why this is bad, if it isn't you need to read a book
// about C++. Moreover, it can only happen if someone manually copies files around and
// messes things up. If instead they run `make install` or `cmake --build . --target
// install` things will be setup correctly, which is what they should do. To summarize: DO
// NOT BUILD A STANDALONE DLIB AND THEN GO CHERRY PICKING FILES FROM THE BUILD FOLDER AND
// MIXING THEM WITH THE SOURCE FROM GITHUB. USE CMAKE'S INSTALL SCRIPTS TO INSTALL DLIB.
// Or even better, don't install dlib at all and instead build your program as shown in
// examples/CMakeLists.txt
#ifdef DLIB_NOT_CONFIGURED
extern int USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_build_configuration;
inline int dlib_check_consistent_config_h_usage() { USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_build_configuration = 0; return 0; }
#else
inline int dlib_check_consistent_config_h_usage() { return 0; }
#endif
const int DLIB_NO_WARN_UNUSED dlib_check_not_configured_helper_variable = dlib_check_consistent_config_h_usage();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment