From 95183b5760d7f168ae093ae8f9b29740628a278f Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Tue, 3 Mar 2015 01:14:07 -0500 Subject: migration to cmake --- utils/CMakeLists.txt | 115 ++++++++++++++++++++++++++++++++++++++++ utils/Makefile.am | 127 --------------------------------------------- utils/fast_sparse_vector.h | 6 --- utils/gzstream.cc | 2 +- 4 files changed, 116 insertions(+), 134 deletions(-) create mode 100644 utils/CMakeLists.txt delete mode 100644 utils/Makefile.am (limited to 'utils') diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt new file mode 100644 index 00000000..17436263 --- /dev/null +++ b/utils/CMakeLists.txt @@ -0,0 +1,115 @@ +include_directories() + +set(TEST_SRCS dict_test.cc + logval_test.cc + m_test.cc + small_vector_test.cc + stringlib_test.cc + sv_test.cc + ts.cc + weights_test.cc) + +foreach(testSrc ${TEST_SRCS}) + #Extract the filename without an extension (NAME_WE) + get_filename_component(testName ${testSrc} NAME_WE) + + #Add compile target + set_source_files_properties(${testSrc} PROPERTIES COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DTEST_DATA=\\\"test_data/\\\"") + add_executable(${testName} ${testSrc}) + + #link to Boost libraries AND your targets and dependencies + target_link_libraries(${testName} utils ${Boost_LIBRARIES} ${ZLIB_LIBRARIES}) + + #I like to move testing binaries into a testBin directory + set_target_properties(${testName} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + + #Finally add it to test execution - + #Notice the WORKING_DIRECTORY and COMMAND + add_test(NAME ${testName} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${testName} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +endforeach(testSrc) + + +set(atools_SRCS atools.cc) +add_executable(atools ${atools_SRCS}) +target_link_libraries(atools utils ${Boost_LIBRARIES} ${ZLIB_LIBRARIES}) + +set(dedup_corpus_SRCS dedup_corpus.cc) +add_executable(dedup_corpus ${dedup_corpus_SRCS}) +target_link_libraries(dedup_corpus utils ${Boost_LIBRARIES} ${ZLIB_LIBRARIES}) + +set(utils_STAT_SRCS + test_data + alias_sampler.h + alignment_io.h + array2d.h + b64featvector.h + b64tools.h + batched_append.h + city.h + citycrc.h + corpus_tools.h + dict.h + exp_semiring.h + fast_sparse_vector.h + fdict.h + feature_vector.h + filelib.h + gzstream.h + hash.h + have_64_bits.h + indices_after.h + kernel_string_subseq.h + logval.h + m.h + maxent.h + maxent.cpp + murmur_hash3.h + murmur_hash3.cc + named_enum.h + null_deleter.h + null_traits.h + perfect_hash.h + prob.h + sampler.h + semiring.h + show.h + small_vector.h + sparse_vector.h + star.h + static_utoa.h + stringlib.h + string_piece.hh + tdict.h + timing_stats.h + utoa.h + value_array.h + verbose.h + warning_compiler.h + warning_pop.h + warning_push.h + weights.h + wordid.h + writer.h + fast_lexical_cast.hpp + intrusive_refcount.hpp + alignment_io.cc + b64featvector.cc + b64tools.cc + corpus_tools.cc + dict.cc + tdict.cc + fdict.cc + gzstream.cc + filelib.cc + stringlib.cc + string_piece.cc + sparse_vector.cc + timing_stats.cc + verbose.cc + weights.cc) + +add_library(utils STATIC ${utils_STAT_SRCS}) + + diff --git a/utils/Makefile.am b/utils/Makefile.am deleted file mode 100644 index c858ac7e..00000000 --- a/utils/Makefile.am +++ /dev/null @@ -1,127 +0,0 @@ -bin_PROGRAMS = reconstruct_weights atools dedup_corpus - -noinst_PROGRAMS = \ - ts \ - phmt \ - dict_test \ - m_test \ - weights_test \ - logval_test \ - small_vector_test \ - stringlib_test \ - sv_test - -TESTS = ts small_vector_test logval_test weights_test dict_test m_test sv_test stringlib_test - -noinst_LIBRARIES = libutils.a - -# EXTRA_DIST = test_data - -libutils_a_SOURCES = \ - test_data \ - alias_sampler.h \ - alignment_io.h \ - array2d.h \ - b64featvector.h \ - b64tools.h \ - batched_append.h \ - city.h \ - citycrc.h \ - corpus_tools.h \ - dict.h \ - exp_semiring.h \ - fast_sparse_vector.h \ - fdict.h \ - feature_vector.h \ - filelib.h \ - gzstream.h \ - hash.h \ - have_64_bits.h \ - indices_after.h \ - kernel_string_subseq.h \ - logval.h \ - m.h \ - maxent.h \ - maxent.cpp \ - murmur_hash3.h \ - murmur_hash3.cc \ - named_enum.h \ - null_deleter.h \ - null_traits.h \ - perfect_hash.h \ - prob.h \ - sampler.h \ - semiring.h \ - show.h \ - small_vector.h \ - sparse_vector.h \ - star.h \ - static_utoa.h \ - stringlib.h \ - string_piece.hh \ - tdict.h \ - timing_stats.h \ - utoa.h \ - value_array.h \ - verbose.h \ - warning_compiler.h \ - warning_pop.h \ - warning_push.h \ - weights.h \ - wordid.h \ - writer.h \ - fast_lexical_cast.hpp \ - intrusive_refcount.hpp \ - alignment_io.cc \ - b64featvector.cc \ - b64tools.cc \ - corpus_tools.cc \ - dict.cc \ - tdict.cc \ - fdict.cc \ - gzstream.cc \ - filelib.cc \ - stringlib.cc \ - string_piece.cc \ - sparse_vector.cc \ - timing_stats.cc \ - verbose.cc \ - weights.cc - -if HAVE_CMPH - libutils_a_SOURCES += perfect_hash.cc -endif - -reconstruct_weights_SOURCES = reconstruct_weights.cc -reconstruct_weights_LDADD = libutils.a -atools_SOURCES = atools.cc -atools_LDADD = libutils.a -atools_LDFLAGS = $(STATIC_FLAGS) - -dedup_corpus_SOURCES = dedup_corpus.cc -dedup_corpus_LDADD = libutils.a -dedup_corpus_LDFLAGS = $(STATIC_FLAGS) - -phmt_SOURCES = phmt.cc -phmt_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -ts_SOURCES = ts.cc -ts_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -m_test_SOURCES = m_test.cc -m_test_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -dict_test_SOURCES = dict_test.cc -dict_test_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -weights_test_SOURCES = weights_test.cc -weights_test_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -logval_test_SOURCES = logval_test.cc -logval_test_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -small_vector_test_SOURCES = small_vector_test.cc -small_vector_test_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -sv_test_SOURCES = sv_test.cc -sv_test_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -stringlib_test_SOURCES = stringlib_test.cc -stringlib_test_LDADD = libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) - -################################################################ -# do NOT NOT NOT add any other -I includes NO NO NO NO NO ###### -AM_CPPFLAGS = -DBOOST_TEST_DYN_LINK -W -Wall -I. -I$(top_srcdir) -DTEST_DATA=\"$(top_srcdir)/utils/test_data\" -################################################################ diff --git a/utils/fast_sparse_vector.h b/utils/fast_sparse_vector.h index 1e0ab428..0697fc44 100644 --- a/utils/fast_sparse_vector.h +++ b/utils/fast_sparse_vector.h @@ -20,9 +20,7 @@ #endif #include -#if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP #include -#endif #include "fdict.h" @@ -471,7 +469,6 @@ class FastSparseVector { unsigned char local_size_; bool is_remote_; -#if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP private: friend class boost::serialization::access; template @@ -502,12 +499,9 @@ class FastSparseVector { } } BOOST_SERIALIZATION_SPLIT_MEMBER() -#endif }; -#if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP BOOST_CLASS_TRACKING(FastSparseVector,track_never) -#endif template const FastSparseVector operator+(const FastSparseVector& x, const FastSparseVector& y) { diff --git a/utils/gzstream.cc b/utils/gzstream.cc index 88cd1bd2..dbfa2f53 100644 --- a/utils/gzstream.cc +++ b/utils/gzstream.cc @@ -26,7 +26,7 @@ // Standard C++ Library". // ============================================================================ -#include +#include "gzstream.h" #include #include // for memcpy #include -- cgit v1.2.3 From 06f1b6aedbd96d652d5337cf1b93b51e4dd9a620 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 4 Mar 2015 21:36:51 -0500 Subject: remove perfect hash function stuff, add zip option to extract.cc --- extractor/CMakeLists.txt | 17 ++++++++++---- extractor/extract.cc | 14 ++++++++---- training/mira/mira.py | 59 +++++++++++++++++++++++------------------------- utils/CMakeLists.txt | 1 - utils/perfect_hash.cc | 37 ------------------------------ utils/perfect_hash.h | 27 ---------------------- utils/phmt.cc | 42 ---------------------------------- 7 files changed, 49 insertions(+), 148 deletions(-) delete mode 100644 utils/perfect_hash.cc delete mode 100644 utils/perfect_hash.h delete mode 100644 utils/phmt.cc (limited to 'utils') diff --git a/extractor/CMakeLists.txt b/extractor/CMakeLists.txt index d37c6b95..1cf8533b 100644 --- a/extractor/CMakeLists.txt +++ b/extractor/CMakeLists.txt @@ -1,9 +1,17 @@ -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../utils) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/features) -find_package(GTest) -find_package(GMock) +find_package(OpenMP) +if (OPENMP_FOUND) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") +endif() + +find_package(GTest REQUIRED) +find_package(GMock REQUIRED) if(GMOCK_FOUND) + #rule_factory_test.cc set(TEST_SRCS alignment_test.cc data_array_test.cc fast_intersector_test.cc @@ -15,7 +23,6 @@ if(GMOCK_FOUND) precomputation_test.cc rule_extractor_helper_test.cc rule_extractor_test.cc - rule_factory_test.cc scorer2_test.cc suffix_array_sampler_test.cc suffix_array_test.cc @@ -56,7 +63,7 @@ target_link_libraries(run_extractor extractor ${Boost_LIBRARIES} z) set(extract_SRCS extract.cc) add_executable(extract ${extract_SRCS}) -target_link_libraries(extract extractor ${Boost_LIBRARIES} z) +target_link_libraries(extract extractor utils ${Boost_LIBRARIES} z) set(extractor_STAT_SRCS diff --git a/extractor/extract.cc b/extractor/extract.cc index e5b6f6ff..08f209cc 100644 --- a/extractor/extract.cc +++ b/extractor/extract.cc @@ -14,6 +14,7 @@ const unsigned omp_get_num_threads() { return 1; } #endif +#include "filelib.h" #include "alignment.h" #include "data_array.h" #include "features/count_source_target.h" @@ -42,8 +43,8 @@ using namespace features; using namespace std; // Returns the file path in which a given grammar should be written. -fs::path GetGrammarFilePath(const fs::path& grammar_path, int file_number) { - string file_name = "grammar." + to_string(file_number); +fs::path GetGrammarFilePath(const fs::path& grammar_path, int file_number, bool use_zip) { + string file_name = "grammar." + to_string(file_number) + (use_zip ? ".gz" : ""); return grammar_path / file_name; } @@ -58,6 +59,7 @@ int main(int argc, char** argv) { ("threads,t", po::value()->required()->default_value(1), threads_option.c_str()) ("grammars,g", po::value()->required(), "Grammars output path") + ("gzip,z", "Gzip grammars") ("max_rule_span", po::value()->default_value(15), "Maximum rule span") ("max_rule_symbols", po::value()->default_value(5), @@ -205,12 +207,14 @@ int main(int argc, char** argv) { vm["max_rule_symbols"].as(), vm["max_samples"].as(), vm["tight_phrases"].as()); + const bool use_zip = vm.count("gzip"); // Creates the grammars directory if it doesn't exist. fs::path grammar_path = vm["grammars"].as(); if (!fs::is_directory(grammar_path)) { fs::create_directory(grammar_path); } + grammar_path = fs::canonical(grammar_path); // Reads all sentences for which we extract grammar rules (the paralellization // is simplified if we read all sentences upfront). @@ -239,12 +243,12 @@ int main(int argc, char** argv) { } Grammar grammar = extractor.GetGrammar( sentences[i], blacklisted_sentence_ids); - ofstream output(GetGrammarFilePath(grammar_path, i).c_str()); - output << grammar; + WriteFile wf(GetGrammarFilePath(grammar_path, i, use_zip).c_str()); + *wf.stream() << grammar; } for (size_t i = 0; i < sentences.size(); ++i) { - cout << " " << sentences[i] << " " << suffixes[i] << endl; } diff --git a/training/mira/mira.py b/training/mira/mira.py index ec9c2d64..ccecb10e 100755 --- a/training/mira/mira.py +++ b/training/mira/mira.py @@ -5,12 +5,6 @@ import argparse import logging import random, time import gzip, itertools -try: - import cdec.score -except ImportError: - sys.stderr.write('Could not import pycdec, see cdec/python/README.md for details\n') - sys.exit(1) -have_mpl = True try: import matplotlib matplotlib.use('Agg') @@ -19,26 +13,33 @@ except ImportError: have_mpl = False #mira run script -#requires pycdec to be built, since it is used for scoring hypothesis -#translations. #matplotlib must be installed for graphing to work #email option requires mail +script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) +fast_score_binary = script_dir+'/../../mteval/fast_score' +dlog = None + #scoring function using pycdec scoring def fast_score(hyps, refs, metric): - scorer = cdec.score.Scorer(metric) - logging.info('loaded {0} references for scoring with {1}'.format( - len(refs), metric)) - if metric=='BLEU': - logging.warning('BLEU is ambiguous, assuming IBM_BLEU\n') - metric = 'IBM_BLEU' - elif metric=='COMBI': - logging.warning('COMBI metric is no longer supported, switching to ' - 'COMB:TER=-0.5;BLEU=0.5') - metric = 'COMB:TER=-0.5;BLEU=0.5' - stats = sum(scorer(r).evaluate(h) for h,r in itertools.izip(hyps,refs)) - logging.info('Score={} ({})'.format(stats.score, stats.detail)) - return stats.score + #scorer = cdec.score.Scorer(metric) + #logging.info('loaded {0} references for scoring with {1}'.format( + # len(refs), metric)) + #if metric=='BLEU': + # logging.warning('BLEU is ambiguous, assuming IBM_BLEU\n') + # metric = 'IBM_BLEU' + #elif metric=='COMBI': + # logging.warning('COMBI metric is no longer supported, switching to ' + # 'COMB:TER=-0.5;BLEU=0.5') + # metric = 'COMB:TER=-0.5;BLEU=0.5' + #stats = sum(scorer(r).evaluate(h) for h,r in itertools.izip(hyps,refs)) + #logging.info('Score={} ({})'.format(stats.score, stats.detail)) + #return stats.score + cmd = ('{0} -r{1} -i {2} -m {3}').format(fast_score_binary, refs, hyps, metric) + proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + o = proc.stdout.readline().strip() + print 'res: ', o + return float(o) #create new parallel input file in output directory in sgml format def enseg(devfile, newfile, gprefix): @@ -81,7 +82,6 @@ def enseg(devfile, newfile, gprefix): def main(): #set logging to write all info messages to stderr logging.basicConfig(level=logging.INFO) - script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) if not have_mpl: logging.warning('Failed to import matplotlib, graphs will not be generated.') @@ -373,7 +373,8 @@ def optimize(args, script_dir, dev_size): cmd = parallel_cmd + ' ' + decoder_cmd logging.info('OPTIMIZATION COMMAND: {}'.format(cmd)) - + + global dlog dlog = open(decoderlog,'w') runf = open(runfile,'w') retries = 0 @@ -420,7 +421,7 @@ def optimize(args, script_dir, dev_size): bests = [] fears = [] for line in run: - hope, best, fear = line.split(' ||| ') + hope, best, fear = line.strip().split(' ||| ') hopes.append(hope) bests.append(best) fears.append(fear) @@ -436,14 +437,10 @@ def optimize(args, script_dir, dev_size): gzip_file(runfile) gzip_file(decoderlog) - ref_file = open(refs) - references = [line.split(' ||| ') for line in - ref_file.read().strip().split('\n')] - ref_file.close() #get score for best hypothesis translations, hope and fear translations - dec_score = fast_score(bests, references, args.metric) - dec_score_h = fast_score(hopes, references, args.metric) - dec_score_f = fast_score(fears, references, args.metric) + dec_score = fast_score(runfile+'.B', refs, args.metric) + dec_score_h = fast_score(runfile+'.H', refs, args.metric) + dec_score_f = fast_score(runfile+'.F', refs, args.metric) hope_best_fear['hope'].append(dec_score) hope_best_fear['best'].append(dec_score_h) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 17436263..59fb644d 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -70,7 +70,6 @@ set(utils_STAT_SRCS named_enum.h null_deleter.h null_traits.h - perfect_hash.h prob.h sampler.h semiring.h diff --git a/utils/perfect_hash.cc b/utils/perfect_hash.cc deleted file mode 100644 index 706e2741..00000000 --- a/utils/perfect_hash.cc +++ /dev/null @@ -1,37 +0,0 @@ -#include "config.h" - -#ifdef HAVE_CMPH - -#include "perfect_hash.h" - -#include -#include - -using namespace std; - -PerfectHashFunction::~PerfectHashFunction() { - cmph_destroy(mphf_); -} - -PerfectHashFunction::PerfectHashFunction(const string& fname) { - FILE* f = fopen(fname.c_str(), "r"); - if (!f) { - cerr << "Failed to open file " << fname << " for reading: cannot load hash function.\n"; - abort(); - } - mphf_ = cmph_load(f); - if (!mphf_) { - cerr << "cmph_load failed on " << fname << "!\n"; - abort(); - } -} - -size_t PerfectHashFunction::operator()(const string& key) const { - return cmph_search(mphf_, &key[0], key.size()); -} - -size_t PerfectHashFunction::number_of_keys() const { - return cmph_size(mphf_); -} - -#endif diff --git a/utils/perfect_hash.h b/utils/perfect_hash.h deleted file mode 100644 index 8c12c9f0..00000000 --- a/utils/perfect_hash.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef PERFECT_HASH_MAP_H_ -#define PERFECT_HASH_MAP_H_ - -#include -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef HAVE_CMPH -#include "cmph.h" -#endif - -class PerfectHashFunction : boost::noncopyable { - public: - explicit PerfectHashFunction(const std::string& fname); - ~PerfectHashFunction(); - size_t operator()(const std::string& key) const; - size_t number_of_keys() const; - private: -#ifdef HAVE_CMPH - cmph_t *mphf_; -#endif -}; - -#endif diff --git a/utils/phmt.cc b/utils/phmt.cc deleted file mode 100644 index b17febf6..00000000 --- a/utils/phmt.cc +++ /dev/null @@ -1,42 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifndef HAVE_CMPH -int main() { - return 0; -} -#else - -#include -#include "weights.h" -#include "fdict.h" - -using namespace std; - -int main(int argc, char** argv) { - if (argc != 2) { cerr << "Usage: " << argv[0] << " file.mphf\n"; return 1; } - FD::EnableHash(argv[1]); - cerr << "Number of keys: " << FD::NumFeats() << endl; - cerr << "LexFE = " << FD::Convert("LexFE") << endl; - cerr << "LexEF = " << FD::Convert("LexEF") << endl; - { - vector v(FD::NumFeats()); - v[FD::Convert("LexFE")] = 1.0; - v[FD::Convert("LexEF")] = 0.5; - cerr << "Writing...\n"; - Weights::WriteToFile("weights.bin", v); - cerr << "Done.\n"; - } - { - vector v(FD::NumFeats()); - cerr << "Reading...\n"; - Weights::InitFromFile("weights.bin", &v); - cerr << "Done.\n"; - assert(v[FD::Convert("LexFE")] == 1.0); - assert(v[FD::Convert("LexEF")] == 0.5); - } -} - -#endif - -- cgit v1.2.3 From 42e6a2888f986b062c6391b6bef6ef817c6b8a68 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 4 Mar 2015 22:46:33 -0500 Subject: deal with libdl --- .gitignore | 1 + CMakeLists.txt | 1 + cmake/FindLibDL.cmake | 30 ++++++++++++++++++++++++++++++ decoder/CMakeLists.txt | 4 +++- extractor/CMakeLists.txt | 10 ++++++---- training/crf/CMakeLists.txt | 22 ++++++++-------------- training/dtrain/CMakeLists.txt | 2 +- training/latent_svm/CMakeLists.txt | 2 +- training/mira/CMakeLists.txt | 7 +++---- training/utils/CMakeLists.txt | 6 ++++-- utils/CMakeLists.txt | 2 +- 11 files changed, 59 insertions(+), 28 deletions(-) create mode 100644 cmake/FindLibDL.cmake (limited to 'utils') diff --git a/.gitignore b/.gitignore index 81ede92e..07145db9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +example_extff/libff_example.so* Testing/ */Testing/ training/Testing/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 21c2a230..934c69e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) #### packages find_package(ZLIB REQUIRED) find_package(BZip2 REQUIRED) +find_package(LibDL REQUIRED) # for pycdec find_package(PythonInterp 2.7 REQUIRED) diff --git a/cmake/FindLibDL.cmake b/cmake/FindLibDL.cmake new file mode 100644 index 00000000..1689e4c7 --- /dev/null +++ b/cmake/FindLibDL.cmake @@ -0,0 +1,30 @@ +# - Find libdl +# Find the native LIBDL includes and library +# +# LIBDL_INCLUDE_DIR - where to find dlfcn.h, etc. +# LIBDL_LIBRARIES - List of libraries when using libdl. +# LIBDL_FOUND - True if libdl found. + + +IF (LIBDL_INCLUDE_DIR) + # Already in cache, be silent + SET(LIBDL_FIND_QUIETLY TRUE) +ENDIF (LIBDL_INCLUDE_DIR) + +FIND_PATH(LIBDL_INCLUDE_DIR dlfcn.h) + +SET(LIBDL_NAMES dl libdl ltdl libltdl) +FIND_LIBRARY(LIBDL_LIBRARY NAMES ${LIBDL_NAMES} ) + +# handle the QUIETLY and REQUIRED arguments and set LIBDL_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibDL DEFAULT_MSG LIBDL_LIBRARY LIBDL_INCLUDE_DIR) + +IF(LIBDL_FOUND) + SET( LIBDL_LIBRARIES ${LIBDL_LIBRARY} ) +ELSE(LIBDL_FOUND) + SET( LIBDL_LIBRARIES ) +ENDIF(LIBDL_FOUND) + +MARK_AS_ADVANCED( LIBDL_LIBRARY LIBDL_INCLUDE_DIR ) diff --git a/decoder/CMakeLists.txt b/decoder/CMakeLists.txt index 591ab7b3..f7683887 100644 --- a/decoder/CMakeLists.txt +++ b/decoder/CMakeLists.txt @@ -3,6 +3,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mteval) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../klm) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + PROJECT(decoder C CXX) find_package(FLEX REQUIRED) @@ -145,7 +147,7 @@ add_library(libcdec STATIC ${libcdec_SRCS}) set(cdec_SRCS cdec.cc) add_executable(cdec ${cdec_SRCS}) -target_link_libraries(cdec libcdec mteval utils ksearch klm klm_util klm_util_double ${Boost_LIBRARIES} ${ZLIB_LIBRARIES}) +target_link_libraries(cdec libcdec mteval utils ksearch klm klm_util klm_util_double ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBDL_LIBRARIES}) set(TEST_SRCS grammar_test.cc diff --git a/extractor/CMakeLists.txt b/extractor/CMakeLists.txt index 1cf8533b..93a524cc 100644 --- a/extractor/CMakeLists.txt +++ b/extractor/CMakeLists.txt @@ -8,9 +8,10 @@ if (OPENMP_FOUND) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif() -find_package(GTest REQUIRED) -find_package(GMock REQUIRED) -if(GMOCK_FOUND) +find_package(GTest) +find_package(GMock) +if(GTEST_FOUND) + if(GMOCK_FOUND) #rule_factory_test.cc set(TEST_SRCS alignment_test.cc data_array_test.cc @@ -50,7 +51,8 @@ if(GMOCK_FOUND) add_test(NAME ${testName} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${testName} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach(testSrc) -endif(GMOCK_FOUND) + endif(GMOCK_FOUND) +endif(GTEST_FOUND) set(sacompile_SRCS sacompile.cc) add_executable(sacompile ${sacompile_SRCS}) diff --git a/training/crf/CMakeLists.txt b/training/crf/CMakeLists.txt index 4792983e..85fab7a0 100644 --- a/training/crf/CMakeLists.txt +++ b/training/crf/CMakeLists.txt @@ -9,7 +9,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../decoder) set(mpi_batch_optimize_SRCS mpi_batch_optimize.cc cllh_observer.cc cllh_observer.h) add_executable(mpi_batch_optimize ${mpi_batch_optimize_SRCS}) -target_link_libraries(mpi_batch_optimize training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) +target_link_libraries(mpi_batch_optimize training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) ########### next target ############### @@ -17,8 +17,7 @@ set(mpi_adagrad_optimize_SRCS mpi_adagrad_optimize.cc cllh_observer.cc cllh_obse add_executable(mpi_adagrad_optimize ${mpi_adagrad_optimize_SRCS}) -target_link_libraries(mpi_adagrad_optimize ${KDE4_KDECORE_LIBS} training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) - +target_link_libraries(mpi_adagrad_optimize ${KDE4_KDECORE_LIBS} training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) ########### next target ############### @@ -27,8 +26,7 @@ set(mpi_compute_cllh_SRCS mpi_compute_cllh.cc cllh_observer.cc cllh_observer.h) add_executable(mpi_compute_cllh ${mpi_compute_cllh_SRCS}) -target_link_libraries(mpi_compute_cllh ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) - +target_link_libraries(mpi_compute_cllh ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) ########### next target ############### @@ -37,8 +35,7 @@ set(mpi_extract_features_SRCS mpi_extract_features.cc) add_executable(mpi_extract_features ${mpi_extract_features_SRCS}) -target_link_libraries(mpi_extract_features ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) - +target_link_libraries(mpi_extract_features ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) ########### next target ############### @@ -47,8 +44,7 @@ set(mpi_extract_reachable_SRCS mpi_extract_reachable.cc) add_executable(mpi_extract_reachable ${mpi_extract_reachable_SRCS}) -target_link_libraries(mpi_extract_reachable ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) - +target_link_libraries(mpi_extract_reachable ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) ########### next target ############### @@ -56,8 +52,7 @@ set(mpi_flex_optimize_SRCS mpi_flex_optimize.cc) add_executable(mpi_flex_optimize ${mpi_flex_optimize_SRCS}) -target_link_libraries(mpi_flex_optimize ${KDE4_KDECORE_LIBS} training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) - +target_link_libraries(mpi_flex_optimize ${KDE4_KDECORE_LIBS} training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) ########### next target ############### @@ -65,7 +60,7 @@ set(mpi_online_optimize_SRCS mpi_online_optimize.cc) add_executable(mpi_online_optimize ${mpi_online_optimize_SRCS}) -target_link_libraries(mpi_online_optimize ${KDE4_KDECORE_LIBS} training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) +target_link_libraries(mpi_online_optimize ${KDE4_KDECORE_LIBS} training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) ########### next target ############### @@ -73,6 +68,5 @@ set(mpi_baum_welch_SRCS mpi_baum_welch.cc) add_executable(mpi_baum_welch ${mpi_baum_welch_SRCS}) -target_link_libraries(mpi_baum_welch ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) - +target_link_libraries(mpi_baum_welch ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) diff --git a/training/dtrain/CMakeLists.txt b/training/dtrain/CMakeLists.txt index 653cfe2b..72e80b6b 100644 --- a/training/dtrain/CMakeLists.txt +++ b/training/dtrain/CMakeLists.txt @@ -12,4 +12,4 @@ set(dtrain_SRCS pairsampling.h score.h) add_executable(dtrain ${dtrain_SRCS}) -target_link_libraries(dtrain libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) +target_link_libraries(dtrain libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) diff --git a/training/latent_svm/CMakeLists.txt b/training/latent_svm/CMakeLists.txt index ec48e02f..332b8d42 100644 --- a/training/latent_svm/CMakeLists.txt +++ b/training/latent_svm/CMakeLists.txt @@ -5,4 +5,4 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../decoder) set(latent_svm_SRCS latent_svm.cc) add_executable(latent_svm ${latent_svm_SRCS}) -target_link_libraries(latent_svm libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) +target_link_libraries(latent_svm libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) diff --git a/training/mira/CMakeLists.txt b/training/mira/CMakeLists.txt index 3a8fa516..bba9ef5f 100644 --- a/training/mira/CMakeLists.txt +++ b/training/mira/CMakeLists.txt @@ -5,13 +5,12 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../decoder) set(kbest_mira_SRCS kbest_mira.cc) add_executable(kbest_mira ${kbest_mira_SRCS}) -target_link_libraries(kbest_mira ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) +target_link_libraries(kbest_mira libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) set(kbest_cut_mira_SRCS kbest_cut_mira.cc) add_executable(kbest_cut_mira ${kbest_cut_mira_SRCS}) -target_link_libraries(kbest_cut_mira ${KDE4_KDECORE_LIBS} libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) +target_link_libraries(kbest_cut_mira libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) set(ada_opt_sm_SRCS ada_opt_sm.cc) add_executable(ada_opt_sm ${ada_opt_sm_SRCS}) -target_link_libraries(ada_opt_sm ${KDE4_KDECORE_LIBS} training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z) - +target_link_libraries(ada_opt_sm training_utils libcdec ksearch mteval utils klm klm_util klm_util_double ${Boost_LIBRARIES} z ${LIBDL_LIBRARIES}) diff --git a/training/utils/CMakeLists.txt b/training/utils/CMakeLists.txt index 1734ee73..2753b9f0 100644 --- a/training/utils/CMakeLists.txt +++ b/training/utils/CMakeLists.txt @@ -2,6 +2,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../utils) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../mteval) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../decoder) +find_package(Threads REQUIRED) + set(training_utils_STAT_SRCS candidate_set.h entropy.h @@ -21,11 +23,11 @@ add_library(training_utils STATIC ${training_utils_STAT_SRCS}) set(sentserver_SRCS sentserver.cc) add_executable(sentserver ${sentserver_SRCS}) -target_link_libraries(sentserver) +target_link_libraries(sentserver ${CMAKE_THREAD_LIBS_INIT}) set(sentclient_SRCS sentclient.cc) add_executable(sentclient ${sentclient_SRCS}) -target_link_libraries(sentclient) +target_link_libraries(sentclient ${CMAKE_THREAD_LIBS_INIT}) set(grammar_convert_SRCS grammar_convert.cc) add_executable(grammar_convert ${grammar_convert_SRCS}) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 59fb644d..58668254 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories() +set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(TEST_SRCS dict_test.cc logval_test.cc -- cgit v1.2.3 From 737ed7a7f932b1a7e40d2755bcdee6bc0aa2de63 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Thu, 2 Apr 2015 00:36:01 -0400 Subject: fix PIC flag on old version of cmake --- decoder/CMakeLists.txt | 8 ++++++-- utils/CMakeLists.txt | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'utils') diff --git a/decoder/CMakeLists.txt b/decoder/CMakeLists.txt index ac07e9fe..b49d6477 100644 --- a/decoder/CMakeLists.txt +++ b/decoder/CMakeLists.txt @@ -3,9 +3,13 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mteval) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../klm) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..) -PROJECT(decoder C CXX) +PROJECT(decoder CXX) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +if (CMAKE_VERSION VERSION_LESS 2.8.9) # TODO remove once we increase the cmake requirement + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DPIC") +else() + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() find_package(FLEX REQUIRED) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 58668254..6982fa11 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,4 +1,8 @@ -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +if (CMAKE_VERSION VERSION_LESS 2.8.9) # TODO remove once we increase the cmake requirement + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DPIC") +else() + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() set(TEST_SRCS dict_test.cc logval_test.cc -- cgit v1.2.3