209 lines
7.4 KiB
CMake
209 lines
7.4 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
if (WIN32)
|
|
set(CPACK_GENERATOR "ZIP")
|
|
else()
|
|
set(CPACK_GENERATOR "TGZ")
|
|
endif()
|
|
set(CPACK_VERBATIM_VARIABLES YES)
|
|
include(CPack)
|
|
|
|
function(json_get_list OUT_VAR INPUT_JSON VARIABLE)
|
|
string(JSON LIST_JSON_ELEMENTS ERROR_VARIABLE ${VARIABLE} GET ${INPUT_JSON} ${VARIABLE})
|
|
if (${LIST_JSON_ELEMENTS} EQUAL ${VARIABLE}-NOTFOUND)
|
|
set("${OUT_VAR}" PARENT_SCOPE)
|
|
retrun()
|
|
endif()
|
|
#message("LIST_JSON_ELEMENTS : ${LIST_JSON_ELEMENTS}")
|
|
|
|
string(JSON LENGTH_VALUE LENGTH ${LIST_JSON_ELEMENTS})
|
|
#message("LENGTH_VALUE : ${LENGTH_VALUE}")
|
|
if (${LENGTH_VALUE} EQUAL 0)
|
|
set("${OUT_VAR}" PARENT_SCOPE)
|
|
retrun()
|
|
endif()
|
|
set(OUT_LIST)
|
|
MATH(EXPR LENGTH_VALUE "${LENGTH_VALUE}-1")
|
|
foreach(IDX RANGE ${LENGTH_VALUE})
|
|
string(JSON ELEM GET ${LIST_JSON_ELEMENTS} ${IDX})
|
|
#message(" - : ${ELEM}")
|
|
list(APPEND OUT_LIST ${ELEM})
|
|
endforeach()
|
|
#message("OUT_LIST : ${OUT_LIST}")
|
|
set("${OUT_VAR}" ${OUT_LIST} PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
|
|
|
|
function(json_get_element OUT_VAR INPUT_JSON VARIABLE)
|
|
string(JSON ELEMENT ERROR_VARIABLE ${VARIABLE} GET ${INPUT_JSON} ${VARIABLE})
|
|
if (${ELEMENT} EQUAL ${VARIABLE}-NOTFOUND)
|
|
set("${OUT_VAR}" PARENT_SCOPE)
|
|
retrun()
|
|
endif()
|
|
set("${OUT_VAR}" ${ELEMENT} PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
|
|
|
|
# add the executable
|
|
# add_executable(Tutorial tutorial.cxx)
|
|
|
|
set(LIBRARY_NAME "elog")
|
|
set_property(
|
|
DIRECTORY
|
|
APPEND
|
|
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/GLD_${LIBRARY_NAME}.json
|
|
)
|
|
# Read the JSON file.
|
|
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/GLD_${LIBRARY_NAME}.json MY_JSON_STRING)
|
|
|
|
# Loop through each element of the JSON array (indices 0 though 1).
|
|
|
|
json_get_element(LIBRARY_TYPE ${MY_JSON_STRING} "type")
|
|
json_get_element(LIBRARY_GROUP_ID ${MY_JSON_STRING} "group-id")
|
|
json_get_element(LIBRARY_DECRIPTION ${MY_JSON_STRING} "description")
|
|
json_get_element(LIBRARY_LICENCE ${MY_JSON_STRING} "licence")
|
|
json_get_element(LIBRARY_LICENCE_FILE ${MY_JSON_STRING} "licence-file")
|
|
json_get_element(LIBRARY_MAINTAINER ${MY_JSON_STRING} "maintainer")
|
|
json_get_element(LIBRARY_AUTHORS ${MY_JSON_STRING} "authors")
|
|
json_get_element(LIBRARY_VERSION ${MY_JSON_STRING} "version")
|
|
json_get_element(LIBRARY_SOURCES ${MY_JSON_STRING} "sources")
|
|
json_get_element(LIBRARY_HEADERS ${MY_JSON_STRING} "headers")
|
|
json_get_list(LIBRARY_PATH ${MY_JSON_STRING} "path")
|
|
json_get_element(LIBRARY_COMPILATION_VERSION ${MY_JSON_STRING} "compilation-version")
|
|
json_get_list(LIBRARY_DEPENDENCY ${MY_JSON_STRING} "dependency")
|
|
json_get_element(LIBRARY_PLATFORM ${MY_JSON_STRING} "platform")
|
|
|
|
json_get_element(LIBRARY_COMPILATION_VERSION_LANGUAGE ${MY_JSON_STRING} "language")
|
|
json_get_element(LIBRARY_COMPILATION_VERSION_VALUE ${MY_JSON_STRING} "version")
|
|
|
|
message("LIBRARY_NAME : ${LIBRARY_NAME}")
|
|
message("LIBRARY_TYPE : ${LIBRARY_TYPE}")
|
|
message("LIBRARY_GROUP_ID : ${LIBRARY_GROUP_ID}")
|
|
message("LIBRARY_DECRIPTION : ${LIBRARY_DECRIPTION}")
|
|
message("LIBRARY_LICENCE : ${LIBRARY_LICENCE}")
|
|
message("LIBRARY_LICENCE_FILE : ${LIBRARY_LICENCE_FILE}")
|
|
message("LIBRARY_MAINTAINER : ${LIBRARY_MAINTAINER}")
|
|
message("LIBRARY_AUTHORS : ${LIBRARY_AUTHORS}")
|
|
message("LIBRARY_VERSION : ${LIBRARY_VERSION}")
|
|
message("LIBRARY_COMPILATION_VERSION : ${LIBRARY_COMPILATION_VERSION_LANGUAGE} : ${LIBRARY_COMPILATION_VERSION_VALUE}")
|
|
|
|
#message("LIBRARY_SOURCES: ${LIBRARY_SOURCES}")
|
|
#message("LIBRARY_HEADERS: ${LIBRARY_HEADERS}")
|
|
message("LIBRARY_PATH: ${LIBRARY_PATH}")
|
|
#message("LIBRARY_COMPILATION_VERSION: ${LIBRARY_COMPILATION_VERSION}")
|
|
message("LIBRARY_DEPENDENCY: ${LIBRARY_DEPENDENCY}")
|
|
#message("LIBRARY_PLATFORM: ${LIBRARY_PLATFORM}")
|
|
|
|
|
|
json_get_list(SOURCES_LIST ${LIBRARY_SOURCES} "list")
|
|
message("SOURCES_LIST: ${SOURCES_LIST}")
|
|
|
|
json_get_list(EXPORT_HEADER_LIST ${LIBRARY_HEADERS} "list")
|
|
json_get_element(EXPORT_HEADER_LIST_PATH ${LIBRARY_HEADERS} "destination-path")
|
|
message("EXPORT_HEADER_LIST: ${EXPORT_HEADER_LIST}")
|
|
message("EXPORT_HEADER_LIST_PATH: ${EXPORT_HEADER_LIST_PATH}")
|
|
|
|
|
|
|
|
string(JSON LIBRARY_PLOP ERROR_VARIABLE "qsdfqsdfqsdf" GET ${MY_JSON_STRING} "qsdfqsdfqsdf")
|
|
#string(JSON LIBRARY_MEMBERS MEMBER ${MY_JSON_STRING} )
|
|
#message("LIBRARY_MEMBERS : ${LIBRARY_MEMBERS}")
|
|
message("LIBRARY_PLOP : ${LIBRARY_PLOP}")
|
|
|
|
string(REPLACE "-" "_" LIBRARY_NAME222 ${LIBRARY_NAME})
|
|
set(LIBRARY_NAME222 ${LIBRARY_NAME})
|
|
project(${LIBRARY_NAME222} VERSION ${LIBRARY_VERSION})
|
|
set(${LIBRARY_NAME222} PROPERTIES CPACK_PACKAGE_VERSION ${LIBRARY_VERSION})
|
|
add_library(${LIBRARY_NAME222}_OBJ OBJECT ${SOURCES_LIST})
|
|
# shared libraries need PIC
|
|
set_property(TARGET ${LIBRARY_NAME222}_OBJ PROPERTY POSITION_INDEPENDENT_CODE 1)
|
|
|
|
|
|
#set_target_properties(${LIBRARY_NAME222} PROPERTIES PUBLIC_HEADER ${EXPORT_HEADER_LIST})
|
|
target_include_directories(${LIBRARY_NAME222}_OBJ PUBLIC
|
|
${LIBRARY_PATH}
|
|
)
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "/home/heero/dev/perso/framework/atria-soft/generated_package/etk-core-1.5.3-/cmake/etk-core/")
|
|
|
|
find_package("etk-core" REQUIRED)
|
|
|
|
|
|
add_library(${LIBRARY_NAME222}_dynamic SHARED $<TARGET_OBJECTS:${LIBRARY_NAME222}_OBJ>)
|
|
add_library(${LIBRARY_NAME222}_static STATIC $<TARGET_OBJECTS:${LIBRARY_NAME222}_OBJ>)
|
|
|
|
set_target_properties(${LIBRARY_NAME222}_dynamic PROPERTIES OUTPUT_NAME ${LIBRARY_NAME222})
|
|
if (NOT WIN32)
|
|
set_target_properties(${LIBRARY_NAME222}_static PROPERTIES OUTPUT_NAME ${LIBRARY_NAME222})
|
|
endif()
|
|
|
|
|
|
|
|
set_target_properties(${LIBRARY_NAME222}_dynamic PROPERTIES VERSION ${LIBRARY_VERSION})
|
|
set_target_properties(${LIBRARY_NAME222}_dynamic PROPERTIES SOVERSION ${LIBRARY_VERSION})
|
|
set_target_properties(${LIBRARY_NAME222}_dynamic PROPERTIES DESCRIPTION ${LIBRARY_DECRIPTION})
|
|
|
|
# install dynamic & static library
|
|
install(TARGETS ${LIBRARY_NAME222}_dynamic EXPORT ${LIBRARY_NAME222}Targets
|
|
RUNTIME DESTINATION lib
|
|
)
|
|
install(TARGETS ${LIBRARY_NAME222}_static
|
|
RUNTIME DESTINATION lib)
|
|
|
|
|
|
#install(TARGETS ${LIBRARY_NAME222} EXPORT ${LIBRARY_NAME222}Targets
|
|
# LIBRARY DESTINATION lib
|
|
# ARCHIVE DESTINATION lib
|
|
# RUNTIME DESTINATION bin
|
|
# INCLUDES DESTINATION include
|
|
#)
|
|
# install exported headers
|
|
# this copy all the headers in a single folder:
|
|
#install(FILES ${EXPORT_HEADER_LIST} DESTINATION include)
|
|
# this keep the basic path for each folders:
|
|
set(BASE "${PROJECT_SOURCE_DIR}/install")
|
|
foreach(ITEM ${EXPORT_HEADER_LIST})
|
|
get_filename_component(ITEM_PATH ${ITEM} PATH)
|
|
string(REPLACE ${BASE} "" ITEM_PATH ${ITEM_PATH})
|
|
install(FILES ${ITEM}
|
|
DESTINATION "include/${ITEM_PATH}"
|
|
COMPONENT Devel)
|
|
endforeach()
|
|
|
|
|
|
|
|
#include(CMakePackageConfigHelpers)
|
|
#set(CONFIG_PACKAGE_LOCATION cmake/${LIBRARY_NAME222})
|
|
#install(EXPORT ${LIBRARY_NAME222}Targets
|
|
# FILE
|
|
# ${LIBRARY_NAME222}Targets.cmake
|
|
# NAMESPACE
|
|
# ${LIBRARY_NAME222}::
|
|
# DESTINATION
|
|
# ${CONFIG_PACKAGE_LOCATION}
|
|
#)
|
|
#message("CMAKE_INSTALL_LIBDIR===${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
#include(CMakePackageConfigHelpers)
|
|
#configure_package_config_file(cmake/${LIBRARY_NAME222}Config.cmake.in
|
|
# "${PROJECT_BINARY_DIR}/${LIBRARY_NAME222}Config.cmake"
|
|
# INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION}
|
|
# NO_SET_AND_CHECK_MACRO
|
|
# NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
|
#write_basic_package_version_file(
|
|
# "${PROJECT_BINARY_DIR}/${LIBRARY_NAME222}ConfigVersion.cmake"
|
|
# VERSION ${LIBRARY_VERSION}
|
|
# COMPATIBILITY SameMajorVersion)
|
|
#install(
|
|
# FILES
|
|
# "${PROJECT_BINARY_DIR}/${LIBRARY_NAME222}Config.cmake"
|
|
# "${PROJECT_BINARY_DIR}/${LIBRARY_NAME222}ConfigVersion.cmake"
|
|
# DESTINATION ${CONFIG_PACKAGE_LOCATION}
|
|
# COMPONENT Devel)
|
|
|
|
|
|
|
|
|