Skip to content

Add pkg-config support to cmake #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@
#
# - Test on as many different hardware / OS platforms as possible.
#
# - Configure and install systemc.pc and tlm.pc for pkg-config
#
###############################################################################

cmake_minimum_required (VERSION 3.5...3.31)
Expand Down Expand Up @@ -698,3 +696,60 @@ install(FILES "${PROJECT_BINARY_DIR}/SystemCTLMConfig.cmake"
"${PROJECT_BINARY_DIR}/SystemCTLMConfigVersion.cmake"
DESTINATION "${SystemCTLM_INSTALL_CMAKEDIR}"
COMPONENT dev)

###############################################################################
# Configure and install systemc.pc and tlm.pc for pkg-config
###############################################################################

# pkg-config template substitution
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "\${prefix}")
if(INSTALL_TO_LIB_TARGET_ARCH_DIR)
set(LIB_ARCH_SUFFIX "-${SystemC_TARGET_ARCH}")
else()
set(LIB_ARCH_SUFFIX "")
endif()
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")

# SystemC pkg-config variables
set(TARGET_ARCH "${SystemC_TARGET_ARCH}")
set(PACKAGE_NAME "SystemC")
set(PACKAGE_VERSION "${SystemCLanguage_VERSION}")
set(PACKAGE_URL "https://www.accellera.org/downloads/standards/systemc")
set(PACKAGE "systemc")

# TLM pkg-config variables
set(TLM_PACKAGE_VERSION "${SystemCTLM_VERSION}")

# Set compilation and linking flags for SystemC
set(PKGCONFIG_CFLAGS "")
set(PKGCONFIG_DEFINES "")
set(PKGCONFIG_LDPRIV "")

if(ENABLE_PTHREADS)
get_target_property(pthread_cflags Threads::Threads INTERFACE_COMPILE_OPTIONS)
if(pthread_cflags)
set(PKGCONFIG_CFLAGS ${PKGCONFIG_CFLAGS} ${pthread_cflags})
endif()
get_target_property(pthread_lib Threads::Threads INTERFACE_LINK_LIBRARIES)
if(pthread_lib)
set(PKGCONFIG_LDPRIV ${PKGCONFIG_LDPRIV} ${pthread_lib})
endif()
endif()
Comment on lines +725 to +739
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to query the target properties directly on the SystemC::systemc library to set PKGCONFIG_CFLAGS, PKGCONFIG_DEFINES, and PKGCONFIG_LDPRIV. This should ensure consistency in all cases. It should also take care on the potential transitive dependency on Pthreads.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I attempted to implement that and found it is not possible as SystemC::systemc contains expressions that are only evaluated at GENERATE phase while configuration is done at an earlier phase.

I checked other projects, and it seems like they are all hard-coding flags.


# Configure systemc.pc
configure_file("${PROJECT_SOURCE_DIR}/src/systemc.pc.in"
"${PROJECT_BINARY_DIR}/systemc.pc"
@ONLY)

# Configure tlm.pc
configure_file("${PROJECT_SOURCE_DIR}/src/tlm.pc.in"
"${PROJECT_BINARY_DIR}/tlm.pc"
@ONLY)

# Install pkg-config files
install(FILES "${PROJECT_BINARY_DIR}/systemc.pc"
"${PROJECT_BINARY_DIR}/tlm.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
COMPONENT dev)