Make dynamic or static libraries optional

The user can choose static or dynamic libraries using
BUILD_STATIC_LIBRARIES and BUILD_DYNAMIC_LIBRARIES. By default
Windows will only build static libraries and Linux will build both.
This commit is contained in:
Matt Williams 2011-04-21 21:40:51 +02:00
parent f7f473126c
commit ac0fb2b310
9 changed files with 135 additions and 40 deletions

View File

@ -68,6 +68,8 @@ ADD_SUBDIRECTORY(documentation)
MESSAGE(STATUS "")
MESSAGE(STATUS "Summary")
MESSAGE(STATUS "-------")
MESSAGE(STATUS "Static libraries: " ${BUILD_STATIC_LIBRARIES})
MESSAGE(STATUS "Dynamic libraries: " ${BUILD_DYNAMIC_LIBRARIES})
MESSAGE(STATUS "Build examples: " ${ENABLE_EXAMPLES})
MESSAGE(STATUS "Build tests: " ${BUILD_TESTING})
MESSAGE(STATUS "API Docs available: " ${DOXYGEN_FOUND})

View File

@ -47,6 +47,9 @@ The other available settings for PolyVox are:
``BUILD_TESTING`` (``ON`` or ``OFF``)
Build the test applications that come with PolyVox. Running the tests is detailed in the next section. Defaults to ``ON``.
``BUILD_STATIC_LIBRARIES`` and ``BUILD_DYNAMIC_LIBRARIES`` (``ON`` or ``OFF``)
Choose whether static (``.a``) or dynamic libraries (``.so``) should be built. On Linux both are built by default.
``CMAKE_BUILD_TYPE`` (``Debug``, ``Release``, ``RelWithDebInfo`` or ``MinSizeRel``)
String option to set the type of build. This will automatically set some compilation flags such as the optimisation level or define ``NDEBUG``.
@ -116,6 +119,8 @@ You need CMake installed so get the binary distribution from `CMake.org <http://
Point the source directory to the directory holding this file and the build directory to the ``build`` subdirectory. Then, click the ``Configure`` button. Click through the dialog box that appears and once you've clicked ``Finish`` you should see text appearing in the bottom text area. Once this has finished, some options will appear in the top area. The purpose of these options in detailed in the Linux→CMake section above. Once you have set these options to what you please, click ``Configure`` again. If it completes without errors then you can click ``Generate`` which will generate your compilers project files in the build directory.
Note that while on Linux it is possible to build both static and dynamic versions of the libraries, this is not possible on Windows. By default static libraries are built. If you want dynamic libraries (``.dll``) then make sure the ``BUILD_STATIC_LIBRARIES`` option is disabled and the ``BUILD_DYNAMIC_LIBRARIES`` option is enabled in the CMake GUI and reconfigure.
Building
--------

View File

@ -31,7 +31,7 @@ FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include)
#There has to be a better way!
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release)
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR})
#Build
ADD_EXECUTABLE(BasicExample ${SRC_FILES})

View File

@ -37,7 +37,7 @@ FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include)
#There has to be a better way!
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release)
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR})
#Build
ADD_EXECUTABLE(OpenGLExample ${SRC_FILES})

View File

@ -33,7 +33,7 @@ FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include)
#There has to be a better way!
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release)
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR})
#Build
ADD_EXECUTABLE(PagingExample ${SRC_FILES})

View File

@ -2,6 +2,35 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(PolyVox)
#By default only build static libraries on Windows but both on Linux
#If we ever require CMake 2.8 then use http://www.kitware.com/blog/home/post/82
option(BUILD_STATIC_LIBRARIES "Build static libraries" ON)
if(WIN32)
option(BUILD_DYNAMIC_LIBRARIES "Build dynamic libraries" OFF)
else()
option(BUILD_DYNAMIC_LIBRARIES "Build dynamic libraries" ON)
endif()
if(WIN32)
#If both are enabled then diable the dyanamic build
if(BUILD_STATIC_LIBRARIES AND BUILD_DYNAMIC_LIBRARIES)
message(STATUS "Building both static and dynamic libraries is not supported on Windows. Disabling dynamic libraries.")
set(BUILD_DYNAMIC_LIBRARIES OFF CACHE BOOL "Build dynamic libraries" FORCE)
endif()
#If both are diabled then re-enable the static build
if(NOT BUILD_STATIC_LIBRARIES AND NOT BUILD_DYNAMIC_LIBRARIES)
message(STATUS "Both dynamic and static libraries were disabled - re-enabling static build.")
set(BUILD_STATIC_LIBRARIES ON CACHE BOOL "Build static libraries" FORCE)
endif()
else()
#It's nonsense to disble both so on Linux, re-enable both.
if(NOT BUILD_STATIC_LIBRARIES AND NOT BUILD_DYNAMIC_LIBRARIES)
message(STATUS "Both dynamic and static libraries were disabled - re-enabling both.")
set(BUILD_STATIC_LIBRARIES ON CACHE BOOL "Build static libraries" FORCE)
set(BUILD_DYNAMIC_LIBRARIES ON CACHE BOOL "Build dynamic libraries" FORCE)
endif()
endif()
#add_subdirectory(bindings)
add_subdirectory(PolyVoxCore)
add_subdirectory(PolyVoxUtil)

View File

@ -80,7 +80,6 @@ SET(IMPL_INC_FILES
)
#NOTE: The following line should be uncommented when building shared libs.
#ADD_DEFINITIONS(-DPOLYVOX_SHARED_EXPORTS) #Export symbols in the .dll
#"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too...
@ -95,20 +94,42 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
#Core
#Build
ADD_LIBRARY(PolyVoxCore STATIC ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES})
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports
ENDIF(MSVC)
IF(BUILD_STATIC_LIBRARIES)
ADD_LIBRARY(PolyVoxCoreStatic STATIC ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES})
SET_TARGET_PROPERTIES(PolyVoxCoreStatic PROPERTIES OUTPUT_NAME "PolyVoxCore")
SET_TARGET_PROPERTIES(PolyVoxCoreStatic PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxCoreStatic PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports
ENDIF(MSVC)
SET(PolyVoxCore_LIBRARY "PolyVoxCoreStatic")
ENDIF()
IF(BUILD_DYNAMIC_LIBRARIES)
ADD_LIBRARY(PolyVoxCoreDynamic SHARED ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES})
SET_TARGET_PROPERTIES(PolyVoxCoreDynamic PROPERTIES OUTPUT_NAME "PolyVoxCore")
SET_TARGET_PROPERTIES(PolyVoxCoreDynamic PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS")
SET_TARGET_PROPERTIES(PolyVoxCoreDynamic PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxCoreDynamic PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports
ENDIF(MSVC)
SET(PolyVoxCore_LIBRARY "PolyVoxCoreDynamic")
ENDIF()
#Install
IF(WIN32)
INSTALL(TARGETS PolyVoxCore
RUNTIME DESTINATION PolyVoxCore/bin
LIBRARY DESTINATION PolyVoxCore/lib
ARCHIVE DESTINATION PolyVoxCore/lib
COMPONENT library
)
IF(BUILD_STATIC_LIBRARIES)
INSTALL(TARGETS PolyVoxCoreStatic
RUNTIME DESTINATION PolyVoxCore/bin COMPONENT library
LIBRARY DESTINATION PolyVoxCore/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxCore/lib COMPONENT library
)
ENDIF()
IF(BUILD_DYNAMIC_LIBRARIES)
INSTALL(TARGETS PolyVoxCoreDynamic
RUNTIME DESTINATION PolyVoxCore/bin COMPONENT library
LIBRARY DESTINATION PolyVoxCore/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxCore/lib COMPONENT library
)
ENDIF()
#Install the core header files, including the ones in the PolyVoxImpl subfolder.
INSTALL(DIRECTORY include DESTINATION PolyVoxCore COMPONENT development PATTERN "*.svn*" EXCLUDE)
@ -118,12 +139,20 @@ IF(WIN32)
#found was: http://www.cmake.org/pipermail/cmake/2007-October/016924.html (and it is a bit ugly).
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../Debug/PolyVoxCore.pdb DESTINATION PolyVoxCore/lib CONFIGURATIONS Debug)
ELSE(WIN32)
INSTALL(TARGETS PolyVoxCore
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
COMPONENT library
)
IF(BUILD_STATIC_LIBRARIES)
INSTALL(TARGETS PolyVoxCoreStatic
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
ENDIF()
IF(BUILD_DYNAMIC_LIBRARIES)
INSTALL(TARGETS PolyVoxCoreDynamic
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
ENDIF()
#Install the core header files, including the ones in the PolyVoxImpl subfolder.
INSTALL(DIRECTORY include/ DESTINATION include/PolyVoxCore COMPONENT development PATTERN "*.svn*" EXCLUDE)

View File

@ -25,25 +25,46 @@ SOURCE_GROUP("Headers" FILES ${UTIL_INC_FILES})
#Tell CMake the paths
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include)
#There has to be a better way!
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release)
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/release ${PolyVoxCore_BINARY_DIR})
#Util
#Build
ADD_LIBRARY(PolyVoxUtil STATIC ${UTIL_SRC_FILES} ${UTIL_INC_FILES})
TARGET_LINK_LIBRARIES(PolyVoxUtil PolyVoxCore)
SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports
ENDIF(MSVC)
IF(BUILD_STATIC_LIBRARIES)
ADD_LIBRARY(PolyVoxUtilStatic STATIC ${UTIL_SRC_FILES} ${UTIL_INC_FILES})
TARGET_LINK_LIBRARIES(PolyVoxUtilStatic PolyVoxCore)
SET_TARGET_PROPERTIES(PolyVoxUtilStatic PROPERTIES OUTPUT_NAME "PolyVoxUtil")
SET_TARGET_PROPERTIES(PolyVoxUtilStatic PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxUtilStatic PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports
ENDIF(MSVC)
ENDIF()
IF(BUILD_DYNAMIC_LIBRARIES)
ADD_LIBRARY(PolyVoxUtilDynamic SHARED ${UTIL_SRC_FILES} ${UTIL_INC_FILES})
TARGET_LINK_LIBRARIES(PolyVoxUtilDynamic PolyVoxCore)
SET_TARGET_PROPERTIES(PolyVoxUtilDynamic PROPERTIES OUTPUT_NAME "PolyVoxUtil")
SET_TARGET_PROPERTIES(PolyVoxUtilDynamic PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS")
SET_TARGET_PROPERTIES(PolyVoxUtilDynamic PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxUtilDynamic PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports
ENDIF(MSVC)
ENDIF()
#Install
IF(WIN32)
INSTALL(TARGETS PolyVoxUtil
RUNTIME DESTINATION PolyVoxUtil/bin
LIBRARY DESTINATION PolyVoxUtil/lib
ARCHIVE DESTINATION PolyVoxUtil/lib
COMPONENT library
)
IF(BUILD_STATIC_LIBRARIES)
INSTALL(TARGETS PolyVoxUtilStatic
RUNTIME DESTINATION PolyVoxUtil/bin COMPONENT library
LIBRARY DESTINATION PolyVoxUtil/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxUtil/lib COMPONENT library
)
ENDIF()
IF(BUILD_DYNAMIC_LIBRARIES)
INSTALL(TARGETS PolyVoxUtilDynamic
RUNTIME DESTINATION PolyVoxUtil/bin COMPONENT library
LIBRARY DESTINATION PolyVoxUtil/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxUtil/lib COMPONENT library
)
ENDIF()
#Install the util header files.
INSTALL(DIRECTORY include DESTINATION PolyVoxUtil COMPONENT development PATTERN "*.svn*" EXCLUDE)
@ -53,12 +74,20 @@ IF(WIN32)
#found was: http://www.cmake.org/pipermail/cmake/2007-October/016924.html (and it is a bit ugly).
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../Debug/PolyVoxUtil.pdb DESTINATION PolyVoxUtil/lib CONFIGURATIONS Debug)
ELSE(WIN32)
INSTALL(TARGETS PolyVoxUtil
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
COMPONENT library
)
IF(BUILD_STATIC_LIBRARIES)
INSTALL(TARGETS PolyVoxUtilStatic
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
ENDIF()
IF(BUILD_DYNAMIC_LIBRARIES)
INSTALL(TARGETS PolyVoxUtilDynamic
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
ENDIF()
#Install the util header files.
INSTALL(DIRECTORY include/ DESTINATION include/PolyVoxUtil COMPONENT development PATTERN "*.svn*" EXCLUDE)

View File

@ -5,6 +5,7 @@
MACRO(CREATE_TEST headerfile sourcefile executablename)
UNSET(test_moc_SRCS) #clear out the MOCs from previous tests
QT4_WRAP_CPP(test_moc_SRCS ${headerfile})
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR} ${PolyVoxUtil_BINARY_DIR})
ADD_EXECUTABLE(${executablename} ${sourcefile} ${test_moc_SRCS})
TARGET_LINK_LIBRARIES(${executablename} PolyVoxCore PolyVoxUtil ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY})
#HACK. This is needed since everything is built in the base dir in Windows. As of 2.8 we should change this.