Skip to content

Commit dc945f9

Browse files
committed
Add LTC_PTHREAD to pkg-config file if enabled at build time
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 2400883 commit dc945f9

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

CMakeLists.txt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ option(WITH_TFM "Build with support for tomsfastmath" FALSE)
4040
option(WITH_GMP "Build with support for GNU Multi Precision Arithmetic Library" FALSE)
4141
set(MPI_PROVIDER "LTM" CACHE STRING "Build tests and demos against 'LTM', 'TFM' or 'GMP', default is LTM")
4242
option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF)
43+
option(WITH_PTHREAD "Build with pthread support" FALSE)
4344

4445
#-----------------------------------------------------------------------------
4546
# Add support for ccache if desired
@@ -164,8 +165,8 @@ if(WITH_LTM)
164165
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LTM)
165166
endif()
166167
target_link_libraries(${PROJECT_NAME} PUBLIC libtommath)
167-
list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DLTM_DESC)
168-
list(APPEND LTC_MPI_PROVIDERS_LIBS -ltommath)
168+
list(APPEND LTC_PKG_CONFIG_CFLAGS -DLTM_DESC)
169+
list(APPEND LTC_PKG_CONFIG_LIBS -ltommath)
169170
list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libtommath-dev)
170171
endif()
171172
# tomsfastmath
@@ -177,8 +178,8 @@ if(WITH_TFM)
177178
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_TFM)
178179
endif()
179180
target_link_libraries(${PROJECT_NAME} PUBLIC tomsfastmath)
180-
list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DTFM_DESC)
181-
list(APPEND LTC_MPI_PROVIDERS_LIBS -ltfm)
181+
list(APPEND LTC_PKG_CONFIG_CFLAGS -DTFM_DESC)
182+
list(APPEND LTC_PKG_CONFIG_LIBS -ltfm)
182183
list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libtfm-dev)
183184
endif()
184185
# GNU MP
@@ -190,13 +191,30 @@ if(WITH_GMP)
190191
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_GMP)
191192
endif()
192193
target_link_libraries(${PROJECT_NAME} PUBLIC ${GMP_LIBRARIES})
193-
list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DGMP_DESC)
194-
list(APPEND LTC_MPI_PROVIDERS_LIBS -lgmp)
194+
list(APPEND LTC_PKG_CONFIG_CFLAGS -DGMP_DESC)
195+
list(APPEND LTC_PKG_CONFIG_LIBS -lgmp)
195196
list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libgmp-dev)
196197
endif()
197198

198-
list(JOIN LTC_MPI_PROVIDERS_CFLAGS " " MPI_PROVIDERS_CFLAGS)
199-
list(JOIN LTC_MPI_PROVIDERS_LIBS " " MPI_PROVIDERS_LIBS)
199+
200+
#-----------------------------------------------------------------------------
201+
# other options
202+
#-----------------------------------------------------------------------------
203+
204+
if(WITH_PTHREAD)
205+
set(THREADS_PREFER_PTHREAD_FLAG ON)
206+
find_package(Threads REQUIRED)
207+
if(CMAKE_USE_PTHREADS_INIT)
208+
target_compile_definitions(${PROJECT_NAME} PUBLIC LTC_PTHREAD)
209+
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
210+
list(APPEND LTC_PKG_CONFIG_CFLAGS -DLTC_PTHREAD)
211+
else()
212+
message(SEND_ERROR "pthreads not supported. Reconfigure ${PROJECT_NAME} with -DWITH_PTHREAD=OFF.")
213+
endif()
214+
endif()
215+
216+
list(JOIN LTC_PKG_CONFIG_CFLAGS " " PKG_CONFIG_CFLAGS)
217+
list(JOIN LTC_PKG_CONFIG_LIBS " " PKG_CONFIG_LIBS)
200218
list(JOIN LTC_DEBIAN_MPI_PROVIDER_DEPENDS " " DEBIAN_MPI_PROVIDER_DEPENDS)
201219

202220
#-----------------------------------------------------------------------------

libtomcrypt.pc.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@
55
Name: LibTomCrypt
66
Description: public domain open source cryptographic toolkit
77
Version: @PROJECT_VERSION@
8-
Libs: -L${libdir} -ltomcrypt @MPI_PROVIDERS_LIBS@
9-
Cflags: -I${includedir} @MPI_PROVIDERS_CFLAGS@
8+
Libs: -L${libdir} -ltomcrypt @PKG_CONFIG_LIBS@
9+
Cflags: -I${includedir} @PKG_CONFIG_CFLAGS@

makefile.shared

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,24 @@ endif
5555
include makefile_include.mk
5656

5757
ifneq ($(findstring -DLTM_DESC,$(LTC_CFLAGS)),)
58-
LTC_MPI_PROVIDERS_CFLAGS += -DLTM_DESC
59-
LTC_MPI_PROVIDERS_LIBS += -ltommath
58+
LTC_PKG_CONFIG_CFLAGS += -DLTM_DESC
59+
LTC_PKG_CONFIG_LIBS += -ltommath
6060
endif
6161
ifneq ($(findstring -DTFM_DESC,$(LTC_CFLAGS)),)
62-
LTC_MPI_PROVIDERS_CFLAGS += -DTFM_DESC
63-
LTC_MPI_PROVIDERS_LIBS += -ltfm
62+
LTC_PKG_CONFIG_CFLAGS += -DTFM_DESC
63+
LTC_PKG_CONFIG_LIBS += -ltfm
6464
endif
6565
ifneq ($(findstring -DGMP_DESC,$(LTC_CFLAGS)),)
66-
LTC_MPI_PROVIDERS_CFLAGS += -DGMP_DESC
67-
LTC_MPI_PROVIDERS_LIBS += -lgmp
66+
LTC_PKG_CONFIG_CFLAGS += -DGMP_DESC
67+
LTC_PKG_CONFIG_LIBS += -lgmp
6868
endif
69+
ifneq ($(findstring -DLTC_PTHREAD,$(LTC_CFLAGS)),)
70+
LTC_PKG_CONFIG_CFLAGS += -DLTC_PTHREAD
71+
endif
72+
73+
# set PKG_CONFIG_CFLAGS and PKG_CONFIG_LIBS to what your environment requires
74+
LTC_PKG_CONFIG_CFLAGS += $(PKG_CONFIG_CFLAGS)
75+
LTC_PKG_CONFIG_LIBS += $(PKG_CONFIG_LIBS)
6976

7077
#ciphers come in two flavours... enc+dec and enc
7178
src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
@@ -95,8 +102,8 @@ $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
95102
install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
96103
sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,^libdir=.*,libdir=$(LIBPATH),' \
97104
-e 's,^includedir=.*,includedir=$(INCPATH),' \
98-
-e 's,@MPI_PROVIDERS_LIBS@,$(LTC_MPI_PROVIDERS_LIBS),' \
99-
-e 's,@MPI_PROVIDERS_CFLAGS@,$(LTC_MPI_PROVIDERS_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc
105+
-e 's,@PKG_CONFIG_LIBS@,$(LTC_PKG_CONFIG_LIBS),' \
106+
-e 's,@PKG_CONFIG_CFLAGS@,$(LTC_PKG_CONFIG_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc
100107
install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
101108
install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
102109

0 commit comments

Comments
 (0)