Skip to content

Commit

Permalink
cmake added FetchContent support
Browse files Browse the repository at this point in the history
Primary fixed paths CMAKE_SOURCE_DIR, PROJECT_SOURCE_DIR,
CMAKE_BINARY_DIR and similar.

An user can use the following code in the CMakeLists.txt file to
fetch and configure the TinyORM project from GitHub:

FetchContent_Declare(TinyORM
    GIT_REPOSITORY https://github.com/silverqx/TinyORM.git
    GIT_TAG        origin/main
)
# Here you can configure TinyORM CMake options
set(TOM_EXAMPLE ON)
FetchContent_MakeAvailable(TinyORM)
  • Loading branch information
silverqx committed Aug 11, 2022
1 parent fa6f6b9 commit 23d0d90
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ endif()

# Find icons, orm/version.hpp, and Windows manifest file for MinGW
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
tiny_set_rc_flags("-I \"${CMAKE_CURRENT_SOURCE_DIR}/resources\"")
tiny_set_rc_flags("-I \"${PROJECT_SOURCE_DIR}/resources\"")
endif()

include(TinyResourceAndManifest)
Expand Down
10 changes: 5 additions & 5 deletions cmake/Modules/TinyInitDefaultVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,19 @@ macro(tiny_init_tiny_variables)
string(PREPEND TINY_TESTS_ENV "\
$<SHELL_PATH:${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/\
${CMAKE_INSTALL_BINDIR}>${TINY_PATH_SEPARATOR}\
$<SHELL_PATH:${CMAKE_BINARY_DIR}/tests/${TinyUtils_ns}>${TINY_PATH_SEPARATOR}")
$<SHELL_PATH:${${TinyOrm_ns}_BINARY_DIR}/tests/${TinyUtils_ns}>${TINY_PATH_SEPARATOR}")

# Prepend TinyOrm and TinyUtils library folders
else()
# Multi-config generators have different folders structure
if(TINY_IS_MULTI_CONFIG)
string(PREPEND TINY_TESTS_ENV "\
$<SHELL_PATH:${CMAKE_BINARY_DIR}/$<CONFIG>>${TINY_PATH_SEPARATOR}\
$<SHELL_PATH:${CMAKE_BINARY_DIR}/tests/${TinyUtils_ns}/$<CONFIG>>${TINY_PATH_SEPARATOR}")
$<SHELL_PATH:${${TinyOrm_ns}_BINARY_DIR}/$<CONFIG>>${TINY_PATH_SEPARATOR}\
$<SHELL_PATH:${${TinyOrm_ns}_BINARY_DIR}/tests/${TinyUtils_ns}/$<CONFIG>>${TINY_PATH_SEPARATOR}")
else()
string(PREPEND TINY_TESTS_ENV "\
$<SHELL_PATH:${CMAKE_BINARY_DIR}>${TINY_PATH_SEPARATOR}\
$<SHELL_PATH:${CMAKE_BINARY_DIR}/tests/${TinyUtils_ns}>${TINY_PATH_SEPARATOR}")
$<SHELL_PATH:${${TinyOrm_ns}_BINARY_DIR}>${TINY_PATH_SEPARATOR}\
$<SHELL_PATH:${${TinyOrm_ns}_BINARY_DIR}/tests/${TinyUtils_ns}>${TINY_PATH_SEPARATOR}")
endif()
endif()
endif()
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/TinySources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ function(tinytom_sources out_headers out_sources)
list(SORT headers)
list(SORT sources)

list(TRANSFORM headers PREPEND "${CMAKE_SOURCE_DIR}/tom/include/tom/")
list(TRANSFORM sources PREPEND "${CMAKE_SOURCE_DIR}/tom/src/tom/")
list(TRANSFORM headers PREPEND "${PROJECT_SOURCE_DIR}/tom/include/tom/")
list(TRANSFORM sources PREPEND "${PROJECT_SOURCE_DIR}/tom/src/tom/")

set(${out_headers} ${headers} PARENT_SCOPE)
set(${out_sources} ${sources} PARENT_SCOPE)
Expand Down
14 changes: 9 additions & 5 deletions cmake/Modules/TinyTestCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ${TINY_UNPARSED_ARGUMENTS}")
endif()

target_precompile_headers(${name} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_SOURCE_DIR}/include/pch.h">
$<$<COMPILE_LANGUAGE:CXX>:"${${TinyOrm_ns}_SOURCE_DIR}/include/pch.h">
)

if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
Expand Down Expand Up @@ -56,11 +56,15 @@ ${TINY_UNPARSED_ARGUMENTS}")
endif()

if(TINY_INCLUDE_MIGRATIONS)
target_include_directories(${name} PRIVATE "${CMAKE_SOURCE_DIR}/tests/database")
target_include_directories(${name}
PRIVATE "${${TinyOrm_ns}_SOURCE_DIR}/tests/database"
)
endif()

if(TINY_INCLUDE_MODELS)
target_include_directories(${name} PRIVATE "${CMAKE_SOURCE_DIR}/tests/models")
target_include_directories(${name}
PRIVATE "${${TinyOrm_ns}_SOURCE_DIR}/tests/models"
)
endif()

target_link_libraries(${name}
Expand All @@ -75,7 +79,7 @@ ${TINY_UNPARSED_ARGUMENTS}")

# Find Windows manifest file for MinGW
if(MINGW)
tiny_set_rc_flags("-I \"${CMAKE_SOURCE_DIR}/tests/resources\"")
tiny_set_rc_flags("-I \"${${TinyOrm_ns}_SOURCE_DIR}/tests/resources\"")

# I will not use output variables here, I like it this way 🤘
set(CMAKE_RC_FLAGS ${CMAKE_RC_FLAGS} PARENT_SCOPE)
Expand All @@ -84,7 +88,7 @@ ${TINY_UNPARSED_ARGUMENTS}")

tiny_resource_and_manifest(${name}
OUTPUT_DIR "${TINY_BUILD_GENDIR}/tmp/"
TEST RESOURCES_DIR "${CMAKE_SOURCE_DIR}/tests/resources"
TEST RESOURCES_DIR "${${TinyOrm_ns}_SOURCE_DIR}/tests/resources"
)

endfunction()
8 changes: 4 additions & 4 deletions examples/tom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include(TinyHelpers)
tiny_read_version(TINY_VERSION
TINY_VERSION_MAJOR TINY_VERSION_MINOR TINY_VERSION_PATCH TINY_VERSION_TWEAK
VERSION_HEADER "${CMAKE_SOURCE_DIR}/tom/include/tom/version.hpp"
VERSION_HEADER "${${TinyOrm_ns}_SOURCE_DIR}/tom/include/tom/version.hpp"
PREFIX TINYTOM
HEADER_FOR "${TomExample_ns}"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ set_target_properties(${TomExample_target}
)

target_include_directories(${TomExample_target} PRIVATE
"${CMAKE_SOURCE_DIR}/tests/database"
"${${TinyOrm_ns}_SOURCE_DIR}/tests/database"
)

# Tom command-line application defines
Expand All @@ -58,13 +58,13 @@ target_compile_definitions(${TomExample_target}

# Find icons, tom/version.hpp, and Windows manifest file for MinGW
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
tiny_set_rc_flags("-I \"${CMAKE_SOURCE_DIR}/tom/resources\"")
tiny_set_rc_flags("-I \"${${TinyOrm_ns}_SOURCE_DIR}/tom/resources\"")
endif()

include(TinyResourceAndManifest)
tiny_resource_and_manifest(${TomExample_target}
OUTPUT_DIR "${TINY_BUILD_GENDIR}/tmp/"
RESOURCES_DIR "${CMAKE_SOURCE_DIR}/tom/resources"
RESOURCES_DIR "${${TinyOrm_ns}_SOURCE_DIR}/tom/resources"
)

# Resolve and link dependencies
Expand Down
4 changes: 2 additions & 2 deletions tests/TinyUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ endif()

# Find Windows manifest file
if(MINGW)
tiny_set_rc_flags("-I \"${CMAKE_CURRENT_SOURCE_DIR}/resources\"")
tiny_set_rc_flags("-I \"${PROJECT_SOURCE_DIR}/resources\"")

# To remove values from CMAKE_RC_FLAGS from the previous call
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
Expand All @@ -111,7 +111,7 @@ target_link_libraries(${TinyUtils_target}
# ---

# Create an empty SQLite database file when does not exist
set(tiny_sqlite_db "${CMAKE_BINARY_DIR}/tests/q_tinyorm_test_1.sqlite3")
set(tiny_sqlite_db "${${TinyOrm_ns}_BINARY_DIR}/tests/q_tinyorm_test_1.sqlite3")
create_sqlite_db("${tiny_sqlite_db}")

target_compile_definitions(${TinyUtils_target}
Expand Down
2 changes: 1 addition & 1 deletion tests/auto/functional/others/version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if(TOM_EXAMPLE)
target_compile_definitions(version PRIVATE TINYTOM_EXAMPLE)

# To find tom/include/version.hpp
target_include_directories(version PRIVATE "${CMAKE_SOURCE_DIR}/tom/include")
target_include_directories(version PRIVATE "${${TinyOrm_ns}_SOURCE_DIR}/tom/include")
endif()

target_include_directories(version PRIVATE
Expand Down
6 changes: 3 additions & 3 deletions tests/testdata_tom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include(TinyHelpers)
tiny_read_version(TINY_VERSION
TINY_VERSION_MAJOR TINY_VERSION_MINOR TINY_VERSION_PATCH TINY_VERSION_TWEAK
VERSION_HEADER "${CMAKE_SOURCE_DIR}/tom/include/tom/version.hpp"
VERSION_HEADER "${${TinyOrm_ns}_SOURCE_DIR}/tom/include/tom/version.hpp"
PREFIX TINYTOM
HEADER_FOR "${TomTestData_ns}"
)
Expand Down Expand Up @@ -58,13 +58,13 @@ target_compile_definitions(${TomTestData_target}

# Find icons, tom/version.hpp, and Windows manifest file for MinGW
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
tiny_set_rc_flags("-I \"${CMAKE_SOURCE_DIR}/tom/resources\"")
tiny_set_rc_flags("-I \"${${TinyOrm_ns}_SOURCE_DIR}/tom/resources\"")
endif()

include(TinyResourceAndManifest)
tiny_resource_and_manifest(${TomTestData_target}
OUTPUT_DIR "${TINY_BUILD_GENDIR}/tmp/"
RESOURCES_DIR "${CMAKE_SOURCE_DIR}/tom/resources"
RESOURCES_DIR "${${TinyOrm_ns}_SOURCE_DIR}/tom/resources"
RESOURCE_BASENAME ${Tom_target}
MANIFEST_BASENAME ${Tom_target}
)
Expand Down

0 comments on commit 23d0d90

Please sign in to comment.