From 210fb54ef038304504e746d386b381c3ff421db4 Mon Sep 17 00:00:00 2001 From: wrathdoesthat <152635455+wrathdoesthat@users.noreply.github.com> Date: Sat, 21 Sep 2024 12:23:48 -0400 Subject: [PATCH] Initial commit (#919) --- CMakeLists.txt | 8 ++++---- src/CMakeLists.txt | 48 ++++++++++++++++++++++---------------------- tests/CMakeLists.txt | 16 ++++++++------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 964f846a..5b4ce67a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,17 +29,17 @@ endif() cmake_dependent_option(USE_STD_FORMAT "Use std::format when available" ON "HAS_STD_FORMAT" OFF) -add_library(${CMAKE_PROJECT_NAME}) +add_library(${PROJECT_NAME}) if (USE_SYSTEM_DEPENDENCIES) find_package(fmt CONFIG REQUIRED) elseif (NOT USE_STD_FORMAT) - add_subdirectory("${CMAKE_SOURCE_DIR}/externals/fmt") + add_subdirectory("${SOURCE_DIR}/externals/fmt") find_library(FMT_LIBRARY fmt) if (NOT FMT_LIBRARY) message(FATAL_ERROR "Could not find fmt library. Please, read the contribution guide.") endif() - set(FMT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/fmt/include") + set(FMT_INCLUDE_DIR "${SOURCE_DIR}/externals/fmt/include") endif () add_subdirectory(src) @@ -48,7 +48,7 @@ if (CODE_COVERAGE) set(target_code_coverage_ALL 1) include("cmake/cmake-coverage.cmake") add_code_coverage_all_targets(EXCLUDE tests/*) - target_code_coverage(${CMAKE_PROJECT_NAME} ALL) + target_code_coverage(${PROJECT_NAME} ALL) endif () if (BUILD_TESTING) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1592964e..f881f605 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.22) -include("${CMAKE_SOURCE_DIR}/cmake/CompilerWarnings.cmake") +include("${PROJECT_SOURCE_DIR}/cmake/CompilerWarnings.cmake") set(FAKER_SOURCES modules/airline.cpp @@ -84,42 +84,42 @@ set(FAKER_HEADERS modules/esport_data.h ) -target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${FAKER_SOURCES} ${FAKER_HEADERS}) -target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE $,fmt::fmt,${FMT_LIBRARY}>) +target_sources(${PROJECT_NAME} PRIVATE ${FAKER_SOURCES} ${FAKER_HEADERS}) +target_link_libraries(${PROJECT_NAME} PRIVATE $,fmt::fmt,${FMT_LIBRARY}>) if (USE_STD_FORMAT) - target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE USE_STD_FORMAT) + target_compile_definitions(${PROJECT_NAME} PRIVATE USE_STD_FORMAT) endif () target_include_directories( - ${CMAKE_PROJECT_NAME} PUBLIC - $ + ${PROJECT_NAME} PUBLIC + $ $ ) target_include_directories( - ${CMAKE_PROJECT_NAME} PRIVATE + ${PROJECT_NAME} PRIVATE $ ) -target_compile_features(${CMAKE_PROJECT_NAME} PUBLIC cxx_std_20) -configure_compiler_warnings(${CMAKE_PROJECT_NAME} +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) +configure_compiler_warnings(${PROJECT_NAME} "${WARNINGS_AS_ERRORS}" "${MSVC_WARNINGS}" "${CLANG_WARNINGS}" "${GCC_WARNINGS}") configure_file( - "${CMAKE_SOURCE_DIR}/cmake/Version.h.in" + "${PROJECT_SOURCE_DIR}/cmake/Version.h.in" "${CMAKE_BINARY_DIR}/include/faker-cxx/version.h" @ONLY ) include(GenerateExportHeader) -generate_export_header(${CMAKE_PROJECT_NAME} +generate_export_header(${PROJECT_NAME} BASE_NAME FAKER_CXX EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/include/faker-cxx/export.h ) -set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES +set_target_properties(${PROJECT_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden CMAKE_VISIBILITY_INLINES_HIDDEN 1 VERSION ${CMAKE_PROJECT_VERSION} @@ -127,7 +127,7 @@ set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ) target_include_directories( - ${CMAKE_PROJECT_NAME} + ${PROJECT_NAME} PUBLIC $ PRIVATE ${CMAKE_BINARY_DIR}/include ) @@ -136,22 +136,22 @@ include(CMakePackageConfigHelpers) include(GNUInstallDirs) configure_file( - "${CMAKE_SOURCE_DIR}/cmake/${CMAKE_PROJECT_NAME}.pc.in" - "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.pc" + "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}.pc.in" + "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY ) -write_basic_package_version_file(${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake +write_basic_package_version_file(${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${CMAKE_PROJECT_VERSION} COMPATIBILITY SameMajorVersion) -install(TARGETS ${CMAKE_PROJECT_NAME} - EXPORT ${CMAKE_PROJECT_NAME}-targets +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/faker-cxx +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/faker-cxx DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h" @@ -163,17 +163,17 @@ install(DIRECTORY ${CMAKE_BINARY_DIR}/include/faker-cxx PATTERN "*.h" ) -install(FILES "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.pc" +install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) install(FILES - "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake" + "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake ) -install(EXPORT ${CMAKE_PROJECT_NAME}-targets - NAMESPACE ${CMAKE_PROJECT_NAME}:: - FILE ${CMAKE_PROJECT_NAME}-config.cmake +install(EXPORT ${PROJECT_NAME}-targets + NAMESPACE ${PROJECT_NAME}:: + FILE ${PROJECT_NAME}-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0bc3a7af..ef1c1213 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.22) project(${CMAKE_PROJECT_NAME}-UT CXX) include(CTest) -include("${CMAKE_SOURCE_DIR}/cmake/CompilerWarnings.cmake") + +get_filename_component(PARENT_DIR ../ ABSOLUTE) +include("${PARENT_DIR}/cmake/CompilerWarnings.cmake") set(FAKER_UT_SOURCES common/format_helper_test.cpp @@ -57,19 +59,19 @@ configure_compiler_warnings(${PROJECT_NAME} "${GCC_WARNINGS}") target_include_directories(${PROJECT_NAME} PRIVATE - ${CMAKE_SOURCE_DIR}/src - ${CMAKE_SOURCE_DIR}/src/common - ${CMAKE_SOURCE_DIR}/src/modules + ../src + ../src/common + ../src/modules ) if (USE_SYSTEM_DEPENDENCIES) find_package(GTest REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main faker-cxx) else () - add_subdirectory("${CMAKE_SOURCE_DIR}/externals/googletest" "${CMAKE_BINARY_DIR}/googletest") + add_subdirectory("${PARENT_DIR}/externals/googletest" "${CMAKE_BINARY_DIR}/googletest") - set(GTEST_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/googletest/googletest/include") - set(GMOCK_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/googletest/googlemock/include") + set(GTEST_INCLUDE_DIR "${PARENT_DIR}/externals/googletest/googletest/include") + set(GMOCK_INCLUDE_DIR "${PARENT_DIR}/externals/googletest/googlemock/include") target_link_libraries(${PROJECT_NAME} PRIVATE gtest_main gmock_main faker-cxx) endif ()