Skip to content

Commit f16b6ed

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 f16b6ed

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

CMakeLists.txt

Lines changed: 53 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,56 @@ 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+
if(THREADS_HAVE_PTHREAD_ARG)
732+
set(PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS} -pthread")
733+
set(PKGCONFIG_LDPRIV "${PKGCONFIG_LDPRIV} -pthread")
734+
endif()
735+
endif()
736+
737+
# Configure systemc.pc
738+
configure_file("${PROJECT_SOURCE_DIR}/src/systemc.pc.in"
739+
"${PROJECT_BINARY_DIR}/systemc.pc"
740+
@ONLY)
741+
742+
# Configure tlm.pc
743+
configure_file("${PROJECT_SOURCE_DIR}/src/tlm.pc.in"
744+
"${PROJECT_BINARY_DIR}/tlm.pc"
745+
@ONLY)
746+
747+
# Install pkg-config files
748+
install(FILES "${PROJECT_BINARY_DIR}/systemc.pc"
749+
"${PROJECT_BINARY_DIR}/tlm.pc"
750+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
751+
COMPONENT dev)

0 commit comments

Comments
 (0)