Skip to content

Commit

Permalink
Merge pull request #18 from BlueBrain/pramodk/cmake_master_merge
Browse files Browse the repository at this point in the history
Support for CMake based build system
  • Loading branch information
nrnhines authored Dec 2, 2019
2 parents 08c48bb + 254fa24 commit ead384c
Show file tree
Hide file tree
Showing 22 changed files with 1,092 additions and 208 deletions.
52 changes: 52 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#=============================================================================
# Travis IV settings
#=============================================================================

#=============================================================================
# Environment
#=============================================================================
language: cpp
dist: bionic
osx_image: xcode10.2

#=============================================================================
# Common Packages
#=============================================================================
addons:
apt:
packages:
- libx11-dev
- libxcomposite-dev
homebrew:
packages:
- xz

#=============================================================================
# Configure build matrix and corresponding environment
#=============================================================================
env:
global:
- INSTALL_DIR="$HOME/install"
jobs:
- BUILD_CMD="bash build.sh && ./configure --prefix=$INSTALL_DIR"
- BUILD_CMD="cmake . -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DIV_ENABLE_SHARED=OFF"
- BUILD_CMD="cmake . -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DIV_ENABLE_SHARED=ON"
os:
- linux
- osx

#=============================================================================
# Setup environment and Install dependencies (nothing for now)
#=============================================================================
before_install:
- echo $LANG
- echo $LC_ALL
- $CXX -v

#=============================================================================
# Build and install
#=============================================================================
script:
- eval ${BUILD_CMD}
- make -j 2
- make install
185 changes: 185 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
project(INTERVIEWS C CXX)

# =============================================================================
# CMake common project settings
# =============================================================================
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 1)

set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})


# =============================================================================
# To be able to use project as submodule, avoid using PROJECT_SOURCE_DIR
# =============================================================================
set(IV_PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# For future target customization
set(IV_AS_SUBPROJECT OFF)
if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(IV_AS_SUBPROJECT ON)
endif()

# =============================================================================
# Project build options
# =============================================================================
option(IV_ENABLE_SHARED "Build libraries shared or static" OFF)

# =============================================================================
# CMake build settings
# =============================================================================
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)

if(NOT IV_ENABLE_SHARED)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(IV_LIB_TYPE "STATIC")
else()
set(IV_LIB_TYPE "SHARED")
endif()

# CYGWIN macros is used in the code
if(${CMAKE_SYSTEM_NAME} MATCHES "CYGWIN")
set(CYGWIN 1)
endif()

# =============================================================================
# Include cmake modules
# =============================================================================
list(APPEND CMAKE_MODULE_PATH ${IV_PROJECT_SOURCE_DIR}/cmake)
include(HelperFunctions)
include(PlatformHelper)
include(RpathHelper)
include(CheckIncludeFiles)
include(CheckFunctionExists)

# =============================================================================
# Find dependencies
# =============================================================================
find_package(X11)

if(NOT X11_FOUND AND NOT IV_WINDOWS_BUILD)
if(APPLE)
message(FATAL_ERROR "Install XQuartz from https://www.xquartz.org/ to build iv")
else()
message(FATAL_ERROR "Install X11 to build iv (e.g. 'apt install libx11-dev libxcomposite-dev' on Ubuntu")
endif()
endif()

# =============================================================================
# Check existance of various headers, functions and directories
# =============================================================================
set(CMAKE_REQUIRED_QUIET TRUE)
message(STATUS "Checking for include files")
check_include_files(fcntl.h HAVE_FCNTL_H)
check_include_files(malloc.h HAVE_MALLOC_H)
check_include_files(memory.h HAVE_MEMORY_H)
check_include_files(osfcn.h HAVE_OSFCN_H)
check_include_files(socket.h HAVE_SOCKET_H)
check_include_files(stdint.h HAVE_STDINT_H)
check_include_files(stdlib.h HAVE_STDLIB_H)
check_include_files(string.h HAVE_STRING_H)
check_include_files(strings.h HAVE_STRINGS_H)
check_include_files(stropts.h HAVE_STROPTS_H)
check_include_files(stream.h HAVE_STREAM_H)
check_include_files(sys/conf.h HAVE_SYS_CONF_H)
check_include_files(sys/file.h HAVE_SYS_FILE_H)
check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
check_include_files(sys/param.h HAVE_SYS_PARAM_H)
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
check_include_files(sys/time.h HAVE_SYS_TIME_H)
check_include_files(unistd.h HAVE_UNISTD_H)

message(STATUS "Checking for functions")
check_function_exists(getcwd HAVE_GETCWD)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
check_function_exists(mmap HAVE_MMAP)
check_function_exists(sigprocmask HAVE_POSIX_SIGNALS)
check_function_exists(socket HAVE_SOCKET)
check_function_exists(strcspn HAVE_STRCSPN)
check_function_exists(strerror HAVE_STRERROR)
check_function_exists(strtod HAVE_STRTOD)
check_function_exists(strtol HAVE_STRTOL)
check_function_exists(uname HAVE_UNAME)

message(STATUS "Checking for include directories")
iv_check_dir_exists(dirent.h HAVE_DIRENT_H)
iv_check_dir_exists(ndir.h HAVE_NDIR_H)
iv_check_dir_exists(sys/dir.h HAVE_SYS_DIR_H)
iv_check_dir_exists(sys/ndir.h HAVE_SYS_NDIR_H)

message(STATUS "Checking for types")
iv_check_type_exists(sys/types.h gid_t int gid_t)
iv_check_type_exists(sys/types.h off_t "long int" off_t)
iv_check_type_exists(sys/types.h pid_t int pid_t)
iv_check_type_exists(sys/types.h size_t "unsigned int" size_t)
iv_check_type_exists(sys/types.h uid_t int uid_t)

# =============================================================================
# Check if signals support
# =============================================================================
# NOTE: check_function_exists(sigsetmask HAVE_BSD_SIGNALS) made obsolete by sigprocmask(2).
# sigsetmask exists but the usage generates a variety of errors. See the old autoconf acinclude.m4
# AC_DEFUN([BASH_SIGNAL_CHECK] For now, use only if don't have posix signals.
if(NOT ${HAVE_POSIX_SIGNALS})
set(HAVE_BSD_SIGNALS 1)
else()
set(HAVE_BSD_SIGNALS 0)
endif()

# =============================================================================
# Set return type of signal in RETSIGTYPE
# =============================================================================
iv_check_signal_return_type(RETSIGTYPE)

# =============================================================================
# Generate config.h after all checks
# =============================================================================
add_definitions(-DHAVE_CONFIG_H)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)

# =============================================================================
# Include source directories
# =============================================================================
include_directories(${IV_PROJECT_SOURCE_DIR}/src/include)
add_subdirectory(src/bin)
add_subdirectory(src/lib)

# =============================================================================
# Install binaries and headers
# =============================================================================
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/include/ DESTINATION include)
if(NOT IV_AS_SUBPROJECT)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/iv-config.cmake DESTINATION share/cmake)
install(EXPORT iv DESTINATION share/cmake)
endif()

# =============================================================================
# Print build status
# =============================================================================
message(STATUS "")
message(STATUS "Configured INTERVIEWS ${PROJECT_VERSION}")
message(STATUS "")
string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
if(cmake_generator_tolower MATCHES "makefile")
message(STATUS "Some things you can do now:")
message(STATUS "--------------+--------------------------------------------------------------")
message(STATUS "Command | Description")
message(STATUS "--------------+--------------------------------------------------------------")
message(STATUS "make install | Will install INTERVIEWS to: ${CMAKE_INSTALL_PREFIX}")
message(STATUS " | Change the install location of NEURON using:")
message(STATUS " | cmake <src_path> -DCMAKE_INSTALL_PREFIX=<install_path>")
message(STATUS "--------------+--------------------------------------------------------------")
message(STATUS "Build option | Status")
message(STATUS "--------------+--------------------------------------------------------------")
message(STATUS "SHARED | ${IV_ENABLE_SHARED}")
message(STATUS "--------------+--------------------------------------------------------------")
message(STATUS " See more : https://github.com/neuronsimulator/iv")
message(STATUS "--------------+--------------------------------------------------------------")
endif()
message(STATUS "")
70 changes: 0 additions & 70 deletions chkstream.m4

This file was deleted.

81 changes: 81 additions & 0 deletions cmake/HelperFunctions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# =============================================================================
# Check if directory related to DIR exist by compiling code
# =============================================================================
function(iv_check_dir_exists HEADER VARIABLE)
# code template to check existance of DIR
set(CONFTEST_DIR_TPL "
#include <sys/types.h>
#include <@dir_header@>
int main () {
if ((DIR *) 0)
return 0\;
return 0\;
}")
# first get header file
check_include_files(${HEADER} HAVE_HEADER)
if(${HAVE_HEADER})
# if header is found, create a code from template
string(REPLACE "@dir_header@"
${HEADER}
CONFTEST_DIR
"${CONFTEST_DIR_TPL}")
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c ${CONFTEST_DIR})
# try to compile
try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c)
set(${VARIABLE} ${RESULT_VAR} PARENT_SCOPE)
file(REMOVE "conftest.c")
endif()
endfunction()

# =============================================================================
# Check if given type exist by compiling code
# =============================================================================
function(iv_check_type_exists HEADER TYPE DEFAULT_TYPE VARIABLE)
# code template to check existance of specific type
set(CONFTEST_TYPE_TPL "
#include <@header@>
int main () {
if (sizeof (@type@))
return 0\;
return 0\;
}")
string(REPLACE "@header@"
${HEADER}
CONFTEST_TYPE
"${CONFTEST_TYPE_TPL}")
string(REPLACE "@type@"
${TYPE}
CONFTEST_TYPE
"${CONFTEST_TYPE}")
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c ${CONFTEST_TYPE})

try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c)
if(NOT ${RESULT_VAR})
set(${VARIABLE} ${DEFAULT_TYPE} PARENT_SCOPE)
endif()
file(REMOVE "conftest.c")
endfunction()

# =============================================================================
# Check return type of signal
# =============================================================================
function(iv_check_signal_return_type VARIABLE)
# code template to check signal support
set(CONFTEST_RETSIGTYPE "
#include <sys/types.h>
#include <signal.h>
int main () {
return *(signal (0, 0)) (0) == 1;
}")
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c ${CONFTEST_RETSIGTYPE})
try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c)
if(${RESULT_VAR})
set(${VARIABLE} int PARENT_SCOPE)
else()
set(${VARIABLE} void PARENT_SCOPE)
endif()
file(REMOVE "conftest.c")
endfunction()
Loading

0 comments on commit ead384c

Please sign in to comment.