src/CMakeLists.txt
author Tero Marttila <terom@fixme.fi>
Wed, 27 May 2009 23:07:00 +0300
branchnew-lib-errors
changeset 216 a10ba529ae39
parent 203 ffdf53fd0337
child 217 7728d6ec3abf
permissions -rw-r--r--
initial error code
# dependancies
find_package (LibEvent REQUIRED)
find_package (GnuTLS REQUIRED)
find_package (LibPQ REQUIRED)
find_package (Evsql REQUIRED)
find_package (Lua51 REQUIRED)
find_package (PCRE REQUIRED)

# add our include path
include_directories (${LibEvent_INCLUDE_DIRS} ${GnuTLS_INCLUDE_DIRS} ${Evsql_INCLUDE_DIRS} ${Lua51_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS})

# define our source code modules
set (CORE_SOURCES error.c log.c str.c object.c)
set (IO_SOURCES transport.c service.c transport_fd.c sock.c resolve.c tcp.c tcp_transport.c tcp_client.c tcp_server.c ssl.c ssl_client.c fifo.c)
set (PROTO_SOURCES line_proto.c msg_proto.c)
set (IRC_SOURCES irc_line.c irc_conn.c irc_net.c irc_chan.c chain.c irc_cmd.c irc_proto.c irc_client.c irc_user.c irc_queue.c irc_net_connect.c)
set (LUA_SOURCES nexus_lua.c lua_objs.c lua_config.c lua_irc.c lua_func.c lua_type.c lua_thread.c)
set (CONSOLE_SOURCES console.c lua_console.c)

set (NEXUS_SOURCES nexus.c ${CORE_SOURCES} ${IO_SOURCES} ${PROTO_SOURCES} ${IRC_SOURCES} ${LUA_SOURCES} ${CONSOLE_SOURCES} signals.c module.c config.c)
set (IRC_LOG_SOURCES modules/irc_log.c)
set (LOGWATCH_SOURCES modules/logwatch.c modules/logwatch_source.c modules/logwatch_filter.c modules/logwatch_chan.c)

# define our libraries
set (MODULE_LIBRARIES "dl")
set (NEXUS_LIBRARIES ${LibEvent_LIBRARIES} ${GnuTLS_LIBRARIES} ${MODULE_LIBRARIES} "readline" ${Lua51_LIBRARIES})

# compiler flags
set (CMAKE_C_FLAGS "-Wall -Wextra -std=gnu99")

# add our binaries
add_executable (nexus ${NEXUS_SOURCES})

# add our modules
add_library (irc_log MODULE ${IRC_LOG_SOURCES})
add_library (logwatch MODULE ${LOGWATCH_SOURCES})

# set libraries
target_link_libraries (nexus ${NEXUS_LIBRARIES})
target_link_libraries (irc_log ${Evsql_LIBRARIES})
target_link_libraries (logwatch ${PCRE_LIBRARIES})

# nexus needs to export its symbols to be able to load modules
set_target_properties (nexus PROPERTIES
    # XXX: use ENABLE_EXPORTS?
    LINK_FLAGS      "--export-dynamic"
)

# modules have weird names
set_target_properties (irc_log logwatch PROPERTIES
    PREFIX                      "mod_"
    LIBRARY_OUTPUT_DIRECTORY    "modules"
)

# test stuff
if (ENABLE_TEST)
    # build list of source files
    file (GLOB _TEST_SOURCES "test/*.c")
    set (TEST_SOURCES ${_TEST_SOURCES} ${CORE_SOURCES} ${IO_SOURCES} ${PROTO_SOURCES} transport_test.c ${IRC_SOURCES})
    
    # add executable target and link against libs
    add_executable (test_harness EXCLUDE_FROM_ALL ${TEST_SOURCES})
    target_link_libraries (test_harness ${NEXUS_LIBRARIES})
    
    if (ENABLE_TEST_COVERAGE)
        # test should enable code coverage instrumentation
        set (TEST_CFLAGS "-fprofile-arcs -ftest-coverage")
        set (TEST_LFLAGS "-fprofile-arcs -ftest-coverage")
    
    endif (ENABLE_TEST_COVERAGE)
    
    # set the correct output file name and cc/ld flags
    set_target_properties (test_harness PROPERTIES
        OUTPUT_NAME                 "test"
        COMPILE_FLAGS               ${TEST_CFLAGS}
        LINK_FLAGS                  ${TEST_LFLAGS}
    )

    # path to the test harness executable
    get_target_property (TEST_EXECUTABLE test_harness LOCATION)

    # path to directory containing the .o/.gcdo/.gcno files for the test harness
    get_filename_component (TEST_OBJECT_DIR ${TEST_EXECUTABLE} PATH)

    # XXX: ugly hardcoding of CMake internals, but I can't find anything else for this
    set (TEST_OBJECT_DIR ${TEST_OBJECT_DIR}/CMakeFiles/test_harness.dir PARENT_SCOPE)
    set (TEST_EXECUTABLE ${TEST_EXECUTABLE} PARENT_SCOPE)

endif (ENABLE_TEST)

## setup install info
#install (TARGETS evirc
#    LIBRARY         DESTINATION lib
#    ARCHIVE         DESTINATION lib/static
#    PUBLIC_HEADER   DESTINATION include
#)