Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Generate version files and more #763

Merged
merged 8 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@ genrule(
""",
)

genrule(
name = "generate_version_header",
srcs = [],
outs = ["include/faker-cxx/Version.h"],
cmd = """
echo "#pragma once" > $@
echo '#define FAKER_CXX_VERSION_MAJOR 2' >> $@
echo '#define FAKER_CXX_VERSION_MINOR 0' >> $@
echo '#define FAKER_CXX_VERSION_PATCH 0' >> $@
echo '#define FAKER_CXX_VERSION "2.0.0"' >> $@
""",
)

cc_library(
name = "faker-cxx",
srcs = glob(["src/**/*.cpp"]),
hdrs = glob(["src/**/*.h", "include/**/*.h"]) + [":generate_export_header"],
hdrs = glob(["src/**/*.h", "include/**/*.h"]) + [":generate_export_header"] + [":generate_version_header"],
includes = ["include", "src"],
visibility = ["//visibility:public"],
deps = ["@fmt//:fmt"],
Expand Down
119 changes: 15 additions & 104 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.22)
project(faker-cxx LANGUAGES CXX)
project(faker-cxx
LANGUAGES CXX
VERSION 2.0.0
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
DESCRIPTION "C++ Faker library for generating fake (but realistic) data."
HOMEPAGE_URL "https://github.com/cieslarmichal/faker-cxx")

include(cmake/CompilerWarnings.cmake)

Expand Down Expand Up @@ -29,114 +33,21 @@ if (BUILD_TESTING)
add_code_coverage_all_targets()
endif ()

set(FAKER_SOURCES
src/modules/airline/Airline.cpp
src/modules/animal/Animal.cpp
src/modules/book/Book.cpp
src/modules/color/Color.cpp
src/modules/commerce/Commerce.cpp
src/modules/company/Company.cpp
src/modules/computer/Computer.cpp
src/modules/crypto/Crypto.cpp
src/modules/database/Database.cpp
src/modules/datatype/Datatype.cpp
src/modules/date/Date.cpp
src/modules/finance/Finance.cpp
src/modules/food/Food.cpp
src/modules/git/Git.cpp
src/modules/hacker/Hacker.cpp
src/modules/helper/Helper.cpp
src/modules/image/Image.cpp
src/modules/internet/Internet.cpp
src/modules/location/Location.cpp
src/modules/lorem/Lorem.cpp
src/modules/medicine/Medicine.cpp
src/modules/movie/Movie.cpp
src/modules/music/Music.cpp
src/modules/person/Person.cpp
src/modules/phone/Phone.cpp
src/modules/plant/Plant.cpp
src/modules/science/Science.cpp
src/modules/sport/Sport.cpp
src/modules/string/String.cpp
src/modules/system/System.cpp
src/modules/vehicle/Vehicle.cpp
src/modules/videoGame/VideoGame.cpp
src/modules/weather/Weather.cpp
src/modules/word/Word.cpp
src/common/FormatHelper.cpp
src/common/LuhnCheck.cpp
src/common/StringHelper.cpp
)
add_library(${CMAKE_PROJECT_NAME})

add_library(${CMAKE_PROJECT_NAME} ${FAKER_SOURCES})

target_include_directories(
${CMAKE_PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

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

target_compile_features(${CMAKE_PROJECT_NAME} PUBLIC cxx_std_20)
configure_compiler_warnings(${CMAKE_PROJECT_NAME}
"${WARNINGS_AS_ERRORS}"
"${MSVC_WARNINGS}"
"${CLANG_WARNINGS}"
"${GCC_WARNINGS}")

include(GenerateExportHeader)
generate_export_header(${CMAKE_PROJECT_NAME} BASE_NAME FAKER_CXX EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/include/faker-cxx/Export.h)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden
CMAKE_VISIBILITY_INLINES_HIDDEN 1
)

target_include_directories(
${CMAKE_PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include
)

include(GNUInstallDirs)
install(TARGETS ${CMAKE_PROJECT_NAME}
EXPORT ${CMAKE_PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/faker-cxx
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
)

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/faker-cxx
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
)

install(EXPORT ${CMAKE_PROJECT_NAME}-targets
NAMESPACE ${CMAKE_PROJECT_NAME}::
FILE ${CMAKE_PROJECT_NAME}-config.cmake
DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})

if (USE_STD_FORMAT)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE USE_STD_FORMAT)
elseif (USE_SYSTEM_DEPENDENCIES)
if (USE_SYSTEM_DEPENDENCIES)
find_package(fmt CONFIG REQUIRED)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE fmt::fmt)
else ()
add_subdirectory(externals/fmt)
elseif (NOT USE_STD_FORMAT)
find_library(FMT_LIBRARY fmt)
if (NOT FMT_LIBRARY)
message(FATAL_ERROR "Could not find fmt library. Please, read the contribution guide.")
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
endif()
add_subdirectory("${CMAKE_SOURCE_DIR}/externals/fmt")
set(FMT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/fmt/include")
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE fmt)
endif ()

add_subdirectory(src)

if (BUILD_TESTING)
add_subdirectory(tests)
endif ()
Expand Down
6 changes: 6 additions & 0 deletions cmake/Version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#define FAKER_CXX_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
#define FAKER_CXX_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define FAKER_CXX_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define FAKER_CXX_VERSION "@PROJECT_VERSION@"
12 changes: 12 additions & 0 deletions cmake/faker-cxx.pc.in
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@

Requires:
Libs: -L${libdir} -lfaker-cxx
Cflags: -I${includedir}
1 change: 1 addition & 0 deletions include/faker-cxx/Faker.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "faker-cxx/String.h"
#include "faker-cxx/System.h"
#include "faker-cxx/Vehicle.h"
#include "faker-cxx/Version.h"
#include "faker-cxx/VideoGame.h"
#include "faker-cxx/Weather.h"
#include "faker-cxx/Word.h"
173 changes: 173 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
cmake_minimum_required(VERSION 3.22)

include("${CMAKE_SOURCE_DIR}/cmake/CompilerWarnings.cmake")

set(FAKER_SOURCES
modules/airline/Airline.cpp
modules/animal/Animal.cpp
modules/book/Book.cpp
modules/color/Color.cpp
modules/commerce/Commerce.cpp
modules/company/Company.cpp
modules/computer/Computer.cpp
modules/crypto/Crypto.cpp
modules/database/Database.cpp
modules/datatype/Datatype.cpp
modules/date/Date.cpp
modules/finance/Finance.cpp
modules/food/Food.cpp
modules/git/Git.cpp
modules/hacker/Hacker.cpp
modules/helper/Helper.cpp
modules/image/Image.cpp
modules/internet/Internet.cpp
modules/location/Location.cpp
modules/lorem/Lorem.cpp
modules/medicine/Medicine.cpp
modules/movie/Movie.cpp
modules/music/Music.cpp
modules/person/Person.cpp
modules/phone/Phone.cpp
modules/plant/Plant.cpp
modules/science/Science.cpp
modules/sport/Sport.cpp
modules/string/String.cpp
modules/system/System.cpp
modules/vehicle/Vehicle.cpp
modules/videoGame/VideoGame.cpp
modules/weather/Weather.cpp
modules/word/Word.cpp
common/FormatHelper.cpp
common/LuhnCheck.cpp
common/StringHelper.cpp
)

set(FAKER_HEADERS
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
common/LuhnCheck.h
common/FormatHelper.h
common/StringHelper.h
modules/plant/PlantData.h
modules/person/PersonData.h
modules/internet/InternetData.h
modules/sport/SportData.h
modules/airline/AirlineData.h
modules/location/LocationData.h
modules/book/BookData.h
modules/string/StringData.h
modules/videoGame/VideoGameData.h
modules/medicine/MedicineData.h
modules/vehicle/VehicleData.h
modules/hacker/HackerData.h
modules/science/ScienceData.h
modules/date/DateData.h
modules/system/SystemData.h
modules/commerce/CommerceData.h
modules/computer/ComputerData.h
modules/weather/WeatherData.h
modules/music/MusicData.h
modules/database/DatabaseData.h
modules/movie/MovieData.h
modules/food/FoodData.h
modules/word/WordData.h
modules/word/WordStore.h
modules/animal/AnimalData.h
modules/company/CompanyData.h
modules/finance/FinanceData.h
modules/phone/PhoneData.h
modules/color/ColorData.h
modules/lorem/LoremData.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}>)
if (USE_STD_FORMAT)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE USE_STD_FORMAT)
endif()

target_include_directories(
${CMAKE_PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_include_directories(
${CMAKE_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}
"${WARNINGS_AS_ERRORS}"
"${MSVC_WARNINGS}"
"${CLANG_WARNINGS}"
"${GCC_WARNINGS}")

configure_file(
"${CMAKE_SOURCE_DIR}/cmake/Version.h.in"
"${CMAKE_BINARY_DIR}/include/faker-cxx/Version.h"
@ONLY
)

include(GenerateExportHeader)
generate_export_header(${CMAKE_PROJECT_NAME}
BASE_NAME FAKER_CXX
EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/include/faker-cxx/Export.h
)
set_target_properties(${CMAKE_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}
PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
PRIVATE ${CMAKE_BINARY_DIR}/include
)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

configure_file(
"${CMAKE_SOURCE_DIR}/cmake/${CMAKE_PROJECT_NAME}.pc.in"
"${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.pc"
@ONLY
)

write_basic_package_version_file(${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

install(TARGETS ${CMAKE_PROJECT_NAME}
EXPORT ${CMAKE_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
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
)

install(DIRECTORY ${CMAKE_BINARY_DIR}/include/faker-cxx
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
)

install(FILES "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

install(FILES
"${CMAKE_BINARY_DIR}/${CMAKE_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
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
)
6 changes: 5 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.22)
project(${CMAKE_PROJECT_NAME}-UT CXX)

include(CTest)
include(GoogleTest)
include("${CMAKE_SOURCE_DIR}/cmake/CompilerWarnings.cmake")

set(FAKER_UT_SOURCES
Expand Down Expand Up @@ -40,6 +41,7 @@ set(FAKER_UT_SOURCES
modules/string/StringTest.cpp
modules/system/SystemTest.cpp
modules/vehicle/VehicleTest.cpp
modules/version/VersionTest.cpp
modules/videoGame/VideoGameTest.cpp
modules/weather/WeatherTest.cpp
modules/word/WordTest.cpp
Expand Down Expand Up @@ -74,7 +76,7 @@ if (USE_STD_FORMAT)
target_include_directories(${PROJECT_NAME} PRIVATE ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR})
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_STD_FORMAT)
else ()
target_link_libraries(${PROJECT_NAME} PRIVATE $<IF:$<TARGET_EXISTS:fmt::fmt>,fmt::fmt,fmt>)
target_link_libraries(${PROJECT_NAME} PRIVATE $<IF:$<TARGET_EXISTS:fmt::fmt>,fmt::fmt,${FMT_LIBRARY}>)
target_include_directories(${PROJECT_NAME} PRIVATE ${FMT_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR})
endif ()

Expand All @@ -83,3 +85,5 @@ set_tests_properties(${PROJECT_NAME} PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<$<BOOL:${WIN32}>:$<TARGET_FILE_DIR:faker-cxx>>")

target_code_coverage(${PROJECT_NAME} ALL)

gtest_discover_tests(${PROJECT_NAME})
uilianries marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading