Skip to content

Commit 6da5579

Browse files
committed
Add pkg-config support to cmake
pkg-config pc file is essential for distributions. It was provided by autotools based builds but never supported properly by cmake builds.
1 parent e7d46b0 commit 6da5579

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

CMakeLists.txt

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@
161161
#
162162
# - Test on as many different hardware / OS platforms as possible.
163163
#
164-
# - Configure and install systemc.pc and tlm.pc for pkg-config
165-
#
166164
###############################################################################
167165

168166
cmake_minimum_required (VERSION 3.5...3.31)
@@ -698,3 +696,60 @@ install(FILES "${PROJECT_BINARY_DIR}/SystemCTLMConfig.cmake"
698696
"${PROJECT_BINARY_DIR}/SystemCTLMConfigVersion.cmake"
699697
DESTINATION "${SystemCTLM_INSTALL_CMAKEDIR}"
700698
COMPONENT dev)
699+
700+
###############################################################################
701+
# Configure and install systemc.pc and tlm.pc for pkg-config
702+
###############################################################################
703+
704+
# pkg-config template substitution
705+
set(prefix "${CMAKE_INSTALL_PREFIX}")
706+
set(exec_prefix "\${prefix}")
707+
if(INSTALL_TO_LIB_TARGET_ARCH_DIR)
708+
set(LIB_ARCH_SUFFIX "-${SystemC_TARGET_ARCH}")
709+
else()
710+
set(LIB_ARCH_SUFFIX "")
711+
endif()
712+
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
713+
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
714+
715+
# SystemC pkg-config variables
716+
set(TARGET_ARCH "${SystemC_TARGET_ARCH}")
717+
set(PACKAGE_NAME "SystemC")
718+
set(PACKAGE_VERSION "${SystemCLanguage_VERSION}")
719+
set(PACKAGE_URL "https://www.accellera.org/downloads/standards/systemc")
720+
set(PACKAGE "systemc")
721+
722+
# TLM pkg-config variables
723+
set(TLM_PACKAGE_VERSION "${SystemCTLM_VERSION}")
724+
725+
# Set compilation and linking flags for SystemC
726+
set(PKGCONFIG_CFLAGS "")
727+
set(PKGCONFIG_DEFINES "")
728+
set(PKGCONFIG_LDPRIV "")
729+
730+
if(ENABLE_PTHREADS)
731+
get_target_property(pthread_cflags Threads::Threads INTERFACE_COMPILE_OPTIONS)
732+
if(pthread_cflags)
733+
set(PKGCONFIG_CFLAGS ${PKGCONFIG_CFLAGS} ${pthread_cflags})
734+
endif()
735+
get_target_property(pthread_lib Threads::Threads INTERFACE_LINK_LIBRARIES)
736+
if(pthread_lib)
737+
set(PKGCONFIG_LDPRIV ${PKGCONFIG_LDPRIV} ${pthread_lib})
738+
endif()
739+
endif()
740+
741+
# Configure systemc.pc
742+
configure_file("${PROJECT_SOURCE_DIR}/src/systemc.pc.in"
743+
"${PROJECT_BINARY_DIR}/systemc.pc"
744+
@ONLY)
745+
746+
# Configure tlm.pc
747+
configure_file("${PROJECT_SOURCE_DIR}/src/tlm.pc.in"
748+
"${PROJECT_BINARY_DIR}/tlm.pc"
749+
@ONLY)
750+
751+
# Install pkg-config files
752+
install(FILES "${PROJECT_BINARY_DIR}/systemc.pc"
753+
"${PROJECT_BINARY_DIR}/tlm.pc"
754+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
755+
COMPONENT dev)

0 commit comments

Comments
 (0)