Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a build based on CMake. #44

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ stamp-h1
libtool
tags

build/

config/
!config/libotr.m4

Expand Down
48 changes: 48 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 2.8)
project(irssi-otr C)
set(PROJECT_VERSION "1.0.0")
set(BUILD_SHARED_LIBS ON)

# Avoid source tree pollution
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not permitted. Make a separate folder for building:\nmkdir build; cd build; cmake ..\nBefore that, remove the files already created:\nrm -rf CMakeCache.txt CMakeFiles")
endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

# Add a sensible build type default and warning because empty means no optimization and no debug info.
if(NOT CMAKE_BUILD_TYPE)
message("WARNING: CMAKE_BUILD_TYPE is not defined!\n Defaulting to CMAKE_BUILD_TYPE=Debug. Use ccmake to set a proper value.")
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif(NOT CMAKE_BUILD_TYPE)

# Disable assertions for release builds
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions("-DNDEBUG")
endif()

# Enable extra compiler flags...
set(CMAKE_C_FLAGS "-std=gnu99 -Wall -Wextra ${CMAKE_CXX_FLAGS}")

set(IRSSI_MODULE_DIR "lib/irssi/modules" CACHE STRING "Irssi module install path. Must be a relative path (from CMAKE_INSTALL_PREFIX), with no trailing slash.")
mark_as_advanced(IRSSI_MODULE_DIR)

set(IRSSI_HELP_DIR "share/irssi/help" CACHE STRING "Help page install path. Must be a relative path (from CMAKE_INSTALL_PREFIX), with no trailing slash.")
mark_as_advanced(IRSSI_HELP_DIR)

find_package(Threads REQUIRED)
find_package(OTR 4.0.0 REQUIRED)
find_package(Irssi REQUIRED)
include_directories(${Threads_INCLUDE_DIRS} ${OTR_INCLUDE_DIRS} ${Irssi_INCLUDE_DIRS})

add_definitions(-DMODULE_NAME=\"otr\")
add_definitions(-DVERSION=\"${PROJECT_VERSION}\")
add_definitions(-pthread)

file(GLOB srcfiles src/*.h src/*.c)
add_library(otr MODULE ${srcfiles})
target_link_libraries(otr ${Threads_LIBRARIES} ${OTR_LIBRARIES} ${Irssi_LIBRARIES})

install(TARGETS otr DESTINATION ${Irssi_MODULE_DIR})
install(FILES help/otr DESTINATION ${Irssi_SHARE_DIR}/help)

39 changes: 39 additions & 0 deletions cmake/FindGlib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# - Try to find Glib-2.0
# Once done, this will define
#
# Glib_FOUND - system has Glib
# Glib_INCLUDE_DIRS - the Glib include directories
# Glib_LIBRARIES - link these to use Glib

include(LibFindMacros)

# Use pkg-config to get hints about paths
libfind_pkg_check_modules(Glib_PKGCONF glib-2.0)

# Main include dir
find_path(Glib_INCLUDE_DIR
NAMES glib.h
PATHS ${Glib_PKGCONF_INCLUDE_DIRS}
PATH_SUFFIXES glib-2.0
)

# Glib-related libraries also use a separate config header, which is in lib dir
find_path(GlibConfig_INCLUDE_DIR
NAMES glibconfig.h
PATHS ${Glib_PKGCONF_INCLUDE_DIRS} /usr
PATH_SUFFIXES lib/glib-2.0/include ../lib/glib-2.0/include
)

# Finally the library itself
find_library(Glib_LIBRARY
NAMES glib-2.0
PATHS ${Glib_PKGCONF_LIBRARY_DIRS}
)

# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
set(Glib_PROCESS_INCLUDES Glib_INCLUDE_DIR GlibConfig_INCLUDE_DIR)
set(Glib_PROCESS_LIBS Glib_LIBRARY)
libfind_process(Glib)


30 changes: 30 additions & 0 deletions cmake/FindIrssi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# - Try to find Irssi
# Once done, this will define
#
# Irssi_FOUND - system has LibIrssi
# Irssi_INCLUDE_DIRS - the LibIrssi include directories
# Irssi_LIBRARIES - link these to use LibIrssi
#
# See documentation on how to write CMake scripts at
# http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries

include(LibFindMacros)

libfind_package(Irssi Glib)
find_path(Irssi_INCLUDE_DIR NAMES src/core/chatnets.h PATH_SUFFIXES irssi)

if (Irssi_INCLUDE_DIR)
string(REGEX REPLACE "include/irssi$" "lib/irssi/modules" Irssi_MODULE_DIR "${Irssi_INCLUDE_DIR}")
string(REGEX REPLACE "include/irssi$" "share/irssi" Irssi_SHARE_DIR "${Irssi_INCLUDE_DIR}")
endif()

# Irssi has b0rked headers that require subdirectories to be included in path
set(Irssi_src_INCLUDE_DIR ${Irssi_INCLUDE_DIR}/src)
set(Irssi_core_INCLUDE_DIR ${Irssi_INCLUDE_DIR}/src/core)
set(Irssi_PROCESS_INCLUDES Irssi_src_INCLUDE_DIR Irssi_core_INCLUDE_DIR)

# The headers would cause a lot of warnings...
add_definitions(-Wno-missing-field-initializers -Wno-unused-parameter)

libfind_process(Irssi)

16 changes: 16 additions & 0 deletions cmake/FindOTR.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# - Try to find OTR
# Once done, this will define
#
# OTR_FOUND - system has LibOTR
# OTR_INCLUDE_DIRS - the LibOTR include directories
# OTR_LIBRARIES - link these to use LibOTR
#
# See documentation on how to write CMake scripts at
# http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries

include(LibFindMacros)

libfind_pkg_detect(OTR libotr FIND_PATH libotr/version.h FIND_LIBRARY otr)
libfind_version_header(OTR libotr/version.h OTRL_VERSION)
libfind_process(OTR)

Loading