|
| 1 | +# Copyright - 2016-2020 - Jan Christoph Uhde <[email protected]> |
| 2 | + |
| 3 | +cmake_minimum_required(VERSION 3.8) |
| 4 | +project(ext-logging VERSION 0.0.1 LANGUAGES CXX) |
| 5 | +message(STATUS "extINFO -- entering ext-logging") |
| 6 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") |
| 7 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 8 | + |
| 9 | +## OPTIONS |
| 10 | +option(EXTLOG_EXAMPLES "build examples" OFF) |
| 11 | +option(EXTLOG_WARNINGS "enable warnings" ON) |
| 12 | +option(EXTLOG_CHECKED "user assert" ON) |
| 13 | +option(EXTLOG_TESTS "build tests" OFF) |
| 14 | + |
| 15 | +## general setup and includes |
| 16 | +set(CMAKE_CXX_STANDARD 17) |
| 17 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 18 | +set_property(GLOBAL PROPERTY USE_FOLDERS ON) # XCode / VS folders |
| 19 | + |
| 20 | +set(LIBEXT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_libs/ext-basics) |
| 21 | +include(ext_cmake_setup) |
| 22 | +include(ext_cmake_install) |
| 23 | + |
| 24 | +find_package(Threads REQUIRED) |
| 25 | +if(NOT TARGET ext::basics) |
| 26 | + add_subdirectory(external_libs/ext-basics EXCLUDE_FROM_ALL) |
| 27 | +endif() |
| 28 | + |
| 29 | +set(FORCE_COLORED_OUTPUT ON) |
| 30 | +ext_colored_compiler_ouput() |
| 31 | + |
| 32 | +# verbose windows linking |
| 33 | +#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /VERBOSE:LIB") |
| 34 | + |
| 35 | +if(LINUX) |
| 36 | + set(EXT_OUTDIR "") |
| 37 | +elseif(MSVC) |
| 38 | + #TODO - move settings below into corresponding targets |
| 39 | + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${EXT_OUTDIR}") |
| 40 | + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${EXT_OUTDIR}") |
| 41 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXT_OUTDIR}") |
| 42 | + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
| 43 | +endif() |
| 44 | + |
| 45 | +# include build dir to find version.hpp |
| 46 | +set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 47 | + |
| 48 | +# required by folder structure for XCode and VisualStudio (includes) |
| 49 | +# sources are always required |
| 50 | +include(src_files.cmake) |
| 51 | +include(include_files.cmake) |
| 52 | + |
| 53 | +### library setup |
| 54 | +set(ext_common_compile_definitions |
| 55 | + $<IF:$<BOOL:${ext_is_big_endian}>,EXT_BIG_ENDIAN,EXT_LITTLE_ENDIAN> |
| 56 | + $<$<BOOL:${EXT_CXX_COMPILER_IS_GCC}>:EXT_GCC> |
| 57 | + $<$<BOOL:${EXT_CXX_COMPILER_IS_CLANG}>:EXT_CLANG> |
| 58 | + $<$<BOOL:${ext_l1_cache_line_size}>:EXT_KNOWN_L1_CACHE_LINE_SIZE=${ext_l1_cache_line_size}> |
| 59 | +) |
| 60 | + |
| 61 | + |
| 62 | +add_library(ext-logging ${ext-logging-source} ${ext-logging-header}) |
| 63 | +target_include_directories(ext-logging PUBLIC |
| 64 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 65 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include> |
| 66 | +) |
| 67 | +target_compile_features(ext-logging PUBLIC cxx_std_17) |
| 68 | +target_compile_options(ext-logging PRIVATE ${ext_stone-warnings}) |
| 69 | +target_compile_definitions(ext-logging PUBLIC ${ext_common_compile_definitions}) |
| 70 | +target_compile_definitions(ext-logging PUBLIC EXT_SHARED_LIB) |
| 71 | +target_compile_definitions(ext-logging PRIVATE EXT_IN_LIB=1) |
| 72 | +target_link_libraries(ext-logging PUBLIC ext::basics Threads::Threads) |
| 73 | + |
| 74 | +# set up folder structure for XCode and VisualStudio |
| 75 | +set_target_properties (ext-logging PROPERTIES FOLDER logging) |
| 76 | +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ext-logging-header} ${ext-logging-source}) |
| 77 | + |
| 78 | +add_library(ext::logging ALIAS ext-logging) |
| 79 | + |
| 80 | +## testing |
| 81 | +if(EXTLOG_TESTS) |
| 82 | + ext_log("ext-logging tests enabled") |
| 83 | + include(CTest) |
| 84 | + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 85 | + ext_add_test_subdirectory("google" tests) |
| 86 | +else() |
| 87 | + ext_log("ext-logging tests disabled") |
| 88 | +endif() |
| 89 | + |
| 90 | +## add projects using this lib |
| 91 | +if(EXTLOG_EXAMPLES) |
| 92 | + ext_log("ext-logging examples enabled") |
| 93 | + add_subdirectory(examples) |
| 94 | +else() |
| 95 | + ext_log("ext-logging examples disabled") |
| 96 | +endif() |
| 97 | + |
| 98 | +## installation |
| 99 | +if(COMMAND ext_install) |
| 100 | + set_target_properties(ext-logging PROPERTIES EXPORT_NAME logging) |
| 101 | + |
| 102 | + ext_install(ext-logging include/ext) |
| 103 | + |
| 104 | + install(TARGETS ext-logging |
| 105 | + EXPORT ext-logging-targets |
| 106 | + DESTINATION ${CMAKE_INSTALL_PREFIX} |
| 107 | + ) |
| 108 | + install( |
| 109 | + EXPORT ext-logging-targets |
| 110 | + FILE ext-logging-config.cmake |
| 111 | + NAMESPACE ext:: |
| 112 | + DESTINATION ${CMAKE_INSTALL_PREFIX} |
| 113 | + ) |
| 114 | +endif() |
| 115 | + |
| 116 | +add_custom_target( |
| 117 | + update_logging_version ALL |
| 118 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 119 | + COMMAND ${CMAKE_COMMAND} |
| 120 | + -D "EXT_GIT_VERSION_OUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/ext_version.hpp" |
| 121 | + -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/ext_script_git_version.cmake" |
| 122 | +) |
0 commit comments