11cmake_minimum_required (VERSION  3.30)
22
33set (prev_name mysvac)                          
4- set (lib_name json)                     
5- set (package_name "mysvac-jsonlib" )
6- 
7- set (CMAKE_CXX_STANDARD 20)
8- set (CMAKE_CXX_STANDARD_REQUIRED ON )
9- 
10- if (MYSVAC_JSONLIB_ENABLE_TEST)
11-     set (CMAKE_CXX_STANDARD 23)
12- endif  ()
4+ set (lib_name jsonlib)
5+ set (package_name "${prev_name} -${lib_name} " )
136
147# Project declaration with metadata 
158project (${package_name} 
@@ -27,68 +20,40 @@ file(GLOB_RECURSE cxx_header_files "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
2720
2821# Library target creation 
2922# Create the main library target that can be built as either static or shared 
30- add_library (${lib_name} )
23+ add_library (${lib_name}   INTERFACE )
3124# Create an alias target for namespaced usage 
3225add_library (${prev_name} ::${lib_name}  ALIAS ${lib_name} )
3326
34- # Default use unordered_map 
35- # If you want to use std::map instead, define M_MYSVAC_JSON_ORDERED_MAP 
36- # target_compile_definitions(${lib_name} PUBLIC 
37- #     M_MYSVAC_JSON_UNORDERED_MAP=1    # Define to use std::unordered_map for JSON objects 
38- # ) 
39- 
4027# Library properties configuration 
4128set_target_properties (${lib_name}  PROPERTIES
42-     # CXX_MODULE_STD ON                                 # Enable C++23 standard library modules 
4329    OUTPUT_NAME  ${package_name}                        # Set the output file name 
4430)
45- # Source files configuration 
46- # Add C++23 module files as PUBLIC sources (exported for consumers) 
47- target_sources (${lib_name}  PUBLIC 
48-         FILE_SET cxx_modules                          # Define a file set for modules 
49-         TYPE  CXX_MODULES                              # Specify this is a C++ modules file set 
50-         BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} /modules # Base directory for module resolution 
51-         FILES  ${cxx_module_files}                      # List of module files to include 
52- )
5331# Add header files as INTERFACE sources (header-only, not compiled) 
5432target_sources (${lib_name}  INTERFACE 
55-     FILE_SET cxx_headers                              # Define a file set for headers 
56-     TYPE  HEADERS                                      # Specify this is a headers file set 
57-     BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} /include     # Base directory for header resolution 
58-     FILES  ${cxx_header_files}                         # List of header files to include 
33+     FILE_SET mysvac_json_cxx_headers                 # Define a file set for headers 
34+     TYPE  HEADERS                                     # Specify this is a headers file set 
35+     BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} /include 
36+     FILES  ${cxx_header_files} 
37+     BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} /modules
38+     FILES  ${cxx_module_files} 
5939)
6040# Include directories configuration 
6141# Set up include paths for both build and install configurations 
6242target_include_directories (${lib_name}  INTERFACE 
6343    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >   # Path during build 
6444    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >         # Path after installation 
6545)
66- target_compile_features (${lib_name}  PUBLIC  cxx_std_20)
67- 
68- # Dynamic library configuration (optional) 
69- # Configure additional properties when building as a shared library 
70- if (BUILD_SHARED_LIBS )
71-     set_target_properties (${lib_name}  PROPERTIES
72-         WINDOWS_EXPORT_ALL_SYMBOLS ON                # Export all symbols on Windows (no explicit __declspec needed) 
73-         VERSION  ${PROJECT_VERSION}                   # Set the library version (used for .so.x.y.z on Linux) 
74-         SOVERSION  ${PROJECT_VERSION_MAJOR}           # Set the ABI version (used for .so.x on Linux) 
75-     )
76- endif ()
7746
7847# Installation configuration 
7948# Include standard CMake modules for installation and packaging 
8049include (GNUInstallDirs)                             # Provides standard installation directory variables 
8150include (CMakePackageConfigHelpers)                  # Provides functions for creating config files 
8251
83- 
8452# Target installation 
8553# Install the library target and its associated file sets 
8654install (TARGETS ${lib_name} 
8755    EXPORT  ${package_name} -targets                   # Export target for find_package() support 
88-     FILE_SET cxx_modules
89-         DESTINATION  ${CMAKE_INSTALL_INCLUDEDIR}      # Install modules to include directory 
90-                                                     # Note: vct prefix is already included in module paths 
91-     FILE_SET cxx_headers
56+     FILE_SET mysvac_json_cxx_headers
9257        DESTINATION  ${CMAKE_INSTALL_INCLUDEDIR}      # Install headers to include directory 
9358                                                    # Note: vct prefix is already included in header paths 
9459)
@@ -112,7 +77,7 @@ configure_package_config_file(
11277write_basic_package_version_file(
11378    ${CMAKE_CURRENT_BINARY_DIR} /${package_name} -config-version .cmake   # Output version file 
11479    VERSION  ${PROJECT_VERSION}                      # Use project version 
115-     COMPATIBILITY ExactVersion                      # Require exact version match (strict compatibility) 
80+     COMPATIBILITY SameMinorVersion                  # Require exact version match (strict compatibility) 
11681)
11782
11883# Install configuration files 
@@ -123,11 +88,30 @@ install(FILES
12388    DESTINATION  ${CMAKE_INSTALL_DATADIR} /${package_name}    # Install to share/${package_name}/ 
12489)
12590
91+ ################### 
92+ # utilities for testing or direct usage 
93+ function (target_link_mysvac_jsonlib target  visibility)
94+     if (NOT  TARGET  ${target} )
95+         message (FATAL_ERROR "Target '${target} ' does not exist!" )
96+     endif ()
97+     # add module target 
98+     target_link_libraries (${target}  ${visibility}  mysvac::jsonlib)
99+     target_sources (${target}  ${visibility} 
100+             FILE_SET mysvac_json_cxx_modules
101+             TYPE  CXX_MODULES
102+             BASE_DIRS ${CMAKE_CURRENT_FUNCTION_LIST_DIR} /modules
103+             FILES  ${cxx_module_files} 
104+     )
105+ endfunction ()
106+ ################### 
107+ 
108+ 
126109# Testing configuration (optional) 
127110# Enable testing support 
128- if (MYSVAC_JSONLIB_ENABLE_TEST )
111+ if (MYSVAC_JSON_ENABLE_TEST )
129112    if (EXISTS  ${CMAKE_CURRENT_SOURCE_DIR} /test /CMakeLists.txt)
130113        enable_testing ()                                # Enable CTest integration 
131114        add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /test )    # Add test subdirectory 
132115    endif ()
133116endif ()
117+ 
0 commit comments