Skip to content

Commit

Permalink
Merge pull request #5 from red0124/improvement/cmake_update
Browse files Browse the repository at this point in the history
Update CMake files
  • Loading branch information
red0124 authored Feb 18, 2023
2 parents d461084 + fac70fe commit e6a9a3b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
34 changes: 15 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ cmake_minimum_required(VERSION 3.14)

project(
sgc
VERSION 0.0.1
DESCRIPTION "Static split parser"
VERSION 1.0.0
DESCRIPTION "generic algorithms and data structures"
HOMEPAGE_URL "https://github.com/red0124/sgc"
LANGUAGES C
)

# ---- Warning guard ----

# Protect dependents from this project's warnings if the guard isn't disabled
set(sgc_warning_guard SYSTEM)
set(SGC_WARNING_GUARD SYSTEM)
if(sgc_INCLUDE_WITHOUT_SYSTEM)
set(sgc_warning_guard "")
set(SGC_WARNING_GUARD "")
endif()

# ---- Declare library ----
Expand All @@ -23,36 +23,32 @@ add_library(sgc::sgc ALIAS sgc)

target_include_directories(
sgc
${sgc_warning_guard}
INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
${SGC_WARNING_GUARD}
INTERFACE "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
)

target_compile_features(sgc INTERFACE)

target_link_libraries(
sgc
INTERFACE
)
target_link_libraries(sgc INTERFACE)

# ---- Install ----

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

set(sgc_directory "sgc-${PROJECT_VERSION}")
set(sgc_include_directory "${CMAKE_INSTALL_INCLUDEDIR}")
set(SGC_DIRECTORY "sgc-${PROJECT_VERSION}")
set(SGC_INCLUDE_DIRECTORY "${CMAKE_INSTALL_INCLUDEDIR}")

install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
DESTINATION "${sgc_include_directory}"
DESTINATION "${SGC_INCLUDE_DIRECTORY}"
COMPONENT sgc_Development
)

install(
TARGETS sgc
EXPORT sgcTargets
INCLUDES DESTINATION "${sgc_include_directory}"
INCLUDES DESTINATION "${SGC_INCLUDE_DIRECTORY}"
)

write_basic_package_version_file(
Expand All @@ -61,22 +57,22 @@ write_basic_package_version_file(
ARCH_INDEPENDENT
)

set(sgc_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${sgc_directory}")
set(SGC_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${SGC_DIRECTORY}")

install(
FILES "${PROJECT_BINARY_DIR}/sgc-config-version.cmake"
DESTINATION "${sgc_install_cmakedir}"
DESTINATION "${SGC_INSTALL_CMAKEDIR}"
COMPONENT sgc_Development
)

install(
EXPORT sgcTargets
FILE sgc-config.cmake
NAMESPACE sgc::
DESTINATION "${sgc_install_cmakedir}"
DESTINATION "${SGC_INSTALL_CMAKEDIR}"
COMPONENT sgc_Development
)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
include(CPack)
include(CPack)
endif()
69 changes: 41 additions & 28 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,59 @@ enable_testing()

# ---- Dependencies ----

set(
sgc_INCLUDE_WITHOUT_SYSTEM
YES
CACHE
INTERNAL
"Turn the warning guard off to have errors appear in test builds"
)

include(FetchContent)
FetchContent_Declare(sgc SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
FetchContent_MakeAvailable(sgc)
fetchcontent_declare(sgc SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
fetchcontent_makeavailable(sgc)

if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(sgc INTERFACE -Wall -Wextra)
target_compile_options(sgc INTERFACE -Wall -Wextra)
endif()

# ---- Dependencies ----

include(FetchContent)
FetchContent_Declare(
unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity
GIT_TAG origin/master
GIT_SHALLOW TRUE)
fetchcontent_declare(
UNITY
GIT_REPOSITORY https://github.com/red0124/Unity
GIT_TAG origin/master
GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(unity)
set(unity "${FETCHCONTENT_BASE_DIR}/unity-src")
fetchcontent_makeavailable(UNITY)
set(UNITY "${FETCHCONTENT_BASE_DIR}/unity-src")

# ---- Test ----

enable_testing()

foreach(name IN ITEMS test_algorithm test_deque test_forward_list test_list
test_map test_priority_queue test_queue test_set test_stack
test_fs_deque test_fs_priority_queue test_fs_queue
test_fs_stack test_fs_unordered_map test_fs_unordered_set
test_fs_vector test_string test_unordered_map test_unordered_set
test_vector test_utils)
add_executable("${name}" "${name}.c")
target_link_libraries("${name}" PRIVATE sgc::sgc unity)
target_compile_definitions("${name}" PRIVATE CMAKE_GITHUB_CI)
add_test("${name}" "${name}" "./${name}")
foreach(
name
IN
ITEMS
test_algorithm
test_deque
test_forward_list
test_list
test_map
test_priority_queue
test_queue
test_set
test_stack
test_fs_deque
test_fs_priority_queue
test_fs_queue
test_fs_stack
test_fs_unordered_map
test_fs_unordered_set
test_fs_vector
test_string
test_unordered_map
test_unordered_set
test_vector
test_utils
)
add_executable("${name}" "${name}.c")
target_link_libraries("${name}" PRIVATE sgc::sgc unity)
target_compile_definitions("${name}" PRIVATE CMAKE_GITHUB_CI)
add_test("${name}" "${name}" "./${name}")
endforeach()

0 comments on commit e6a9a3b

Please sign in to comment.