From 2510a5e6f98360bb7cd4a52ecf2274656fe75dcc Mon Sep 17 00:00:00 2001 From: kinichiro Date: Thu, 7 Apr 2016 15:08:12 +0900 Subject: [PATCH] modify cmake to build nc - modify structure of CMakeLists.txt under apps/ * move apps/CMakeLists.txt to apps/openssl/ since this is for openssl build * create new apps/nc/CMakeLists.txt for nc build * modify apps/CMakeLists.txt just add_subdirectory() - add checking and compile of arc4random_uniform() - add installing man files, openssl.1 and nc.1 --- CMakeLists.txt | 5 +++ apps/CMakeLists.txt | 82 +------------------------------------ apps/nc/CMakeLists.txt | 54 ++++++++++++++++++++++++ apps/nc/Makefile.am | 1 + apps/openssl/CMakeLists.txt | 81 ++++++++++++++++++++++++++++++++++++ apps/openssl/Makefile.am | 1 + crypto/CMakeLists.txt | 4 ++ include/CMakeLists.txt | 2 +- 8 files changed, 149 insertions(+), 81 deletions(-) create mode 100644 apps/nc/CMakeLists.txt create mode 100644 apps/openssl/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 14a1ae1..c9ce99d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,11 @@ if(HAVE_ARC4RANDOM_BUF) add_definitions(-DHAVE_ARC4RANDOM_BUF) endif() +check_function_exists(arc4random_uniform HAVE_ARC4RANDOM_UNIFORM) +if(HAVE_ARC4RANDOM_UNIFORM) + add_definitions(-DHAVE_ARC4RANDOM_UNIFORM) +endif() + check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO) if(HAVE_EXPLICIT_BZERO) add_definitions(-DHAVE_EXPLICIT_BZERO) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 6213aeb..b55006f 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,80 +1,2 @@ -include_directories( - . - ../include - ../include/compat -) - -set( - OPENSSL_SRC - openssl/apps.c - openssl/asn1pars.c - openssl/ca.c - openssl/ciphers.c - openssl/cms.c - openssl/crl.c - openssl/crl2p7.c - openssl/dgst.c - openssl/dh.c - openssl/dhparam.c - openssl/dsa.c - openssl/dsaparam.c - openssl/ec.c - openssl/ecparam.c - openssl/enc.c - openssl/errstr.c - openssl/gendh.c - openssl/gendsa.c - openssl/genpkey.c - openssl/genrsa.c - openssl/nseq.c - openssl/ocsp.c - openssl/openssl.c - openssl/passwd.c - openssl/pkcs12.c - openssl/pkcs7.c - openssl/pkcs8.c - openssl/pkey.c - openssl/pkeyparam.c - openssl/pkeyutl.c - openssl/prime.c - openssl/rand.c - openssl/req.c - openssl/rsa.c - openssl/rsautl.c - openssl/s_cb.c - openssl/s_client.c - openssl/s_server.c - openssl/s_socket.c - openssl/s_time.c - openssl/sess_id.c - openssl/smime.c - openssl/speed.c - openssl/spkac.c - openssl/ts.c - openssl/verify.c - openssl/version.c - openssl/x509.c -) - -if(CMAKE_HOST_UNIX) - set(OPENSSL_SRC ${OPENSSL_SRC} openssl/apps_posix.c) - set(OPENSSL_SRC ${OPENSSL_SRC} openssl/certhash.c) -endif() - -if(CMAKE_HOST_WIN32) - set(OPENSSL_SRC ${OPENSSL_SRC} openssl/apps_win.c) - set(OPENSSL_SRC ${OPENSSL_SRC} openssl/certhash_win.c) - set(OPENSSL_SRC ${OPENSSL_SRC} openssl/compat/poll_win.c) -endif() - -check_function_exists(strtonum HAVE_STRTONUM) -if(HAVE_STRTONUM) - add_definitions(-DHAVE_STRTONUM) -else() - set(OPENSSL_SRC ${OPENSSL_SRC} openssl/compat/strtonum.c) -endif() - -add_executable(openssl ${OPENSSL_SRC}) -target_link_libraries(openssl ${OPENSSL_LIBS}) - -install(TARGETS openssl DESTINATION bin) +add_subdirectory(openssl) +add_subdirectory(nc) diff --git a/apps/nc/CMakeLists.txt b/apps/nc/CMakeLists.txt new file mode 100644 index 0000000..a218899 --- /dev/null +++ b/apps/nc/CMakeLists.txt @@ -0,0 +1,54 @@ +if(BUILD_NC) + +include_directories( + . + ./compat + ../../include + ../../include/compat +) + +set( + NC_SRC + atomicio.c + netcat.c + socks.c + compat/socket.c +) + +check_function_exists(b64_ntop HAVE_B64_NTOP) +if(HAVE_B64_NTOP) + add_definitions(-DHAVE_B64_NTOP) +else() + set(NC_SRC ${NC_SRC} compat/base64.c) +endif() + +check_function_exists(accept4 HAVE_ACCEPT4) +if(HAVE_ACCEPT4) + add_definitions(-DHAVE_ACCEPT4) +else() + set(NC_SRC ${NC_SRC} compat/accept4.c) +endif() + +check_function_exists(readpassphrase HAVE_READPASSPHRASE) +if(HAVE_READPASSPHRASE) + add_definitions(-DHAVE_READPASSPHRASE) +else() + set(NC_SRC ${NC_SRC} compat/readpassphrase.c) +endif() + +check_function_exists(strtonum HAVE_STRTONUM) +if(HAVE_STRTONUM) + add_definitions(-DHAVE_STRTONUM) +else() + set(NC_SRC ${NC_SRC} compat/strtonum.c) +endif() + +add_executable(nc ${NC_SRC}) +target_link_libraries(nc tls ${OPENSSL_LIBS}) + +if(ENABLE_NC) + install(TARGETS nc DESTINATION bin) + install(FILES nc.1 DESTINATION share/man/man1) +endif() + +endif() diff --git a/apps/nc/Makefile.am b/apps/nc/Makefile.am index 34c5cd3..ceb72b8 100644 --- a/apps/nc/Makefile.am +++ b/apps/nc/Makefile.am @@ -9,6 +9,7 @@ noinst_PROGRAMS = nc endif EXTRA_DIST = nc.1 +EXTRA_DIST += CMakeLists.txt nc_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) nc_LDADD += $(top_builddir)/crypto/libcrypto.la diff --git a/apps/openssl/CMakeLists.txt b/apps/openssl/CMakeLists.txt new file mode 100644 index 0000000..d4f786b --- /dev/null +++ b/apps/openssl/CMakeLists.txt @@ -0,0 +1,81 @@ +include_directories( + . + ../../include + ../../include/compat +) + +set( + OPENSSL_SRC + apps.c + asn1pars.c + ca.c + ciphers.c + cms.c + crl.c + crl2p7.c + dgst.c + dh.c + dhparam.c + dsa.c + dsaparam.c + ec.c + ecparam.c + enc.c + errstr.c + gendh.c + gendsa.c + genpkey.c + genrsa.c + nseq.c + ocsp.c + openssl.c + passwd.c + pkcs12.c + pkcs7.c + pkcs8.c + pkey.c + pkeyparam.c + pkeyutl.c + prime.c + rand.c + req.c + rsa.c + rsautl.c + s_cb.c + s_client.c + s_server.c + s_socket.c + s_time.c + sess_id.c + smime.c + speed.c + spkac.c + ts.c + verify.c + version.c + x509.c +) + +if(CMAKE_HOST_UNIX) + set(OPENSSL_SRC ${OPENSSL_SRC} apps_posix.c) + set(OPENSSL_SRC ${OPENSSL_SRC} certhash.c) +endif() + +if(CMAKE_HOST_WIN32) + set(OPENSSL_SRC ${OPENSSL_SRC} apps_win.c) + set(OPENSSL_SRC ${OPENSSL_SRC} certhash_win.c) + set(OPENSSL_SRC ${OPENSSL_SRC} compat/poll_win.c) +endif() + +check_function_exists(strtonum HAVE_STRTONUM) +if(HAVE_STRTONUM) + add_definitions(-DHAVE_STRTONUM) +else() + set(OPENSSL_SRC ${OPENSSL_SRC} compat/strtonum.c) +endif() + +add_executable(openssl ${OPENSSL_SRC}) +target_link_libraries(openssl ${OPENSSL_LIBS}) + +install(TARGETS openssl DESTINATION bin) +install(FILES openssl.1 DESTINATION share/man/man1) diff --git a/apps/openssl/Makefile.am b/apps/openssl/Makefile.am index 6ec3d62..7345479 100644 --- a/apps/openssl/Makefile.am +++ b/apps/openssl/Makefile.am @@ -89,6 +89,7 @@ noinst_HEADERS += timeouts.h EXTRA_DIST = cert.pem EXTRA_DIST += openssl.cnf EXTRA_DIST += x509v3.cnf +EXTRA_DIST += CMakeLists.txt install-exec-hook: @if [ "@OPENSSLDIR@x" != "x" ]; then \ diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 904e69f..24c6821 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -631,6 +631,10 @@ if(NOT HAVE_ARC4RANDOM_BUF) endif() endif() +if(NOT HAVE_ARC4RANDOM_UNIFORM) + set(CRYPTO_SRC ${CRYPTO_SRC} compat/arc4random_uniform.c) +endif() + if(NOT HAVE_TIMINGSAFE_BCMP) set(CRYPTO_SRC ${CRYPTO_SRC} compat/timingsafe_bcmp.c) endif() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index be442a0..110caa5 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -2,4 +2,4 @@ install(DIRECTORY . DESTINATION include PATTERN "CMakeLists.txt" EXCLUDE PATTERN "compat" EXCLUDE - PATTERN "Makefile.*" EXCLUDE) + PATTERN "Makefile*" EXCLUDE)