Commit 391f022b authored by Dominik Charousset's avatar Dominik Charousset

support build as static library

the configure script provides two new flags:
* `--build-static`
* `--build-static-only`
parent 556406fe
...@@ -174,25 +174,29 @@ if (DISABLE_CONTEXT_SWITCHING) ...@@ -174,25 +174,29 @@ if (DISABLE_CONTEXT_SWITCHING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCPPA_DISABLE_CONTEXT_SWITCHING") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCPPA_DISABLE_CONTEXT_SWITCHING")
endif () endif ()
add_library(libcppa SHARED ${LIBCPPA_SRC}) # bulid shared library only if not comiling static only
if (NOT "${CPPA_BUILD_STATIC_ONLY}" STREQUAL "yes")
set(LIBRARY_VERSION ${LIBCPPA_VERSION_MAJOR}.${LIBCPPA_VERSION_MINOR}.${LIBCPPA_VERSION_PATCH}) add_library(libcppa SHARED ${LIBCPPA_SRC})
set(LIBRARY_SOVERSION ${LIBCPPA_VERSION_MAJOR}) target_link_libraries(libcppa ${LD_FLAGS})
set_target_properties(libcppa set(LIBRARY_VERSION ${LIBCPPA_VERSION_MAJOR}.${LIBCPPA_VERSION_MINOR}.${LIBCPPA_VERSION_PATCH})
set(LIBRARY_SOVERSION ${LIBCPPA_VERSION_MAJOR})
set_target_properties(libcppa
PROPERTIES PROPERTIES
SOVERSION ${LIBRARY_SOVERSION} SOVERSION ${LIBRARY_SOVERSION}
VERSION ${LIBRARY_VERSION} VERSION ${LIBRARY_VERSION}
OUTPUT_NAME cppa) OUTPUT_NAME cppa)
install(TARGETS libcppa LIBRARY DESTINATION lib)
endif ()
add_library(libcppaStatic STATIC ${LIBCPPA_SRC}) # build static library if --build-static or --build-static-only was set
set_target_properties(libcppaStatic PROPERTIES OUTPUT_NAME cppa) if ("${CPPA_BUILD_STATIC_ONLY}" STREQUAL "yes" OR "${CPPA_BUILD_STATIC}" STREQUAL "yes")
add_library(libcppaStatic STATIC ${LIBCPPA_SRC})
set_target_properties(libcppaStatic PROPERTIES OUTPUT_NAME cppa_static)
install(TARGETS libcppaStatic ARCHIVE DESTINATION lib)
endif ()
link_directories(${LD_DIRS}) link_directories(${LD_DIRS})
include_directories(${INCLUDE_DIRS}) include_directories(${INCLUDE_DIRS})
target_link_libraries(libcppa ${LD_FLAGS})
# install shared library
install(TARGETS libcppa LIBRARY DESTINATION lib)
# install includes # install includes
install(DIRECTORY cppa/ DESTINATION include/cppa FILES_MATCHING PATTERN "*.hpp") install(DIRECTORY cppa/ DESTINATION include/cppa FILES_MATCHING PATTERN "*.hpp")
...@@ -220,12 +224,16 @@ endif () ...@@ -220,12 +224,16 @@ endif ()
set (CPPA_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libcppa) set (CPPA_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libcppa)
set (CPPA_INCLUDE ${CPPA_INCLUDE_PATH}) set (CPPA_INCLUDE ${CPPA_INCLUDE_PATH})
if (APPLE) if ("${CPPA_BUILD_STATIC_ONLY}" STREQUAL "yes")
set (CPPA_LIBRARY ${LIBRARY_OUTPUT_PATH}/libcppa_static.a ${LD_FLAGS})
else ()
if (APPLE)
set (CPPA_LIBRARY ${LIBRARY_OUTPUT_PATH}/libcppa.dylib) set (CPPA_LIBRARY ${LIBRARY_OUTPUT_PATH}/libcppa.dylib)
elseif (UNIX) elseif (UNIX)
set (CPPA_LIBRARY ${LIBRARY_OUTPUT_PATH}/libcppa.so) set (CPPA_LIBRARY ${LIBRARY_OUTPUT_PATH}/libcppa.so)
else () else ()
message (SEND_FATAL "Host platform not supported ...") message (SEND_FATAL "Host platform not supported ...")
endif ()
endif () endif ()
if (EXECUTABLE_OUTPUT_PATH) if (EXECUTABLE_OUTPUT_PATH)
...@@ -235,13 +243,21 @@ endif () ...@@ -235,13 +243,21 @@ endif ()
# set up subdirectories # set up subdirectories
if (NOT "${CPPA_NO_UNIT_TESTS}" STREQUAL "yes") if (NOT "${CPPA_NO_UNIT_TESTS}" STREQUAL "yes")
enable_testing()
add_subdirectory(unit_testing) add_subdirectory(unit_testing)
if ("${CPPA_BUILD_STATIC_ONLY}" STREQUAL "yes")
add_dependencies(all_unit_tests libcppaStatic)
else ()
add_dependencies(all_unit_tests libcppa) add_dependencies(all_unit_tests libcppa)
enable_testing() endif ()
endif () endif ()
if (NOT "${CPPA_NO_EXAMPLES}" STREQUAL "yes") if (NOT "${CPPA_NO_EXAMPLES}" STREQUAL "yes")
add_subdirectory(examples) add_subdirectory(examples)
if ("${CPPA_BUILD_STATIC_ONLY}" STREQUAL "yes")
add_dependencies(all_examples libcppaStatic)
else ()
add_dependencies(all_examples libcppa) add_dependencies(all_examples libcppa)
endif ()
endif () endif ()
# set optional flags # set optional flags
...@@ -262,6 +278,7 @@ if (DOXYGEN_FOUND) ...@@ -262,6 +278,7 @@ if (DOXYGEN_FOUND)
VERBATIM) VERBATIM)
endif (DOXYGEN_FOUND) endif (DOXYGEN_FOUND)
# set variables for summary
set(LOG_LEVEL_STR "none") set(LOG_LEVEL_STR "none")
if (CPPA_LOG_LEVEL) if (CPPA_LOG_LEVEL)
if (${CPPA_LOG_LEVEL} EQUAL 0) if (${CPPA_LOG_LEVEL} EQUAL 0)
...@@ -299,6 +316,16 @@ toYesNo(ENABLE_DEBUG DEBUG_MODE_STR) ...@@ -299,6 +316,16 @@ toYesNo(ENABLE_DEBUG DEBUG_MODE_STR)
invertYesNo(CPPA_NO_EXAMPLES BUILD_EXAMPLES) invertYesNo(CPPA_NO_EXAMPLES BUILD_EXAMPLES)
invertYesNo(CPPA_NO_UNIT_TESTS BUILD_UNIT_TESTS) invertYesNo(CPPA_NO_UNIT_TESTS BUILD_UNIT_TESTS)
if (NOT "${CPPA_BUILD_STATIC}" STREQUAL "yes")
set(CPPA_BUILD_STATIC "no")
endif ()
if (NOT "${CPPA_BUILD_STATIC_ONLY}" STREQUAL "yes")
set(CPPA_BUILD_STATIC_ONLY "no")
else ()
set(CPPA_BUILD_STATIC "yes")
endif ()
# done (print summary) # done (print summary)
message("\n====================| Build Summary |====================" message("\n====================| Build Summary |===================="
"\n" "\n"
...@@ -310,6 +337,8 @@ message("\n====================| Build Summary |====================" ...@@ -310,6 +337,8 @@ message("\n====================| Build Summary |===================="
"\nContext switching: ${CONTEXT_SWITCHING}" "\nContext switching: ${CONTEXT_SWITCHING}"
"\nBuild examples: ${BUILD_EXAMPLES}" "\nBuild examples: ${BUILD_EXAMPLES}"
"\nBuild unit tests: ${BUILD_UNIT_TESTS}" "\nBuild unit tests: ${BUILD_UNIT_TESTS}"
"\nBuild static: ${CPPA_BUILD_STATIC}"
"\nBulid static only: ${CPPA_BUILD_STATIC_ONLY}"
"\n" "\n"
"\nCXX: ${CMAKE_CXX_COMPILER}" "\nCXX: ${CMAKE_CXX_COMPILER}"
"\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${build_type}}" "\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${build_type}}"
......
...@@ -31,6 +31,8 @@ Usage: $0 [OPTION]... [VAR=VALUE]... ...@@ -31,6 +31,8 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
--dual-build build both with gcc and clang --dual-build build both with gcc and clang
--no-examples build libcppa without examples --no-examples build libcppa without examples
--no-unit-tests build libcppa without unit tests --no-unit-tests build libcppa without unit tests
--build-static build libcppa as static and shared library
--build-static-only build libcppa as static library only
Installation Directories: Installation Directories:
--prefix=PREFIX installation directory [/usr/local] --prefix=PREFIX installation directory [/usr/local]
...@@ -214,6 +216,12 @@ while [ $# -ne 0 ]; do ...@@ -214,6 +216,12 @@ while [ $# -ne 0 ]; do
--no-unit-tests) --no-unit-tests)
append_cache_entry CPPA_NO_UNIT_TESTS STRING yes append_cache_entry CPPA_NO_UNIT_TESTS STRING yes
;; ;;
--build-static)
append_cache_entry CPPA_BUILD_STATIC STRING yes
;;
--build-static-only)
append_cache_entry CPPA_BUILD_STATIC_ONLY STRING yes
;;
*) *)
echo "Invalid option '$1'. Try $0 --help to see available options." echo "Invalid option '$1'. Try $0 --help to see available options."
exit 1 exit 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment