use BUILD_SHARED_LIBS and target_sources()
This commit is contained in:
parent
6767549042
commit
ff2444b3cb
@ -31,12 +31,19 @@ project(nana VERSION 1.6.1
|
||||
|
||||
|
||||
|
||||
####################### Main setting of Nana sources, targets and install
|
||||
option(BUILD_SHARED_LIBS "Compile nana as a shared library." OFF)
|
||||
|
||||
####################### Main setting of Nana targets, sources and installs
|
||||
|
||||
|
||||
add_library(${PROJECT_NAME} )
|
||||
|
||||
|
||||
set(NANA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source)
|
||||
set(NANA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
# collect all source sub-directories in a list to avoid duplication here
|
||||
set(NANA_SOURCE_SUBDIRS /.
|
||||
set(NANA_SOURCE_SUBDIRS
|
||||
/.
|
||||
/detail
|
||||
/filesystem
|
||||
/gui
|
||||
@ -49,7 +56,8 @@ set(NANA_SOURCE_SUBDIRS /.
|
||||
/threads
|
||||
)
|
||||
if(NANA_CMAKE_ENABLE_AUDIO)
|
||||
list(APPEND NANA_SOURCE_SUBDIRS /audio
|
||||
list(APPEND NANA_SOURCE_SUBDIRS
|
||||
/audio
|
||||
/audio/detail
|
||||
)
|
||||
endif()
|
||||
@ -60,18 +68,7 @@ foreach(subdir ${NANA_SOURCE_SUBDIRS})
|
||||
aux_source_directory(${NANA_SOURCE_DIR}${subdir} SOURCES)
|
||||
endforeach()
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||
add_definitions(-fmax-errors=3)
|
||||
endif()
|
||||
|
||||
set(CMAKE_DEBUG_POSTFIX "_d")
|
||||
|
||||
if(NANA_CMAKE_SHARED_LIB)
|
||||
add_library(${PROJECT_NAME} SHARED ${SOURCES})
|
||||
else()
|
||||
add_library(${PROJECT_NAME} STATIC ${SOURCES})
|
||||
endif()
|
||||
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${NANA_INCLUDE_DIR})
|
||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14) #
|
||||
target_link_libraries(${PROJECT_NAME} ${NANA_LINKS})
|
||||
@ -84,7 +81,6 @@ option(NANA_CMAKE_LIBPNG_FROM_OS "Use libpng from operating system." ON)
|
||||
option(NANA_CMAKE_ENABLE_JPEG "Enable the use of JPEG" OFF)
|
||||
option(NANA_CMAKE_LIBJPEG_FROM_OS "Use libjpeg from operating system." ON)
|
||||
option(NANA_CMAKE_ENABLE_AUDIO "Enable class audio::play for PCM playback." OFF)
|
||||
option(NANA_CMAKE_SHARED_LIB "Compile nana as a shared library." OFF)
|
||||
option(NANA_CMAKE_VERBOSE_PREPROCESSOR "Show annoying debug messages during compilation." ON)
|
||||
option(NANA_CMAKE_STOP_VERBOSE_PREPROCESSOR "Stop compilation after showing the annoying debug messages." OFF)
|
||||
option(NANA_CMAKE_AUTOMATIC_GUI_TESTING "Activate automatic GUI testing?" OFF)
|
||||
@ -297,20 +293,11 @@ elseif(NANA_CMAKE_FIND_BOOST_FILESYSTEM OR NANA_CMAKE_BOOST_FILESYSTEM_FORCE)
|
||||
endif()
|
||||
|
||||
|
||||
######## Nana options
|
||||
|
||||
add_definitions(-DNANA_IGNORE_CONF)
|
||||
if(NANA_CMAKE_VERBOSE_PREPROCESSOR)
|
||||
add_definitions(-DVERBOSE_PREPROCESSOR)
|
||||
endif()
|
||||
if(NANA_CMAKE_AUTOMATIC_GUI_TESTING)
|
||||
add_definitions(-DNANA_AUTOMATIC_GUI_TESTING)
|
||||
enable_testing()
|
||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||
add_definitions(-fmax-errors=3)
|
||||
endif()
|
||||
|
||||
|
||||
# Headers: use INCLUDE_DIRECTORIES
|
||||
# Libraries: use FIND_LIBRARY and link with the result of it (try to avoid LINK_DIRECTORIES)
|
||||
set(CMAKE_DEBUG_POSTFIX "_d")
|
||||
|
||||
# Installing: the static "nana lib" will be in DESTDIR/CMAKE_INSTALL_PREFIX/lib/
|
||||
# and the includes files "include/nana/" in DESTDIR/CMAKE_INSTALL_PREFIX/include/nana/
|
||||
@ -352,7 +339,12 @@ endif()
|
||||
|
||||
|
||||
# Just for information:
|
||||
include(CMakePrintHelpers)
|
||||
|
||||
message ("")
|
||||
cmake_print_variables(SOURCES)
|
||||
|
||||
|
||||
message ( "CMAKE_CXX_COMPILER_ID = " ${CMAKE_CXX_COMPILER_ID})
|
||||
message ( "COMPILER_IS_CLANG = " ${COMPILER_IS_CLANG})
|
||||
message ( "CMAKE_COMPILER_IS_GNUCXX = " ${CMAKE_COMPILER_IS_GNUCXX})
|
||||
|
Loading…
x
Reference in New Issue
Block a user