diff --git a/CMakeLists.txt b/CMakeLists.txt index b28ca0b9..007b234e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ option(WITH_TFM "Build with support for tomsfastmath" FALSE) option(WITH_GMP "Build with support for GNU Multi Precision Arithmetic Library" FALSE) set(MPI_PROVIDER "LTM" CACHE STRING "Build tests and demos against 'LTM', 'TFM' or 'GMP', default is LTM") option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF) +option(WITH_PTHREAD "Build with pthread support" FALSE) #----------------------------------------------------------------------------- # Add support for ccache if desired @@ -164,8 +165,8 @@ if(WITH_LTM) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LTM) endif() target_link_libraries(${PROJECT_NAME} PUBLIC libtommath) - list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DLTM_DESC) - list(APPEND LTC_MPI_PROVIDERS_LIBS -ltommath) + list(APPEND LTC_PKG_CONFIG_CFLAGS -DLTM_DESC) + list(APPEND LTC_PKG_CONFIG_LIBS -ltommath) list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libtommath-dev) endif() # tomsfastmath @@ -177,8 +178,8 @@ if(WITH_TFM) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_TFM) endif() target_link_libraries(${PROJECT_NAME} PUBLIC tomsfastmath) - list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DTFM_DESC) - list(APPEND LTC_MPI_PROVIDERS_LIBS -ltfm) + list(APPEND LTC_PKG_CONFIG_CFLAGS -DTFM_DESC) + list(APPEND LTC_PKG_CONFIG_LIBS -ltfm) list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libtfm-dev) endif() # GNU MP @@ -190,13 +191,30 @@ if(WITH_GMP) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_GMP) endif() target_link_libraries(${PROJECT_NAME} PUBLIC ${GMP_LIBRARIES}) - list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DGMP_DESC) - list(APPEND LTC_MPI_PROVIDERS_LIBS -lgmp) + list(APPEND LTC_PKG_CONFIG_CFLAGS -DGMP_DESC) + list(APPEND LTC_PKG_CONFIG_LIBS -lgmp) list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libgmp-dev) endif() -list(JOIN LTC_MPI_PROVIDERS_CFLAGS " " MPI_PROVIDERS_CFLAGS) -list(JOIN LTC_MPI_PROVIDERS_LIBS " " MPI_PROVIDERS_LIBS) + +#----------------------------------------------------------------------------- +# other options +#----------------------------------------------------------------------------- + +if(WITH_PTHREAD) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + if(CMAKE_USE_PTHREADS_INIT) + target_compile_definitions(${PROJECT_NAME} PUBLIC LTC_PTHREAD) + target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) + list(APPEND LTC_PKG_CONFIG_CFLAGS -DLTC_PTHREAD) + else() + message(SEND_ERROR "pthreads not supported. Reconfigure ${PROJECT_NAME} with -DWITH_PTHREAD=OFF.") + endif() +endif() + +list(JOIN LTC_PKG_CONFIG_CFLAGS " " PKG_CONFIG_CFLAGS) +list(JOIN LTC_PKG_CONFIG_LIBS " " PKG_CONFIG_LIBS) list(JOIN LTC_DEBIAN_MPI_PROVIDER_DEPENDS " " DEBIAN_MPI_PROVIDER_DEPENDS) #----------------------------------------------------------------------------- diff --git a/libtomcrypt.pc.in b/libtomcrypt.pc.in index ebc977d8..4ca6bbea 100644 --- a/libtomcrypt.pc.in +++ b/libtomcrypt.pc.in @@ -5,5 +5,5 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@ Name: LibTomCrypt Description: public domain open source cryptographic toolkit Version: @PROJECT_VERSION@ -Libs: -L${libdir} -ltomcrypt @MPI_PROVIDERS_LIBS@ -Cflags: -I${includedir} @MPI_PROVIDERS_CFLAGS@ +Libs: -L${libdir} -ltomcrypt @PKG_CONFIG_LIBS@ +Cflags: -I${includedir} @PKG_CONFIG_CFLAGS@ diff --git a/makefile.shared b/makefile.shared index 22e0edc3..ae8f2370 100644 --- a/makefile.shared +++ b/makefile.shared @@ -55,17 +55,24 @@ endif include makefile_include.mk ifneq ($(findstring -DLTM_DESC,$(LTC_CFLAGS)),) -LTC_MPI_PROVIDERS_CFLAGS += -DLTM_DESC -LTC_MPI_PROVIDERS_LIBS += -ltommath +LTC_PKG_CONFIG_CFLAGS += -DLTM_DESC +LTC_PKG_CONFIG_LIBS += -ltommath endif ifneq ($(findstring -DTFM_DESC,$(LTC_CFLAGS)),) -LTC_MPI_PROVIDERS_CFLAGS += -DTFM_DESC -LTC_MPI_PROVIDERS_LIBS += -ltfm +LTC_PKG_CONFIG_CFLAGS += -DTFM_DESC +LTC_PKG_CONFIG_LIBS += -ltfm endif ifneq ($(findstring -DGMP_DESC,$(LTC_CFLAGS)),) -LTC_MPI_PROVIDERS_CFLAGS += -DGMP_DESC -LTC_MPI_PROVIDERS_LIBS += -lgmp +LTC_PKG_CONFIG_CFLAGS += -DGMP_DESC +LTC_PKG_CONFIG_LIBS += -lgmp endif +ifneq ($(findstring -DLTC_PTHREAD,$(LTC_CFLAGS)),) +LTC_PKG_CONFIG_CFLAGS += -DLTC_PTHREAD +endif + +# set PKG_CONFIG_CFLAGS and PKG_CONFIG_LIBS to what your environment requires +LTC_PKG_CONFIG_CFLAGS += $(PKG_CONFIG_CFLAGS) +LTC_PKG_CONFIG_LIBS += $(PKG_CONFIG_LIBS) #ciphers come in two flavours... enc+dec and enc 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)))) install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,^libdir=.*,libdir=$(LIBPATH),' \ -e 's,^includedir=.*,includedir=$(INCPATH),' \ - -e 's,@MPI_PROVIDERS_LIBS@,$(LTC_MPI_PROVIDERS_LIBS),' \ - -e 's,@MPI_PROVIDERS_CFLAGS@,$(LTC_MPI_PROVIDERS_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc + -e 's,@PKG_CONFIG_LIBS@,$(LTC_PKG_CONFIG_LIBS),' \ + -e 's,@PKG_CONFIG_CFLAGS@,$(LTC_PKG_CONFIG_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/