[sword-svn] r2545 - in trunk: . cmake
greg.hellings at crosswire.org
greg.hellings at crosswire.org
Wed Sep 1 14:48:17 MST 2010
Author: greg.hellings
Date: 2010-09-01 14:48:17 -0700 (Wed, 01 Sep 2010)
New Revision: 2545
Modified:
trunk/CMakeLists.txt
trunk/cmake/install.cmake
Log:
Committing a change that will allow you to build both shared and static at the
same time with CMake.
Modified: trunk/CMakeLists.txt
===================================================================
--- trunk/CMakeLists.txt 2010-08-30 21:30:23 UTC (rev 2544)
+++ trunk/CMakeLists.txt 2010-09-01 21:48:17 UTC (rev 2545)
@@ -82,66 +82,106 @@
# Most of the work for configuration is done above, already.
#
# I want to do this manually, there might be reason in the future
-IF(LIBSWORD_LIBRARY_TYPE STREQUAL "Shared")
+IF(LIBSWORD_LIBRARY_TYPE MATCHES ".*Shared.*")
ADD_LIBRARY(sword SHARED ${sword_SOURCES})
-ELSE(LIBSWORD_LIBRARY_TYPE STREQUAL "Shared")
- ADD_LIBRARY(sword STATIC ${sword_SOURCES})
-#ELSE(LIBSWORD_LIBRARY_TYPE STREQUAL "Static")
-# MESSAGE(ERROR "Please set library build type to either 'Static' or 'Shared'")
-ENDIF(LIBSWORD_LIBRARY_TYPE STREQUAL "Shared")
+ MESSAGE(STATUS "Building Shared library.")
+ SET(BUILDING_SHARED 1)
+ENDIF(LIBSWORD_LIBRARY_TYPE MATCHES ".*Shared.*")
-IF(NOT LIBSWORD_SOVERSION)
+IF(LIBSWORD_LIBRARY_TYPE MATCHES ".*Static.*")
+ ADD_LIBRARY(sword_static STATIC ${sword_SOURCES})
+ SET(BUILDING_STATIC 1)
+ # With MSVC, the .dll files also create .lib files of the same name
+ # with the exported symbols. Thus, we don't want the two to have the
+ # same exact name. In other systems, the .a and .so suffixes suffice
+ # to keep them separate
+ IF(NOT MSVC OR NOT LIBSWORD_LIBRARY_TYPE MATCHES ".*Shared.*")
+ SET_TARGET_PROPERTIES(sword_static PROPERTIES
+ OUTPUT_NAME "sword")
+ MESSAGE(STATUS "Building Static library with name sword")
+ ELSE(NOT MSVC OR NOT LIBSWORD_LIBRARY_TYPE MATCHES ".*Shared.*")
+ MESSAGE(STATUS "Building Static library with name
+ sword_static")
+ ENDIF(NOT MSVC OR NOT LIBSWORD_LIBRARY_TYPE MATCHES ".*Shared.*")
+ENDIF(LIBSWORD_LIBRARY_TYPE MATCHES ".*Static.*")
+
+###############################################################################################
+# This allows the user to set a SONAME for the library. This allows packagers and those who
+# care about that sort of thing to be happy and have all their SONAMES set properly.
+#
+IF(NOT LIBSWORD_SOVERSION AND BUILDING_SHARED)
SET(SWORD_SOVERSION ${SWORD_VERSION})
-ELSE(NOT LIBSWORD_SOVERSION)
+ELSE(NOT LIBSWORD_SOVERSION AND BUILDING_SHARED)
SET(SWORD_SOVERSION ${LIBSWORD_SOVERSION})
-ENDIF(NOT LIBSWORD_SOVERSION)
-SET_TARGET_PROPERTIES(sword
- PROPERTIES SOVERSION ${SWORD_SOVERSION})
+ENDIF(NOT LIBSWORD_SOVERSION AND BUILDING_SHARED)
+IF(BUILDING_SHARED)
+ SET_TARGET_PROPERTIES(sword
+ PROPERTIES SOVERSION ${SWORD_SOVERSION})
+ MESSAGE(STATUS "Setting SOVERSION to ${SWORD_SOVERSION}")
+ENDIF(BUILDING_SHARED)
+
###############################################################################################
# Some options are only needed if we're going to be building a debug option into the library
# These are generally only for developer building and testing
#
# Debug testing
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
- SET_TARGET_PROPERTIES(sword
- PROPERTIES COMPILE_FLAGS "-g3 -Wall -Werror -O0"
- )
+ SET(SWORD_CFLAGS "-g3 -Wall -Werror -O0")
ELSE(CMAKE_BUILD_TYPE STREQUAL "Debug")
- SET_TARGET_PROPERTIES(sword
- PROPERTIES COMPILE_FLAGS "-O3"
- )
+ SET(SWORD_CFLAGS "-O3")
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
IF(SWORD_ENABLE_WARNINGS STREQUAL "Yes")
+ SET(SWORD_CFLAGS "${SWORD_CFLAGS} -Werror")
+ENDIF(SWORD_ENABLE_WARNINGS STREQUAL "Yes")
+
+IF(BUILDING_SHARED)
SET_TARGET_PROPERTIES(sword
- PROPERTIES
- COMPILE_FLAGS "-Werror"
+ PROPERTIES COMPILE_FLAGS ${SWORD_CFLAGS}
)
-ENDIF(SWORD_ENABLE_WARNINGS STREQUAL "Yes")
+ENDIF(BUILDING_SHARED)
+IF(BUILDING_STATIC)
+ SET_TARGET_PROPERTIES(sword_static
+ PROPERTIES COMPILE_FLAGS ${SWORD_CFLAGS}
+ )
+ENDIF(BUILDING_STATIC)
+
+MESSAGE(STATUS "Setting CFlags for compile to ${SWORD_CFLAGS}")
+
##############################################################################################
# Setting libraries and includes
#
IF(WITH_ZLIB)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
- TARGET_LINK_LIBRARIES(sword ${ZLIB_LIBRARY})
+ SET(SWORD_LINK_LIBRARIES ${SWORD_LINK_LIBRARIES} ${ZLIB_LIBRARY})
ENDIF(WITH_ZLIB)
IF(WITH_CURL)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
- TARGET_LINK_LIBRARIES(sword ${CURL_LIBRARY})
+ SET(SWORD_LINK_LIBRARIES ${SWORD_LINK_LIBRARIES} ${CURL_LIBRARY})
ENDIF(WITH_CURL)
IF(WITH_CLUCENE)
INCLUDE_DIRECTORIES(${CLUCENE_INCLUDE_DIR})
- TARGET_LINK_LIBRARIES(sword ${CLUCENE_LIBRARY})
+ SET(SWORD_LINK_LIBRARIES ${SWORD_LINK_LIBRARIES} ${CLUCENE_LIBRARY})
LINK_DIRECTORIES(${CLUCENE_LIBRARY_DIR})
ENDIF(WITH_CLUCENE)
IF(WITH_ICU)
- TARGET_LINK_LIBRARIES(sword ${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES})
INCLUDE_DIRECTORIES(${ICU_INCLUDE_DIRS})
+ SET(SWORD_LINK_LIBRARIES ${SWORD_LINK_LIBRARIES} ${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES})
ENDIF(WITH_ICU)
+IF(BUILDING_SHARED)
+ TARGET_LINK_LIBRARIES(sword ${SWORD_LINK_LIBRARIES})
+ENDIF(BUILDING_SHARED)
+
+IF(BUILDING_STATIC)
+ TARGET_LINK_LIBRARIES(sword_static ${SWORD_LINK_LIBRARIES})
+ENDIF(BUILDING_STATIC)
+
+MESSAGE(STATUS "Setting link libraries to ${SWORD_LINK_LIBRARIES}")
+
##############################################################################################
#########
### TODO: Not sure about these...
Modified: trunk/cmake/install.cmake
===================================================================
--- trunk/cmake/install.cmake 2010-08-30 21:30:23 UTC (rev 2544)
+++ trunk/cmake/install.cmake 2010-09-01 21:48:17 UTC (rev 2545)
@@ -14,8 +14,14 @@
ENDIF(NOT CMAKE_INSTALL_PREFIX)
# Install the library
-INSTALL(TARGETS sword
- DESTINATION ${SWORD_INSTALL_DIR}/lib)
+IF(BUILDING_SHARED)
+ INSTALL(TARGETS sword
+ DESTINATION ${SWORD_INSTALL_DIR}/lib)
+ENDIF(BUILDING_SHARED)
+IF(BUILDING_STATIC)
+ INSTALL(TARGETS sword_static
+ DESTINATION ${SWORD_INSTALL_DIR}/lib)
+ENDIF(BUILDING_STATIC)
# Install the headers
INSTALL(FILES ${SWORD_INSTALL_HEADERS}
@@ -60,13 +66,25 @@
FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/icu")
FOREACH(translit ${translit_SOURCES})
STRING(REPLACE ".txt" ".res" translit_OUTPUT ${translit})
- ADD_CUSTOM_COMMAND(TARGET sword
- POST_BUILD
- COMMAND ${ICU_GENRB} -s . -d "${CMAKE_CURRENT_BINARY_DIR}/icu" ${translit}
- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/icu"
- COMMENT "Converting ${translit}"
- VERBATIM
- )
+ # Only needs to be run once, really, so we'll hook it to the end of either
+ IF(BUILDING_SHARED)
+ ADD_CUSTOM_COMMAND(TARGET sword
+ POST_BUILD
+ COMMAND ${ICU_GENRB} -s . -d "${CMAKE_CURRENT_BINARY_DIR}/icu" ${translit}
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/icu"
+ COMMENT "Converting ${translit}"
+ VERBATIM
+ )
+ ELSE(BUILDING_SHARED)
+ ADD_CUSTOM_COMMAND(TARGET sword_static
+ POST_BUILD
+ COMMAND ${ICU_GENRB} -s . -d "${CMAKE_CURRENT_BINARY_DIR}/icu" ${translit}
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/icu"
+ COMMENT "Converting ${translit}"
+ VERBATIM
+ )
+ ENDIF(BUILDING_SHARED)
+
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/icu/${translit_OUTPUT}"
DESTINATION "${libdir}/${SWORD_VERSION}_icu_${ICU_VERSION}")
ENDFOREACH(translit ${translit_SOURCES})
More information about the sword-cvs
mailing list