Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/AddBitcoinABC.cmake
- This file was added.
include(InstallationHelper) | |||||
# Wrapper for the add_library() function. | |||||
function(abc_add_library NAME) | |||||
cmake_parse_arguments(ARG | |||||
"INSTALL;SHARED;STATIC" | |||||
"OUTPUT_NAME" | |||||
"DEFINITIONS;DEPENDS;LINK_LIBS;OBJLIBS;PRIVATE_HEADERS;PUBLIC_HEADERS" | |||||
${ARGN} | |||||
) | |||||
if(ARG_OBJLIBS) | |||||
set(_all_files ${ARG_OBJLIBS}) | |||||
else() | |||||
set(_all_files | |||||
${ARG_UNPARSED_ARGUMENTS} | |||||
${ARG_PRIVATE_HEADERS} | |||||
${ARG_PUBLIC_HEADERS} | |||||
) | |||||
endif() | |||||
# If none of STATIC or SHARED is explicitly set, determine the library type | |||||
# from BUILD_SHARED_LIBS. | |||||
if(BUILD_SHARED_LIBS AND NOT ARG_STATIC) | |||||
set(ARG_SHARED TRUE) | |||||
endif() | |||||
if(NOT ARG_SHARED) | |||||
set(ARG_STATIC TRUE) | |||||
endif() | |||||
# If both static and shared are requested, use an object library. | |||||
if(ARG_SHARED AND ARG_STATIC) | |||||
set(_obj_name "${NAME}-object") | |||||
add_library(${_obj_name} OBJECT EXCLUDE_FROM_ALL ${_all_files}) | |||||
if(ARG_DEPENDS) | |||||
add_dependencies(${_obj_name} ${ARG_DEPENDS}) | |||||
unset(ARG_DEPENDS) | |||||
endif() | |||||
target_link_libraries(${_obj_name} ${ARG_LINK_LIBS}) | |||||
target_compile_definitions(${_obj_name} PRIVATE ${ARG_DEFINITIONS}) | |||||
unset(ARG_DEFINITIONS) | |||||
set(_all_files "$<TARGET_OBJECTS:${_obj_name}>") | |||||
if(ARG_OUTPUT_NAME) | |||||
set(_output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}") | |||||
endif() | |||||
if(ARG_INSTALL) | |||||
set(_install INSTALL) | |||||
endif() | |||||
abc_add_library("${NAME}-shared" SHARED | |||||
${_install} | |||||
OBJLIBS ${_all_files} | |||||
LINK_LIBS ${ARG_LINK_LIBS} | |||||
PRIVATE_HEADERS ${ARG_PRIVATE_HEADERS} | |||||
PUBLIC_HEADERS ${ARG_PUBLIC_HEADERS} | |||||
${_output_name} | |||||
) | |||||
unset(ARG_SHARED) | |||||
endif() | |||||
if(ARG_SHARED) | |||||
add_library(${NAME} SHARED ${_all_files}) | |||||
else() | |||||
add_library(${NAME} STATIC ${_all_files}) | |||||
endif() | |||||
if(ARG_DEPENDS) | |||||
add_dependencies(${NAME} ${ARG_DEPENDS}) | |||||
endif() | |||||
target_link_libraries(${NAME} ${ARG_LINK_LIBS}) | |||||
target_compile_definitions(${NAME} PRIVATE ${ARG_DEFINITIONS}) | |||||
set(_version "${bitcoin-abc_VERSION_MAJOR}") | |||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") | |||||
# FIXME For compatibility reason with autotools, the version is set | |||||
# to 0.0.0 (major being actually 0). This is obviously wrong and the | |||||
# version of the library should reflect the version of the release. | |||||
# On platforms other than linux, only the major version (0) is used. | |||||
# Replace the VERSION line with the statement below to set the | |||||
# correct version: | |||||
# string(APPEND "${bitcoin-abc_VERSION_MINOR}.${bitcoin-abc_VERSION_PATCH})" | |||||
string(APPEND _version ".0.0") | |||||
endif() | |||||
set(_properties VERSION ${_version}) | |||||
if(ARG_OUTPUT_NAME) | |||||
list(APPEND _properties OUTPUT_NAME "${ARG_OUTPUT_NAME}") | |||||
endif() | |||||
if(ARG_SHARED) | |||||
list(APPEND _properties SOVERSION "${bitcoin-abc_VERSION_MAJOR}") | |||||
if(ARG_PRIVATE_HEADERS) | |||||
list(APPEND _properties PRIVATE_HEADER "${ARG_PRIVATE_HEADERS}") | |||||
endif() | |||||
if(ARG_PUBLIC_HEADERS) | |||||
list(APPEND _properties PUBLIC_HEADER "${ARG_PUBLIC_HEADERS}") | |||||
endif() | |||||
endif() | |||||
set_target_properties(${NAME} PROPERTIES ${_properties}) | |||||
if(ARG_INSTALL) | |||||
install_target(${NAME}) | |||||
endif() | |||||
endfunction() | |||||
No newline at end of file |