# For more information see the CMake documentation:
# http://www.cmake.org/cmake/help/documentation.html
# http://techbase.kde.org/Development/Tutorials/CMake
cmake_minimum_required(VERSION 2.8.12)
# find KDE's extra cmake modules:
find_package(ECM 1.1.0 REQUIRED NO_MODULE)

# Project name
project(HelloWorld)

# Tell CMake we will be using C++ 11:
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")

# Find and link the ThreadWeaver framework:
find_package(KF5ThreadWeaver ${KF5_VERSION} REQUIRED)

# Add the HelloWorld executable and link the ThreadWeaver library to it
add_executable(ThreadWeaver_HelloWorld HelloWorld.cpp)
target_link_libraries(ThreadWeaver_HelloWorld KF5::ThreadWeaver)

# For more information see the CMake documentation:
# http://www.cmake.org/cmake/help/documentation.html
# http://techbase.kde.org/Development/Tutorials/CMake
cmake_minimum_required(VERSION 2.8.12)
# find KDE's extra cmake modules:
find_package(ECM 1.1.0 REQUIRED NO_MODULE)

# Project name
project(HelloWorld)

# Tell CMake we will be using C++ 11:
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")

if (NOT TARGET KF5ThreadWeaver)
  # Find the ThreadWeaver framework when we compiling this example stand-alone
  find_package(KF5ThreadWeaver ${KF5_VERSION} REQUIRED)
endif()

# Add the HelloWorld executable and link the ThreadWeaver library to it
add_executable(ThreadWeaver_HelloWorld HelloWorld.cpp)
target_link_libraries(ThreadWeaver_HelloWorld KF5::ThreadWeaver)

Fix example compilation when ThreadWeaver is not installed yet.
Fix example compilation when ThreadWeaver is not installed yet.

In such a case, the package configuration is not yet installed and
thus CMake would error out with:

CMake Error at examples/HelloWorld/CMakeLists.txt:15 (find_package):
  By not providing "FindKF5ThreadWeaver.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "KF5ThreadWeaver", but CMake did not find one.

  Could not find a package configuration file provided by "KF5ThreadWeaver"
  (requested version 5.1.0) with any of the following names:

    KF5ThreadWeaverConfig.cmake
    kf5threadweaver-config.cmake

  Add the installation prefix of "KF5ThreadWeaver" to CMAKE_PREFIX_PATH or
  set "KF5ThreadWeaver_DIR" to a directory containing one of the above files.
  If "KF5ThreadWeaver" provides a separate development package or SDK, be
  sure it has been installed.

Now, we check whether the KF5ThreadWeaver target is available and
only if not do we try to find the package externally. This way, the
example is compilable stand-alone as well as in-source always.
