| 1 |
#Copyright (c) Microsoft. All rights reserved. |
| 2 |
#Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
cmake_minimum_required(VERSION 2.8.11) |
| 5 |
|
| 6 |
if(TARGET testrunnerswitcher) |
| 7 |
RETURN() |
| 8 |
endif() |
| 9 |
|
| 10 |
project(testrunnerswitcher) |
| 11 |
|
| 12 |
set(TESTRUNNER_VERSION 1.1.19) |
| 13 |
|
| 14 |
# Build with -fPIC always |
| 15 |
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 16 |
|
| 17 |
include (CTest) |
| 18 |
|
| 19 |
option(run_valgrind "set run_valgrind to ON if tests are to be run under valgrind/helgrind/drd. Default is OFF" OFF) |
| 20 |
option(use_installed_dependencies "set use_installed_dependencies to ON to use installed packages instead of building dependencies from submodules" OFF) |
| 21 |
|
| 22 |
if (CMAKE_VERSION VERSION_LESS "3.1") |
| 23 |
if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 24 |
set (CMAKE_C_FLAGS "--std=c99 ${CMAKE_C_FLAGS}") |
| 25 |
set (CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}") |
| 26 |
endif() |
| 27 |
else() |
| 28 |
set (CMAKE_C_STANDARD 99) |
| 29 |
set (CMAKE_CXX_STANDARD 11) |
| 30 |
endif() |
| 31 |
|
| 32 |
if(${use_installed_dependencies}) |
| 33 |
if (NOT azure_macro_utils_cFOUND) |
| 34 |
find_package(azure_macro_utils_c REQUIRED CONFIG) |
| 35 |
include_directories(${MACRO_UTILS_INC_FOLDER}) |
| 36 |
endif() |
| 37 |
else() |
| 38 |
if (NOT TARGET azure_macro_utils_c) |
| 39 |
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/deps/azure-macro-utils-c/CMakeLists.txt) |
| 40 |
add_subdirectory(deps/azure-macro-utils-c) |
| 41 |
include_directories(${MACRO_UTILS_INC_FOLDER}) |
| 42 |
else() |
| 43 |
message(FATAL_ERROR "Could not find azure_macro_utils_c. Run 'git submodule update --init'") |
| 44 |
endif() |
| 45 |
endif() |
| 46 |
endif() |
| 47 |
|
| 48 |
set(testrunnerswitcher_c_files |
| 49 |
./src/testmutex.c |
| 50 |
./src/ctrs_sprintf.c |
| 51 |
) |
| 52 |
|
| 53 |
set(testrunnerswitcher_h_files |
| 54 |
./inc/testrunnerswitcher.h |
| 55 |
./inc/ctrs_sprintf.h |
| 56 |
./inc/testmutex.h |
| 57 |
) |
| 58 |
|
| 59 |
add_library(testrunnerswitcher ${testrunnerswitcher_c_files} ${testrunnerswitcher_h_files}) |
| 60 |
|
| 61 |
target_include_directories(testrunnerswitcher |
| 62 |
PUBLIC |
| 63 |
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/inc> |
| 64 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 65 |
) |
| 66 |
|
| 67 |
set_target_properties(testrunnerswitcher |
| 68 |
PROPERTIES |
| 69 |
FOLDER "test_tools") |
| 70 |
|
| 71 |
#these are the include folders |
| 72 |
#the following "set" statetement exports across the project a global variable called TESTRUNNERSWITCHER_INC_FOLDER that expands to whatever needs to included when using tesrtrunnerswitcher library |
| 73 |
set(TESTRUNNERSWITCHER_INC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/inc CACHE INTERNAL "this is what needs to be included if using testrunnerswitcher header" FORCE) |
| 74 |
|
| 75 |
include_directories(${TESTRUNNERSWITCHER_INC_FOLDER}) |
| 76 |
|
| 77 |
# Set CMAKE_INSTALL_* if not defined |
| 78 |
include(GNUInstallDirs) |
| 79 |
|
| 80 |
if(NOT DEFINED CMAKE_INSTALL_LIBDIR) |
| 81 |
set(CMAKE_INSTALL_LIBDIR "lib") |
| 82 |
endif() |
| 83 |
|
| 84 |
# Install Azure Test Runner Switcher |
| 85 |
set(package_location "cmake") |
| 86 |
|
| 87 |
install (TARGETS testrunnerswitcher EXPORT testrunnerswitcherTargets |
| 88 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 89 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 90 |
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/../bin |
| 91 |
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 92 |
) |
| 93 |
|
| 94 |
install (FILES ${testrunnerswitcher_h_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 95 |
|
| 96 |
include(CMakePackageConfigHelpers) |
| 97 |
|
| 98 |
write_basic_package_version_file( |
| 99 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" |
| 100 |
VERSION ${TESTRUNNER_VERSION} |
| 101 |
COMPATIBILITY SameMajorVersion |
| 102 |
) |
| 103 |
|
| 104 |
configure_file("configs/${PROJECT_NAME}Config.cmake" |
| 105 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" |
| 106 |
COPYONLY |
| 107 |
) |
| 108 |
|
| 109 |
install(EXPORT testrunnerswitcherTargets |
| 110 |
FILE |
| 111 |
"${PROJECT_NAME}Targets.cmake" |
| 112 |
DESTINATION |
| 113 |
${package_location} |
| 114 |
) |
| 115 |
install( |
| 116 |
FILES |
| 117 |
"configs/${PROJECT_NAME}Config.cmake" |
| 118 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" |
| 119 |
DESTINATION |
| 120 |
${package_location} |
| 121 |
) |
| 122 |
|