Skip to content

Commit

Permalink
[build] Rework CMakeLists, add libinotify support
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Apr 22, 2013
1 parent 9a64377 commit e4c6398
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 57 deletions.
131 changes: 74 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ project(alacarte)
cmake_minimum_required( VERSION 2.8 )
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

#
# Depends
#
find_package(Boost 1.47.0 COMPONENTS system filesystem thread unit_test_framework program_options serialization regex REQUIRED)

if (NOT Boost_FOUND)
message(FATAL_ERROR "Fatal error: Boost (version >= 1.47.0) required.\n")
message(FATAL_ERROR "Fatal error: Boost (version >= 1.47.0) required.\n")
endif (NOT Boost_FOUND)

find_package(Log4Cpp REQUIRED)
IF(NOT MINGW)
find_package(Inotify REQUIRED)
ENDIF(NOT MINGW)

find_package(PkgConfig)
pkg_check_modules(Cairomm cairomm-1.0)
pkg_check_modules(Cairo cairo)
pkg_check_modules(Freetype freetype2)
pkg_check_modules(SigC++ sigc++-2.0)

find_package(Doxygen)

#
# Build options
#
STRING (REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\1" num "${Cairo_VERSION}")
MATH (EXPR cairo_ver "${num}")
STRING (REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\2" num "${Cairo_VERSION}")
Expand All @@ -23,18 +39,17 @@ if (cairo_ver LESS 1 OR cairo_major LESS 12 OR cairo_minor LESS 2)
SET(OLD_CAIRO 1)
message (STATUS "${Cairo_VERSION} < 1.12.2: Enabling render lock.")
endif (cairo_ver LESS 1 OR cairo_major LESS 12 OR cairo_minor LESS 2)
pkg_check_modules(Freetype freetype2)
pkg_check_modules(SigC++ sigc++-2.0)

#Set windows version for MinGW
# Set windows version for MinGW
IF(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0501")
add_definitions(-D_WIN32_WINNT=0x0501)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0501")
add_definitions(-D_WIN32_WINNT=0x0501)
set(SYSTEM_LIBRARIES ws2_32 wsock32)
ELSE(MINGW)
include_directories(${INOTIFY_INCLUDE_DIRS})
set(SYSTEM_LIBRARIES ${INOTIFY_LIBRARY})
ENDIF(MINGW)

# Add preprocessor makro
add_subdirectory(extras/log4cpp)

set(TEST_DIRECTORY "${CMAKE_SOURCE_DIR}/tests")

link_directories(${Boost_LIBRARY_DIRS} ${Cairomm_LIBRARY_DIRS})
Expand All @@ -49,6 +64,36 @@ ENDIF(EXISTS "${PROJECT_SOURCE_DIR}/gmock" AND IS_DIRECTORY "${PROJECT_SOURCE_DI

include_directories(include ${Boost_INCLUDE_DIRS} ${LOG4CPP_INCLUDE_DIRS} ${SigC++_INCLUDE_DIRS} ${Freetype_INCLUDE_DIRS} ${Cairomm_INCLUDE_DIRS})

ADD_DEFINITIONS("-std=c++0x")
ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
ADD_DEFINITIONS(${LOG4CPP_DEFINITIONS})
ADD_DEFINITIONS(-DStatistic_Activated)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
SET(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ftest-coverage -fprofile-arcs -fprofile-values -fvpt -pg")
MARK_AS_ADVANCED(CMAKE_CXX_FLAGS_PROFILE)
SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Profile."
FORCE )

set(DEBUG_BUILD 0)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEBUG_BUILD 1)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Profile")
set(DEBUG_BUILD 1)
endif ()
message (STATUS "Enabling debug code: ${DEBUG_BUILD}")

message(STATUS "Default: ${CMAKE_CXX_FLAGS}")
message(STATUS "Debug: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "Profile: ${CMAKE_CXX_FLAGS_PROFILE}")
message(STATUS "Release: ${CMAKE_CXX_FLAGS_RELEASE}")

#
# Sources
#
file(GLOB_RECURSE server_sources src/server/*.cpp)
file(GLOB_RECURSE importer_sources src/importer/*.cpp)
file(GLOB_RECURSE alacarte_sources src/general/*.cpp src/utils/*.cpp)
Expand All @@ -61,6 +106,13 @@ file(GLOB_RECURSE UnitTests_eval_sources tests/eval/*.cpp)
file(GLOB_RECURSE UnitTests_parser_sources tests/parser/*.cpp)
file(GLOB_RECURSE UnitTests_shared_sources tests/shared/*.cpp)

#
# Targets
#
configure_file("data/config/alacarte.conf.in" "${CMAKE_SOURCE_DIR}/data/config/alacarte.conf")
configure_file("tests/config.hpp.in" "${CMAKE_SOURCE_DIR}/tests/config.hpp")
configure_file("include/config.hpp.in" "${CMAKE_SOURCE_DIR}/include/config.hpp")

add_executable(alacarte-server src/alacarte_server.cpp ${server_sources} ${alacarte_sources})
add_executable(alacarte-importer src/alacarte_importer.cpp ${importer_sources} ${alacarte_sources})
add_executable(unitTests_utils EXCLUDE_FROM_ALL ${UnitTests_utils_sources} ${alacarte_sources} ${UnitTests_shared_sources})
Expand All @@ -83,44 +135,8 @@ IF(GMOCK_FOUND)
set_target_properties(unitTests_mapcss PROPERTIES COMPILE_DEFINITIONS "ALACARTE_TEST")
ENDIF(GMOCK_FOUND)

ADD_DEFINITIONS("-std=c++0x")
ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
ADD_DEFINITIONS(${LOG4CPP_DEFINITIONS})
ADD_DEFINITIONS(-DStatistic_Activated)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
SET(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ftest-coverage -fprofile-arcs -fprofile-values -fvpt -pg")
MARK_AS_ADVANCED(CMAKE_CXX_FLAGS_PROFILE)
SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Profile."
FORCE )

set(DEBUG_BUILD 0)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEBUG_BUILD 1)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Profile")
set(DEBUG_BUILD 1)
endif ()
message (STATUS "Enabling debug code: ${DEBUG_BUILD}")

message(STATUS "Default: ${CMAKE_CXX_FLAGS}")
message(STATUS "Debug: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "Profile: ${CMAKE_CXX_FLAGS_PROFILE}")
message(STATUS "Release: ${CMAKE_CXX_FLAGS_RELEASE}")

configure_file("data/config/alacarte.conf.in" "${CMAKE_SOURCE_DIR}/data/config/alacarte.conf")
configure_file("tests/config.hpp.in" "${CMAKE_SOURCE_DIR}/tests/config.hpp")
configure_file("include/config.hpp.in" "${CMAKE_SOURCE_DIR}/include/config.hpp")

IF(MINGW)
target_link_libraries(alacarte-server ${Boost_LIBRARIES} ${Cairomm_LIBRARIES} ${LOG4CPP_LIBRARIES} ${SigC++_LIBRARIES} pthread ws2_32 wsock32)
target_link_libraries(alacarte-importer ${Boost_LIBRARIES} ${LOG4CPP_LIBRARIES} pthread ws2_32 wsock32)
ELSE()
target_link_libraries(alacarte-server ${Boost_LIBRARIES} ${Cairomm_LIBRARIES} ${LOG4CPP_LIBRARIES} ${SigC++_LIBRARIES} pthread)
target_link_libraries(alacarte-importer ${Boost_LIBRARIES} ${LOG4CPP_LIBRARIES} pthread)
ENDIF()
target_link_libraries(alacarte-server ${Boost_LIBRARIES} ${Cairomm_LIBRARIES} ${LOG4CPP_LIBRARIES} ${SigC++_LIBRARIES} pthread ${SYSTEM_LIBRARIES})
target_link_libraries(alacarte-importer ${Boost_LIBRARIES} ${LOG4CPP_LIBRARIES} pthread ${SYSTEM_LIBRARIES})
target_link_libraries(unitTests_utils ${Boost_LIBRARIES} ${Cairomm_LIBRARIES} ${LOG4CPP_LIBRARIES} pthread)
target_link_libraries(unitTests_general ${Boost_LIBRARIES} ${Cairomm_LIBRARIES} ${LOG4CPP_LIBRARIES} ${SigC++_LIBRARIES} pthread)
target_link_libraries(unitTests_importer ${Boost_LIBRARIES} ${LOG4CPP_LIBRARIES} ${Cairomm_LIBRARIES} ${SigC++_LIBRARIES} pthread)
Expand Down Expand Up @@ -150,17 +166,7 @@ add_custom_target(tests
DEPENDS alacarte-importer unitTests_server unitTests_importer unitTests_general unitTests_parser unitTests_utils ${test_files}
)


install(TARGETS alacarte-server RUNTIME DESTINATION bin)
install(TARGETS alacarte-importer RUNTIME DESTINATION bin)
install(FILES data/config/alacarte.conf DESTINATION /etc)
install(FILES data/default.png DESTINATION share/alacarte)
install(DIRECTORY data/mapcss/ DESTINATION share/alacarte/styles)
install(DIRECTORY data/img DESTINATION share/alacarte)
install(DIRECTORY data/icons DESTINATION share/alacarte)

# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc.doxy ${CMAKE_CURRENT_BINARY_DIR}/doc.doxy @ONLY)
add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc.doxy
Expand All @@ -170,3 +176,14 @@ if(DOXYGEN_FOUND)
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)

#
# Installation
#
install(TARGETS alacarte-server RUNTIME DESTINATION bin)
install(TARGETS alacarte-importer RUNTIME DESTINATION bin)
install(FILES data/config/alacarte.conf DESTINATION /etc)
install(FILES data/default.png DESTINATION share/alacarte)
install(DIRECTORY data/mapcss/ DESTINATION share/alacarte/styles)
install(DIRECTORY data/img DESTINATION share/alacarte)
install(DIRECTORY data/icons DESTINATION share/alacarte)
23 changes: 23 additions & 0 deletions cmake/FindInotify.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Find libinotify (inotify compatibility library used on FreeBSD and MacOS X)
#
# INOTIFY_INCLUDE_DIR
# INOTIFY_LIBRARY
# INOTIFY_FOUND
#

IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
# not needed on Linux
SET(INOTIFY_FOUND TRUE)

SET(INOTIFY_INCLUDE_DIR "")
SET(INOTIFY_LIBRARY "")
ELSE(CMAKE_SYSTEM_NAME MATCHES "Linux")
FIND_PATH(INOTIFY_INCLUDE_DIR NAMES sys/inotify.h)

FIND_LIBRARY(INOTIFY_LIBRARY NAMES inotify)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(INOTIFY DEFAULT_MSG INOTIFY_LIBRARY INOTIFY_INCLUDE_DIR)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")

MARK_AS_ADVANCED(INOTIFY_INCLUDE_DIR INOTIFY_LIBRARY)
File renamed without changes.

0 comments on commit e4c6398

Please sign in to comment.