Build only one of static or shared libraries

As discussed on the forums, to simplify the CMake code and avoid having to
manually specify dependencies this removes the hack to allow both static
and shared libraries to be built at the same time.

It introduces the new variable LIBRARY_TYPE which can be either STATIC or
DYNAMIC.

See: http://www.volumesoffun.com/phpBB3/viewtopic.php?p=3203#p3203
This commit is contained in:
Matt Williams 2012-07-19 17:33:34 +01:00
parent 5d93eef5ac
commit f11b4e17c1
6 changed files with 48 additions and 150 deletions

View File

@ -13,6 +13,12 @@ FIND_PACKAGE(Doxygen)
set_package_properties(Doxygen PROPERTIES URL http://www.doxygen.org DESCRIPTION "API documentation generator" TYPE OPTIONAL PURPOSE "Building the API documentation")
OPTION(ENABLE_EXAMPLES "Should the examples be built" ON)
SET(LIBRARY_TYPE "DYNAMIC" CACHE STRING "Should the library be STATIC or DYNAMIC")
SET_PROPERTY(CACHE LIBRARY_TYPE PROPERTY STRINGS DYNAMIC STATIC)
IF(WIN32)
SET(LIBRARY_TYPE "STATIC")
ENDIF()
# Qt is required for building the tests, the example and optionally for bundling the documentation
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL QtTest)
INCLUDE(${QT_USE_FILE})
@ -42,18 +48,6 @@ IF(ENABLE_EXAMPLES)
ADD_SUBDIRECTORY(examples/Paging)
ADD_SUBDIRECTORY(examples/OpenGL)
ADD_SUBDIRECTORY(examples/SmoothLOD)
if(ENABLE_STATIC_LIBRARIES)
ADD_DEPENDENCIES(BasicExample PolyVoxCoreStatic PolyVoxUtilStatic)
ADD_DEPENDENCIES(PagingExample PolyVoxCoreStatic PolyVoxUtilStatic)
ADD_DEPENDENCIES(OpenGLExample PolyVoxCoreStatic PolyVoxUtilStatic)
ADD_DEPENDENCIES(SmoothLODExample PolyVoxCoreStatic PolyVoxUtilStatic)
endif()
if(ENABLE_DYNAMIC_LIBRARIES)
ADD_DEPENDENCIES(BasicExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
ADD_DEPENDENCIES(PagingExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
ADD_DEPENDENCIES(OpenGLExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
ADD_DEPENDENCIES(SmoothLODExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
endif()
ENDIF(ENABLE_EXAMPLES)
INCLUDE(Packaging.cmake)
@ -74,8 +68,6 @@ ENDIF()
ADD_SUBDIRECTORY(documentation)
add_feature_info("Static libraries" ENABLE_STATIC_LIBRARIES "Will static libraries be built")
add_feature_info("Dynamic libraries" ENABLE_DYNAMIC_LIBRARIES "Will dynamic libraries be built")
add_feature_info("Examples" ENABLE_EXAMPLES "Examples of PolyVox usage")
add_feature_info("Tests" ENABLE_TESTS "Unit tests")
add_feature_info("Bindings" BUILD_BINDINGS "SWIG bindings")
@ -89,8 +81,7 @@ feature_summary(WHAT ALL)
MESSAGE(STATUS "")
MESSAGE(STATUS "Summary")
MESSAGE(STATUS "-------")
MESSAGE(STATUS "Static libraries: " ${ENABLE_STATIC_LIBRARIES})
MESSAGE(STATUS "Dynamic libraries: " ${ENABLE_DYNAMIC_LIBRARIES})
MESSAGE(STATUS "Library type: " ${LIBRARY_TYPE})
MESSAGE(STATUS "Build examples: " ${ENABLE_EXAMPLES})
MESSAGE(STATUS "Build tests: " ${ENABLE_TESTS})
MESSAGE(STATUS "Build bindings: " ${BUILD_BINDINGS})

View File

@ -2,35 +2,6 @@ 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(ENABLE_STATIC_LIBRARIES "Build static libraries" ON)
if(WIN32)
option(ENABLE_DYNAMIC_LIBRARIES "Build dynamic libraries" OFF)
else()
option(ENABLE_DYNAMIC_LIBRARIES "Build dynamic libraries" ON)
endif()
if(WIN32)
#If both are enabled then diable the dyanamic build
if(ENABLE_STATIC_LIBRARIES AND ENABLE_DYNAMIC_LIBRARIES)
message(STATUS "Building both static and dynamic libraries is not supported on Windows. Disabling dynamic libraries.")
set(ENABLE_DYNAMIC_LIBRARIES OFF CACHE BOOL "Build dynamic libraries" FORCE)
endif()
#If both are diabled then re-enable the static build
if(NOT ENABLE_STATIC_LIBRARIES AND NOT ENABLE_DYNAMIC_LIBRARIES)
message(STATUS "Both dynamic and static libraries were disabled - re-enabling static build.")
set(ENABLE_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 ENABLE_STATIC_LIBRARIES AND NOT ENABLE_DYNAMIC_LIBRARIES)
message(STATUS "Both dynamic and static libraries were disabled - re-enabling both.")
set(ENABLE_STATIC_LIBRARIES ON CACHE BOOL "Build static libraries" FORCE)
set(ENABLE_DYNAMIC_LIBRARIES ON CACHE BOOL "Build dynamic libraries" FORCE)
endif()
endif()
add_subdirectory(PolyVoxCore)
add_subdirectory(PolyVoxUtil)
add_subdirectory(bindings)

View File

@ -111,42 +111,26 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
#Core
#Build
IF(ENABLE_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 "/W4 /wd4251 /wd4127") #Disable warning on STL exports
ENDIF(MSVC)
SET(PolyVoxCore_LIBRARY "PolyVoxCoreStatic")
IF(LIBRARY_TYPE STREQUAL "STATIC")
ADD_LIBRARY(PolyVoxCore STATIC ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES})
ENDIF()
IF(ENABLE_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 "/W4 /wd4251 /wd4127") #Disable warning on STL exports
ENDIF(MSVC)
SET(PolyVoxCore_LIBRARY "PolyVoxCoreDynamic")
IF(LIBRARY_TYPE STREQUAL "DYNAMIC")
ADD_LIBRARY(PolyVoxCore SHARED ${CORE_SRC_FILES} ${CORE_INC_FILES} ${IMPL_SRC_FILES} ${IMPL_INC_FILES})
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS")
ENDIF()
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxCore PROPERTIES COMPILE_FLAGS "/W4 /wd4251 /wd4127") #Disable warning on STL exports
ENDIF(MSVC)
#Install
IF(WIN32)
IF(ENABLE_STATIC_LIBRARIES)
INSTALL(TARGETS PolyVoxCoreStatic
INSTALL(TARGETS PolyVoxCore
RUNTIME DESTINATION PolyVoxCore/bin COMPONENT library
LIBRARY DESTINATION PolyVoxCore/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxCore/lib COMPONENT library
)
ENDIF()
IF(ENABLE_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)
@ -157,20 +141,11 @@ IF(WIN32)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/PolyVoxCore.pdb DESTINATION PolyVoxCore/lib CONFIGURATIONS Debug)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/PolyVoxCore.pdb DESTINATION PolyVoxCore/lib CONFIGURATIONS RelWithDebInfo)
ELSE(WIN32)
IF(ENABLE_STATIC_LIBRARIES)
INSTALL(TARGETS PolyVoxCoreStatic
INSTALL(TARGETS PolyVoxCore
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
ENDIF()
IF(ENABLE_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

@ -29,44 +29,27 @@ LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/debug ${PolyVoxCore_BINARY_DIR}/relea
#Util
#Build
IF(ENABLE_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)
IF(LIBRARY_TYPE STREQUAL "STATIC")
ADD_LIBRARY(PolyVoxUtil STATIC ${UTIL_SRC_FILES} ${UTIL_INC_FILES})
ENDIF()
IF(LIBRARY_TYPE STREQUAL "DYNAMIC")
ADD_LIBRARY(PolyVoxUtil SHARED ${UTIL_SRC_FILES} ${UTIL_INC_FILES})
SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS")
ENDIF()
TARGET_LINK_LIBRARIES(PolyVoxUtil PolyVoxCore)
SET_TARGET_PROPERTIES(PolyVoxUtil PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR})
IF(MSVC)
SET_TARGET_PROPERTIES(PolyVoxUtilStatic PROPERTIES COMPILE_FLAGS "/W4 /wd4251 /wd4127") #Disable warning on STL exports
ENDIF(MSVC)
ADD_DEPENDENCIES(PolyVoxUtilStatic PolyVoxCoreStatic)
ENDIF()
IF(ENABLE_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 "/W4 /wd4251 /wd4127") #Disable warning on STL exports
ENDIF(MSVC)
ADD_DEPENDENCIES(PolyVoxUtilDynamic PolyVoxCoreDynamic)
ENDIF()
ENDIF(MSVC)
#Install
IF(WIN32)
IF(ENABLE_STATIC_LIBRARIES)
INSTALL(TARGETS PolyVoxUtilStatic
INSTALL(TARGETS PolyVoxUtil
RUNTIME DESTINATION PolyVoxUtil/bin COMPONENT library
LIBRARY DESTINATION PolyVoxUtil/lib COMPONENT library
ARCHIVE DESTINATION PolyVoxUtil/lib COMPONENT library
)
ENDIF()
IF(ENABLE_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)
@ -77,20 +60,11 @@ IF(WIN32)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/PolyVoxUtil.pdb DESTINATION PolyVoxUtil/lib CONFIGURATIONS Debug)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/PolyVoxUtil.pdb DESTINATION PolyVoxUtil/lib CONFIGURATIONS RelWithDebInfo)
ELSE(WIN32)
IF(ENABLE_STATIC_LIBRARIES)
INSTALL(TARGETS PolyVoxUtilStatic
INSTALL(TARGETS PolyVoxUtil
RUNTIME DESTINATION bin COMPONENT library
LIBRARY DESTINATION lib COMPONENT library
ARCHIVE DESTINATION lib COMPONENT library
)
ENDIF()
IF(ENABLE_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

@ -19,13 +19,6 @@ if(ENABLE_BINDINGS)
swig_add_module(PolyVoxCore python PolyVoxCore.i)
swig_link_libraries(PolyVoxCore ${PYTHON_LIBRARIES} PolyVoxCore)
#set_target_properties(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PROPERTIES SUFFIX ".pyd")
if(ENABLE_STATIC_LIBRARIES)
ADD_DEPENDENCIES(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PolyVoxCoreStatic PolyVoxUtilStatic)
endif()
if(ENABLE_DYNAMIC_LIBRARIES)
ADD_DEPENDENCIES(${SWIG_MODULE_PolyVoxCore_REAL_NAME} PolyVoxCoreDynamic PolyVoxUtilDynamic)
endif()
endif()
else()
set(BUILD_BINDINGS OFF CACHE BOOL "Will the bindings be built" FORCE)

View File

@ -14,12 +14,6 @@ MACRO(CREATE_TEST headerfile sourcefile executablename)
ELSE(WIN32)
SET(LATEST_TEST ${CMAKE_CURRENT_BINARY_DIR}/${executablename})
ENDIF(WIN32)
if(ENABLE_STATIC_LIBRARIES)
ADD_DEPENDENCIES(${executablename} PolyVoxCoreStatic PolyVoxUtilStatic)
endif()
if(ENABLE_DYNAMIC_LIBRARIES)
ADD_DEPENDENCIES(${executablename} PolyVoxCoreDynamic PolyVoxUtilDynamic)
endif()
ENDMACRO(CREATE_TEST)
IF(NOT QT_QTTEST_FOUND)