CMakeLists.txt 7.52 KB
Newer Older
Jason Rhinelander's avatar
Jason Rhinelander committed
1 2
cmake_minimum_required(VERSION 2.8)

Jason Rhinelander's avatar
Jason Rhinelander committed
3
project(fracdist CXX)
Jason Rhinelander's avatar
Jason Rhinelander committed
4

5
set(fracdist_VMAJ 1)
Jason Rhinelander's avatar
Jason Rhinelander committed
6
set(fracdist_VMIN 0)
7
set(fracdist_VPAT 2)
8 9 10 11
set(fracdist_description "fractional unit roots/cointegration pvalue and critical value finder")
set(fracdist_author "Jason Rhinelander <jason@imaginary.ca>")
set(fracdist_homepage "https://github.com/jagerman/fracdist")

12 13 14 15 16 17 18 19 20 21 22 23 24 25
# libfracdist library version (CURRENT.AGE.REVISION), which is totally separate
# from the above.
# CURRENT gets incremented for an incompatible interface change
# AGE gets incremented for compatible-preserving interface changes/additions
# REVISION gets incremented for code changes without interface changes
set(libfracdist_CURRENT  "0")
set(libfracdist_AGE      "0")
set(libfracdist_REVISION "0")

# The versions for the .so file; changes needed only for ABI-incompatible changes.
set(libfracdist_so_VMAJ 1)
set(libfracdist_so_VMIN 0)
set(libfracdist_so_VPAT 0)

26 27 28 29
set(fracdist_data_zip_basename mn-files.zip)
set(fracdist_data_zip "${CMAKE_CURRENT_BINARY_DIR}/data/${fracdist_data_zip_basename}")
set(fracdist_data_url "http://qed.econ.queensu.ca/jae/datasets/mackinnon004/${fracdist_data_zip_basename}")
set(fracdist_data_generated "${CMAKE_BINARY_DIR}/fracdist/data.cpp" "${CMAKE_BINARY_DIR}/fracdist/data.hpp")
30

Jason Rhinelander's avatar
Jason Rhinelander committed
31 32 33 34 35 36 37 38
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
find_package(Perl REQUIRED)

# No in-source building
include(MacroEnsureOutOfSourceBuild)
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out-of-source build.  Create a build directory and run 'cmake ${CMAKE_SOURCE_DIR} [options]'.")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
39 40 41 42 43 44 45 46 47 48
set(CMAKE_CXX_FLAGS "-O3 ${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wextra ${CMAKE_CXX_FLAGS_DEBUG} -O0")

if (MINGW)
    # Link to libgcc/libstdc++ statically (so that we don't need to carry around the extra DLLs)
    set(CMAKE_EXE_LINKER_FLAGS "-static -Wl,--allow-multiple-definition")
    set(CMAKE_SHARED_LINKER_FLAGS "-static")
    add_definitions(-DBOOST_DISABLE_THREADS)
endif()

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
message(STATUS "Downloading ${fracdist_data_url}...")
file(DOWNLOAD "${fracdist_data_url}" "${fracdist_data_zip}" STATUS zipdl_stat EXPECTED_MD5 "d9033e3f941aed5c7ccf5f5ce2756b79")

list(GET zipdl_stat 0 errcode)
if (errcode)
    list(GET zipdl_stat 1 errmsg)
    message(FATAL_ERROR "Unable to download data files from ${fracdist_data_url}: ${errmsg}")
endif()
message(STATUS "${fracdist_data_zip} downloaded.")

foreach(type c m)
    foreach (n RANGE 1 12)
        if (n LESS 10)
            set(n "0${n}")
        endif()
        list(APPEND fracdist_datafiles "${CMAKE_CURRENT_BINARY_DIR}/data/fr${type}app${n}.txt")
    endforeach()
endforeach()

add_custom_command(OUTPUT ${fracdist_datafiles}
    COMMAND ${CMAKE_COMMAND} -E tar xf "${fracdist_data_zip}"
    COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_BINARY_DIR}/data/fracdist.f" "${CMAKE_CURRENT_BINARY_DIR}/data/fracdist.f-win"
    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/data"
    COMMENT "Extracting data/frcapp*.txt, frmapp*.txt from ${fracdist_data_zip_basename}")
Jason Rhinelander's avatar
Jason Rhinelander committed
73

74 75 76
foreach(hpp fracdist/common.hpp fracdist/pvalue.hpp fracdist/critical.hpp)
    list(APPEND fracdist_headers "${CMAKE_CURRENT_SOURCE_DIR}/${hpp}")
endforeach()
77
list(APPEND fracdist_headers "${CMAKE_CURRENT_BINARY_DIR}/fracdist/data.hpp")
78 79 80
foreach(cpp fracdist/pvalue.cpp fracdist/critical.cpp fracdist/common.cpp)
    list(APPEND fracdist_source "${CMAKE_CURRENT_SOURCE_DIR}/${cpp}")
endforeach()
Jason Rhinelander's avatar
Jason Rhinelander committed
81
set(fracdist_programs fdpval fdcrit)
Jason Rhinelander's avatar
Jason Rhinelander committed
82

83 84
add_custom_command(OUTPUT ${fracdist_data_generated}
    COMMAND ${PERL_EXECUTABLE} "-I${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/build-data.pl" "${CMAKE_BINARY_DIR}/data"
Jason Rhinelander's avatar
Jason Rhinelander committed
85
    DEPENDS build-data.pl DataParser.pm ${fracdist_datafiles}
86
    COMMENT "Generating fracdist/data.{cpp,hpp} from data/*.txt"
Jason Rhinelander's avatar
Jason Rhinelander committed
87
)
88
add_custom_target(data DEPENDS ${fracdist_data_generated})
Jason Rhinelander's avatar
Jason Rhinelander committed
89

90 91 92 93 94 95 96
# Try to find Eigen3 on the system first; if that fails, use the included copy
find_package(Eigen3)
if (NOT EIGEN3_FOUND)
    message(STATUS "Eigen3 not found on system; using bundled copy")
    set(EIGEN3_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/eigen3")
    find_package(Eigen3 REQUIRED)
endif()
Jason Rhinelander's avatar
Jason Rhinelander committed
97
include_directories(${EIGEN3_INCLUDE_DIR})
98

99 100 101 102 103 104 105
# Try to find Boost on the system first; if that fails, use the included boost subset
find_package(Boost)
if (NOT Boost_FOUND)
    message(STATUS "Boost not found on system; using bundled copy")
    set(Boost_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/boost")
    find_package(Boost REQUIRED)
endif()
Jason Rhinelander's avatar
Jason Rhinelander committed
106
include_directories(${Boost_INCLUDE_DIRS})
107

108
add_library(fracdist SHARED ${fracdist_source} "${CMAKE_BINARY_DIR}/fracdist/data.cpp")
109 110 111 112
set_target_properties(fracdist PROPERTIES
    VERSION "${libfracdist_CURRENT}.${libfracdist_AGE}.${libfracdist_REVISION}"
    SOVERSION "${libfracdist_CURRENT}"
)
113

114
add_dependencies(fracdist data)
Jason Rhinelander's avatar
Jason Rhinelander committed
115

Jason Rhinelander's avatar
Jason Rhinelander committed
116 117
foreach(exec ${fracdist_programs})
    add_executable(${exec} ${exec}.cpp)
Jason Rhinelander's avatar
Jason Rhinelander committed
118 119 120
    target_link_libraries(${exec} fracdist)
endforeach()

121 122 123 124 125 126 127
# If fracdist_PACKAGE_DOCS is not set, include it only if doxygen is found
if (NOT DEFINED fracdist_PACKAGE_DOCS)
    find_package(Doxygen 1.8.2)
    if (DOXYGEN_FOUND)
        message(STATUS "doxygen found: enabling documentation generation")
        set(fracdist_PACKAGE_DOCS 1)
    else()
128
        message(WARNING "doxygen not found: documentation generation and packaging disabled")
129 130
    endif()
endif()
131

132 133 134 135 136 137 138 139 140 141 142
if (CMAKE_SYSTEM_NAME STREQUAL Windows)
    set(fracdist_docdir "doc")
else()
    set(fracdist_docdir "share/doc/fracdist")
endif()

if (fracdist_PACKAGE_DOCS)
    add_subdirectory(doc)
else()
    add_subdirectory(doc EXCLUDE_FROM_ALL)
endif()
143 144


145 146 147 148
set(CPACK_PACKAGE_VERSION_MAJOR ${fracdist_VMAJ})
set(CPACK_PACKAGE_VERSION_MINOR ${fracdist_VMIN})
set(CPACK_PACKAGE_VERSION_PATCH ${fracdist_VPAT})

149 150
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")

Jason Rhinelander's avatar
Jason Rhinelander committed
151

152 153 154 155
install(FILES ${fracdist_headers} DESTINATION include/fracdist COMPONENT headers)

install(FILES README.md CHANGELOG.md DESTINATION "${fracdist_docdir}" COMPONENT docs)

156
if (CMAKE_SYSTEM_NAME STREQUAL Windows)
157 158 159
    # Windows users are scared of version numbers:
    set(CPACK_PACKAGE_INSTALL_DIRECTORY "fracdist")

160 161 162
    # Windows binaries and lib go in the top-level dir:
    install(TARGETS ${fracdist_programs} COMPONENT binaries DESTINATION .)
    install(TARGETS fracdist COMPONENT library DESTINATION .)
163

164
    set(CPACK_GENERATOR ZIP NSIS)
165 166
    set(CPACK_PACKAGE_FILE_NAME "fracdist-${fracdist_VMAJ}.${fracdist_VMIN}.${fracdist_VPAT}-windows")
else()
167 168
    install(TARGETS fracdist COMPONENT library DESTINATION lib)
    install(TARGETS ${fracdist_programs} COMPONENT binaries DESTINATION bin)
169 170 171 172 173 174 175 176

    set(CPACK_GENERATOR DEB RPM)

    set(arch ${CMAKE_HOST_SYSTEM_PROCESSOR})
    if (arch STREQUAL x86_64)
        set(arch amd64)
    endif()
    set(CPACK_PACKAGE_FILE_NAME "fracdist-${fracdist_VMAJ}.${fracdist_VMIN}.${fracdist_VPAT}-${arch}")
177
    set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${fracdist_author}")
Jason Rhinelander's avatar
Jason Rhinelander committed
178
    #set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
179 180
    set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${fracdist_homepage}")
    set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${fracdist_description}")
181
endif()
182 183 184

set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)

185
include(CPack)
186

187 188 189 190 191
cpack_add_component(library REQUIRED DISPLAY_NAME "libfracdist" DESCRIPTION "The main fracdist library code.")
cpack_add_component(binaries DISPLAY_NAME "Binaries" DESCRIPTION "'fdpval' and 'fdcrit' provide a simple command-line interface to libfracdist functionality.")
cpack_add_component(headers DISABLED DISPLAY_NAME "C++ headers" DESCRIPTION "C++ headers needed to compile code linking to libfracdist.")
cpack_add_component(docs DISABLED DISPLAY_NAME "Documentation" DESCRIPTION "API documentation for libfracdist programming.")