check if cppformat is the master project or just used as dependency

Based on that information less intrusive option defaults are choosen.
Additionally, packaging support is omitted.
This commit is contained in:
Mario Werner 2016-02-03 11:20:19 +01:00
parent 797d72133e
commit c1a4cd0fa7
4 changed files with 44 additions and 6 deletions

View File

@ -2,6 +2,13 @@ message(STATUS "CMake version: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
# determine if cppformat is built as sub project (using add_subdirectory)
# or if it is the master project
set(MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MASTER_PROJECT ON)
endif ()
# Set the default CMAKE_BUILD_TYPE to Release. # Set the default CMAKE_BUILD_TYPE to Release.
# This should be done before the project command since the latter can set # This should be done before the project command since the latter can set
# CMAKE_BUILD_TYPE itself (it does so for nmake). # CMAKE_BUILD_TYPE itself (it does so for nmake).
@ -13,9 +20,9 @@ endif ()
option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF)
# Options that control generation of various targets. # Options that control generation of various targets.
option(FMT_DOC "Generate the doc target." ON) option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT})
option(FMT_INSTALL "Generate the install target." ON) option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
option(FMT_TEST "Generate the test target." ON) option(FMT_TEST "Generate the test target." ${MASTER_PROJECT})
project(FORMAT) project(FORMAT)
@ -41,7 +48,7 @@ if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wshadow -pedantic) set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wshadow -pedantic)
endif () endif ()
if (CMAKE_GENERATOR MATCHES "Visual Studio") if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio")
# If Microsoft SDK is installed create script run-msbuild.bat that # If Microsoft SDK is installed create script run-msbuild.bat that
# calls SetEnv.cmd to to set up build environment and runs msbuild. # calls SetEnv.cmd to to set up build environment and runs msbuild.
# It is useful when building Visual Studio projects with the SDK # It is useful when building Visual Studio projects with the SDK
@ -81,7 +88,7 @@ if (FMT_TEST)
endif () endif ()
set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore) set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore)
if (EXISTS ${gitignore}) if (MASTER_PROJECT AND EXISTS ${gitignore})
# Get the list of ignored files from .gitignore. # Get the list of ignored files from .gitignore.
file (STRINGS ${gitignore} lines) file (STRINGS ${gitignore} lines)
LIST(REMOVE_ITEM lines /doc/html) LIST(REMOVE_ITEM lines /doc/html)

View File

@ -144,3 +144,13 @@ add_test(find-package-test ${CMAKE_CTEST_COMMAND}
--build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options "-Dcppformat_DIR=${PROJECT_BINARY_DIR}" --build-options "-Dcppformat_DIR=${PROJECT_BINARY_DIR}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
# test if the targets are findable when add_subdirectory is used
add_test(add_subdirectory-test ${CMAKE_CTEST_COMMAND}
-C ${CMAKE_BUILD_TYPE}
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/add_subdirectory-test"
"${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory-test"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")

View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 2.8.12)
project(cppformat-test)
add_subdirectory(../.. cppformat)
add_executable(library-test "main.cpp")
target_link_libraries(library-test cppformat)
if (TARGET cppformat-header-only)
add_executable(header-only-test "main.cpp")
target_link_libraries(header-only-test cppformat-header-only)
endif ()

View File

@ -0,0 +1,8 @@
#include "cppformat/format.h"
int main(int argc, char** argv)
{
for(int i = 0; i < argc; ++i)
fmt::print("{}: {}\n", i, argv[i]);
return 0;
}