Skip to content

Commit

Permalink
cmake: Changes in the build system
Browse files Browse the repository at this point in the history
Changes in this commit involve removing some existing parts of the main
CMake file and enabling the building of examples from the main CMake.

Signed-off-by: Tomasz Leman <tomasz.leman@outlook.com>
  • Loading branch information
tmleman committed Mar 29, 2024
1 parent a488f8e commit 16e1a60
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 72 deletions.
59 changes: 19 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
cmake_minimum_required(VERSION 3.8)
project(clipp
VERSION 1.2.3
LANGUAGES CXX)

include(GNUInstallDirs)
set(CMAKE_VERBOSE_MAKEFILE ON)

message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

set(CONFIG_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CONFIG_VERSION_FILE} COMPATIBILITY AnyNewerVersion
)

install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-config
)
install(EXPORT ${PROJECT_NAME}-config
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
)
install(FILES ${CONFIG_VERSION_FILE}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
)

option(BUILD_TESTING "Do not build tests by default" OFF)
include(CTest)
if(BUILD_TESTING AND ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
add_subdirectory(test)
VERSION 1.2.3
LANGUAGES CXX)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(include)

add_subdirectory(examples)

enable_testing()
add_subdirectory(test)

18 changes: 0 additions & 18 deletions examples/Makefile

This file was deleted.

31 changes: 17 additions & 14 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Debug)
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options(-stdlib=libc++)
add_compile_options(-stdlib=libc++)
else()
add_compile_options(-Wlogical-op)
add_compile_options(-Wnoexcept)
add_compile_options(-Wstrict-null-sentinel)
add_compile_options(-Wuseless-cast)
add_compile_options(-Wlogical-op)
add_compile_options(-Wnoexcept)
add_compile_options(-Wstrict-null-sentinel)
add_compile_options(-Wuseless-cast)
endif()
add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options(-Wcast-align -Wcast-qual)
Expand All @@ -30,14 +30,17 @@ add_compile_options(-Wstrict-overflow=5)
add_compile_options(-Wswitch-default)
add_compile_options(-Wundef)

add_custom_target(all_tests)

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} source_files)
foreach(src IN LISTS source_files)
get_filename_component(name_we ${src} NAME_WE)
add_executable(test-${name_we} ${src})
target_link_libraries(test-${name_we} ${PROJECT_NAME}::${PROJECT_NAME})
set_target_properties(test-${name_we} PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)
add_test(NAME ${name_we} COMMAND $<TARGET_FILE:test-${name_we}>)
get_filename_component(name_we ${src} NAME_WE)
add_executable(test-${name_we} ${src})
set_target_properties(test-${name_we} PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)
add_test(NAME ${name_we} COMMAND $<TARGET_FILE:test-${name_we}>)
add_dependencies(all_tests test-${name_we})
endforeach()

0 comments on commit 16e1a60

Please sign in to comment.