Browse Source

cleaned up the build system and introduced new targets

master 0.0.2
Arwed Mett 3 years ago
parent
commit
fc4f5a27e3
  1. 48
      CMakeLists.txt
  2. 4
      README.md
  3. 2
      cmake/LoggingConfig.cmake
  4. 2
      cmake/loggingConfig.cmake

48
CMakeLists.txt

@ -1,35 +1,31 @@
cmake_minimum_required(VERSION 3.5)
project(logging.h LANGUAGES C)
project(logging LANGUAGES C)
message(STATUS ${CMAKE_SYSTEM_NAME})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
include(require-git)
#Targets
add_library(Logging OBJECT src/logging.c)
target_include_directories(Logging PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_property(TARGET Logging PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(shared SHARED $<TARGET_OBJECTS:Logging>)
target_include_directories(shared PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
)
add_library(static STATIC $<TARGET_OBJECTS:Logging>)
target_include_directories(static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
set(SRCS src/logging.c)
add_library(logging-headers INTERFACE)
target_include_directories(logging-headers INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
add_library(logging-shared SHARED ${SRCS})
target_link_libraries(logging-shared PUBLIC logging-headers)
add_library(logging-static STATIC ${SRCS})
target_link_libraries(logging-static PUBLIC logging-headers)
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
add_executable(example example/main.c)
target_link_libraries(example shared)
target_link_libraries(example PRIVATE logging-shared)
endif()
#Install
install(TARGETS static shared EXPORT LoggingTargets
install(TARGETS logging-headers logging-static logging-shared EXPORT loggingTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
@ -37,24 +33,24 @@ install(TARGETS static shared EXPORT LoggingTargets
)
install(DIRECTORY include/logging DESTINATION include)
install(EXPORT LoggingTargets
FILE LoggingTargets.cmake
NAMESPACE Logging::
DESTINATION lib/cmake/Logging
install(EXPORT loggingTargets
FILE loggingTargets.cmake
NAMESPACE logging::
DESTINATION lib/cmake/logging
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file("LoggingConfigVersion.cmake"
VERSION ${Logging_VERSION}
write_basic_package_version_file("loggingConfigVersion.cmake"
VERSION ${logging_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
FILES
"cmake/LoggingConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/LoggingConfigVersion.cmake"
"cmake/loggingConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/loggingConfigVersion.cmake"
DESTINATION
lib/cmake/Logging
lib/cmake/logging
)
include(pack)

4
README.md

@ -36,6 +36,6 @@ cmake --build . --target install
You can use logging.h with cmake as follows. Thereby replace `<target>` with your target.
```cmake
find_package(Logging REQUIRED)
target_link_libraries(<target> PRIVATE Logging::static)
find_package(logging 0.0.2 EXACT REQUIRED)
target_link_libraries(<target> PRIVATE logging::logging-static)
```

2
cmake/LoggingConfig.cmake

@ -1,2 +0,0 @@
include(CMakeFindDependencyMacro)
include("${CMAKE_CURRENT_LIST_DIR}/LoggingTargets.cmake")

2
cmake/loggingConfig.cmake

@ -0,0 +1,2 @@
include(CMakeFindDependencyMacro)
include("${CMAKE_CURRENT_LIST_DIR}/loggingTargets.cmake")
Loading…
Cancel
Save