Skip to content

Commit

Permalink
Initial commit (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
wrathdoesthat authored Sep 21, 2024
1 parent b47afe8 commit 210fb54
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
48 changes: 24 additions & 24 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -84,50 +84,50 @@ set(FAKER_HEADERS
modules/esport_data.h
)

target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${FAKER_SOURCES} ${FAKER_HEADERS})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE $<IF:$<TARGET_EXISTS:fmt::fmt>,fmt::fmt,${FMT_LIBRARY}>)
target_sources(${PROJECT_NAME} PRIVATE ${FAKER_SOURCES} ${FAKER_HEADERS})
target_link_libraries(${PROJECT_NAME} PRIVATE $<IF:$<TARGET_EXISTS:fmt::fmt>,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
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_include_directories(
${CMAKE_PROJECT_NAME} PRIVATE
${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

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}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
)

target_include_directories(
${CMAKE_PROJECT_NAME}
${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
PRIVATE ${CMAKE_BINARY_DIR}/include
)
Expand All @@ -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"
Expand All @@ -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
)
16 changes: 9 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down

0 comments on commit 210fb54

Please sign in to comment.