reorganize cmake in small scripts with some fix from https://github.com/cnjinhao/nana/pull/278
This commit is contained in:
parent
b430f82855
commit
2e6a85bf89
235
CMakeLists.txt
235
CMakeLists.txt
@ -1,5 +1,4 @@
|
||||
# CMake configuration for Nana
|
||||
# Author: Andrew Kornilov(https://github.com/ierofant)
|
||||
# Contributors:
|
||||
# Andrew Kornilov (ierofant) - original version
|
||||
# Jinhao
|
||||
@ -8,7 +7,7 @@
|
||||
# Robert Hauck - Enable support for PNG/Freetype
|
||||
# Pavel O. - fix compilation with boost::filesystem (#281)
|
||||
# Frostbane - Add option for compiling a shared library (#263,#265)
|
||||
# Qiangqiang Wu - Add biicode support
|
||||
# Qiangqiang Wu - Add biicode support: todo migrate to https://conan.io/
|
||||
#
|
||||
# Nana uses some build systems: MS-VS solution, MAKE, bakefile, codeblock, etc. manually optimized.
|
||||
# Maybe CMake will be used in the future to generate some of them in the central nana repository.
|
||||
@ -20,6 +19,7 @@
|
||||
# https://cliutils.gitlab.io/modern-cmake/
|
||||
# https://cmake.org/cmake-tutorial/
|
||||
# https://cmake.org/cmake/help/v3.12/module/CMakeDependentOption.html?highlight=cmakedependentoption
|
||||
# cmake 3.12 have more better modern c++ support
|
||||
|
||||
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
|
||||
project(nana VERSION 1.6.2
|
||||
@ -27,15 +27,27 @@ project(nana VERSION 1.6.2
|
||||
HOMEPAGE_URL http://nanapro.org
|
||||
LANGUAGES CXX )
|
||||
|
||||
|
||||
option(BUILD_SHARED_LIBS "Compile nana as a shared library." OFF)
|
||||
|
||||
####################### Main setting of Nana targets, sources and installs
|
||||
####################### Main setting of Nana targets, sources and installs #####################
|
||||
|
||||
add_library(nana)
|
||||
target_compile_features(nana PUBLIC cxx_std_14)
|
||||
target_compile_features(nana PUBLIC cxx_std_17)
|
||||
|
||||
### collect all source sub-directories in a list to avoid duplication here
|
||||
# need after cxx_std_14 or cxx_std_17 ??
|
||||
target_compile_features(nana
|
||||
PUBLIC cxx_nullptr
|
||||
PUBLIC cxx_range_for
|
||||
PUBLIC cxx_lambdas
|
||||
PUBLIC cxx_decltype_auto
|
||||
PUBLIC cxx_defaulted_functions
|
||||
PUBLIC cxx_deleted_functions
|
||||
PUBLIC cxx_auto_type
|
||||
PUBLIC cxx_decltype_incomplete_return_types
|
||||
PUBLIC cxx_defaulted_move_initializers
|
||||
PUBLIC cxx_noexcept
|
||||
PUBLIC cxx_rvalue_references
|
||||
)
|
||||
|
||||
### collect all source sub-directories in a list to avoid duplication ###
|
||||
|
||||
# By using CMAKE_CURRENT_LIST_DIR here you can compile and consume nana by just:
|
||||
# add_subdirectory(../nana ../cmake-nana-build-${CONFIG} ) or simmilar
|
||||
@ -71,8 +83,7 @@ endforeach()
|
||||
|
||||
target_sources(nana PRIVATE ${SOURCES})
|
||||
|
||||
|
||||
### collect all headers sub-directories in a list to avoid duplication here ??
|
||||
### collect all headers sub-directories in a list to avoid duplication ###
|
||||
# To show .h files in Visual Studio, add them to the list of sources in add_executable / add_library / target_sources
|
||||
# and Use SOURCE_GROUP if all your sources are in the same directory
|
||||
set(NANA_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include)
|
||||
@ -101,39 +112,11 @@ foreach(subdir ${NANA_INCLUDE_SUBDIRS})
|
||||
aux_source_directory(${NANA_INCLUDE_DIR}/nana${subdir} HEADERS) # todo: use GLOB to add headers too !!!!!!!
|
||||
endforeach()
|
||||
|
||||
|
||||
option(NANA_CMAKE_INSTALL "Install nana when compile the library" OFF)
|
||||
option(NANA_CMAKE_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ "replaced boost.thread with meganz's mingw-std-threads." OFF)
|
||||
option(NANA_CMAKE_VERBOSE_PREPROCESSOR "Show annoying debug messages during compilation." ON)
|
||||
### Some nana compilation options ###
|
||||
option(NANA_CMAKE_VERBOSE_PREPROCESSOR "Show annoying debug messages during compilation." OFF)
|
||||
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)
|
||||
|
||||
|
||||
# Install the include directories too.
|
||||
if(NANA_CMAKE_INSTALL)
|
||||
# this is the prefered method to consume nana directly with some specific bulid system
|
||||
# Is your responsability to ensure all compiler options are compatible with the compilation
|
||||
# of the project linking to the nana lib here generated
|
||||
target_sources(nana PRIVATE ${HEADERS})
|
||||
target_include_directories(nana PRIVATE ${NANA_INCLUDE_DIR})
|
||||
message("The compiled Nana library will be installed in ${CMAKE_INSTALL_PREFIX}/lib")
|
||||
# Actually in DESTDIR/CMAKE_INSTALL_PREFIX/lib but in windows there is no DESTDIR/ part.
|
||||
install(TARGETS nana
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
RUNTIME DESTINATION bin)
|
||||
install(DIRECTORY ${NANA_INCLUDE_DIR}/nana DESTINATION include) # in ${CMAKE_INSTALL_PREFIX}/include/nana
|
||||
message("The Nana include files will be installed in ${CMAKE_INSTALL_PREFIX}/include")
|
||||
else()
|
||||
# this is the prefered method to consume nana with cmake
|
||||
target_sources(nana PUBLIC ${HEADERS})
|
||||
target_include_directories(nana PUBLIC ${NANA_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
|
||||
if(BUILD_SHARED_LIBS) # ??
|
||||
include(build/cmake/shared_libs.cmake)
|
||||
endif()
|
||||
option(NANA_CMAKE_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ "replaced boost.thread with meganz's mingw-std-threads." OFF) # deprecate?
|
||||
|
||||
######## Nana options
|
||||
|
||||
@ -146,160 +129,42 @@ if(NANA_CMAKE_AUTOMATIC_GUI_TESTING)
|
||||
# todo: enable_testing() # ??
|
||||
endif()
|
||||
|
||||
########### OS
|
||||
# https://blog.kowalczyk.info/article/j/guide-to-predefined-macros-in-c-compilers-gcc-clang-msvc-etc..html
|
||||
# http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
|
||||
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/build/cmake/Modules)
|
||||
include(build/cmake/install_nana.cmake) # includes and libs, or just expose the nana target
|
||||
include(build/cmake/OS.cmake) # windows, unix, linux, apple, ...
|
||||
include(build/cmake/shared_libs.cmake) # static and shared
|
||||
include(build/cmake/compilers.cmake) # VC, gcc, clang
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(nana PUBLIC WIN32) # todo: why not simple test for _WIN32 in code??
|
||||
set(CMAKE_DEBUG_POSTFIX "_d")
|
||||
# Global MSVC definitions. You may prefer the hand-tuned sln and projects from the nana repository.
|
||||
if(MSVC)
|
||||
option(MSVC_USE_MP "Set to ON to build nana with the /MP option (Visual Studio 2005 and above)." ON)
|
||||
option(MSVC_USE_STATIC_RUNTIME "Set to ON to build nana with the /MT(d) option." ON)
|
||||
|
||||
# Change the MSVC Compiler flags
|
||||
if(MSVC_USE_MP)
|
||||
target_compile_options(nana PUBLIC "/MP" )
|
||||
endif()
|
||||
|
||||
if(MSVC_USE_STATIC_RUNTIME)
|
||||
foreach(flag
|
||||
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
||||
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
if(NANA_CMAKE_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ) # deprecated ?????
|
||||
target_compile_definitions(nana PUBLIC STD_THREAD_NOT_SUPPORTED)
|
||||
target_compile_definitions(nana PUBLIC NANA_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
target_compile_definitions(nana PUBLIC APPLE) # ??? not added by compilers? use __APPLE__ ?
|
||||
target_include_directories(nana PUBLIC /opt/X11/include/)
|
||||
target_link_libraries(nana PRIVATE iconv)
|
||||
set(ENABLE_AUDIO OFF)
|
||||
elseif(UNIX)
|
||||
target_compile_definitions(nana PUBLIC linux) # todo: eliminate. Added by compilers. Also __linux posible
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
find_package(X11 REQUIRED)
|
||||
target_link_libraries(nana
|
||||
PUBLIC ${X11_LIBRARIES}
|
||||
PUBLIC ${X11_Xft_LIB}
|
||||
)
|
||||
target_include_directories(nana SYSTEM
|
||||
PUBLIC ${X11_Xft_INCLUDE_PATH}
|
||||
PUBLIC ${X11_INCLUDE_DIR}
|
||||
)
|
||||
find_package(Freetype)
|
||||
if (FREETYPE_FOUND)
|
||||
find_package(Fontconfig REQUIRED)
|
||||
target_include_directories(nana SYSTEM
|
||||
PUBLIC ${FREETYPE_INCLUDE_DIRS}
|
||||
PUBLIC ${FONTCONFIG_INCLUDE_DIR}
|
||||
)
|
||||
target_link_libraries(nana
|
||||
PUBLIC ${FREETYPE_LIBRARIES}
|
||||
PUBLIC ${FONTCONFIG_LIBRARIES}
|
||||
)
|
||||
endif(FREETYPE_FOUND)
|
||||
endif(UNIX)
|
||||
|
||||
|
||||
########### Compilers
|
||||
#
|
||||
# Using gcc: gcc 4.8 don't support C++14 and make_unique. You may want to update at least to 4.9.
|
||||
# gcc 5.3 and 5.4 include filesytem, but you need to add the link flag: -lstdc++fs
|
||||
#
|
||||
# In Windows, with CLion Allways check in File/Settings.../toolchains
|
||||
# You could install MinGW-w64 from the TDM-GCC Compiler Suite for Windows which will update you to gcc 5.1.
|
||||
# It is posible to follow https://computingabdn.com/softech/mingw-howto-install-gcc-for-windows/
|
||||
# and install MinGW with gcc 7.1 with has STD_THREADS and fs, from: https://sourceforge.net/projects/mingw-w64/files/
|
||||
#
|
||||
# see at end of: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dynamic_or_shared.html
|
||||
#
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
|
||||
target_compile_options(nana PRIVATE -Wall)
|
||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
if("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
|
||||
target_compile_options(nana PUBLIC -I/usr/local/include)
|
||||
endif()
|
||||
endif()
|
||||
# set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
# find_package(Threads REQUIRED)
|
||||
# target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_options(nana PUBLIC -lgcc -lstdc++)
|
||||
else()
|
||||
|
||||
if(MINGW)
|
||||
target_compile_options(nana PUBLIC -static) # -static ?? cmake knows BUILD_SHARED_LIBS
|
||||
else()
|
||||
target_compile_options(nana PUBLIC -static-libgcc -static-libstdc++)
|
||||
endif()
|
||||
endif(BUILD_SHARED_LIBS)
|
||||
# target_link_libraries(nana PRIVATE stdc++fs) # ??
|
||||
|
||||
target_compile_options(nana PUBLIC -pthread)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
if (APPLE AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # APPLE Clang
|
||||
target_compile_options(nana PUBLIC -stdlib=libstdc++)
|
||||
endif ()
|
||||
|
||||
|
||||
############# Optional libraries
|
||||
############# Optional libraries #####################
|
||||
include(build/cmake/enable_png.cmake)
|
||||
include(build/cmake/enable_jpeg.cmake)
|
||||
include(build/cmake/enable_audio.cmake)
|
||||
include(build/cmake/select_filesystem.cmake)
|
||||
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||
target_compile_options(nana PRIVATE -fmax-errors=3)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
target_compile_features(${PROJECT_NAME}
|
||||
PUBLIC cxx_nullptr
|
||||
PUBLIC cxx_range_for
|
||||
PUBLIC cxx_lambdas
|
||||
PUBLIC cxx_decltype_auto
|
||||
PUBLIC cxx_defaulted_functions
|
||||
PUBLIC cxx_deleted_functions
|
||||
PUBLIC cxx_auto_type
|
||||
PUBLIC cxx_decltype_incomplete_return_types
|
||||
PUBLIC cxx_defaulted_move_initializers
|
||||
PUBLIC cxx_noexcept
|
||||
PUBLIC cxx_rvalue_references
|
||||
### Just for information: ########################################
|
||||
include(CMakePrintHelpers)
|
||||
# see: https://cmake.org/cmake/help/v3.12/manual/cmake-properties.7.html#properties-on-targets
|
||||
cmake_print_properties(TARGETS nana PROPERTIES
|
||||
COMPILE_DEFINITIONS COMPILE_OPTIONS COMPILE_FLAGS LINK_LIBRARIES
|
||||
INCLUDE_DIRECTORIES INSTALL_NAME_DIR LINK_FLAGS VERSION
|
||||
)
|
||||
|
||||
# Just for information:
|
||||
include(CMakePrintHelpers)
|
||||
|
||||
message ("")
|
||||
#message ("")
|
||||
# cmake_print_variables(SOURCES)
|
||||
cmake_print_variables(HEADERS)
|
||||
cmake_print_variables(PUBLIC_HEADERS)
|
||||
cmake_print_variables(NANA_CMAKE_INSTALL)
|
||||
|
||||
cmake_print_variables(Boost_INCLUDE_DIR)
|
||||
cmake_print_variables(Boost_LIBRARIES)
|
||||
cmake_print_variables(Boost::filesystem)
|
||||
|
||||
cmake_print_variables(PNG_INCLUDE_DIRS)
|
||||
cmake_print_variables(PNG_LIBRARIES)
|
||||
cmake_print_variables(PNG::PNG)
|
||||
|
||||
|
||||
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})
|
||||
@ -307,14 +172,6 @@ message ( "CMAKE_CXX_FLAGS = " ${CMAKE_CXX_FLAGS})
|
||||
message ( "CMAKE_EXE_LINKER_FLAGS = " ${CMAKE_EXE_LINKER_FLAGS})
|
||||
message ( "CMAKE_STATIC_LINKER_FLAGS = " ${CMAKE_STATIC_LINKER_FLAGS})
|
||||
|
||||
|
||||
# see: https://cmake.org/cmake/help/v3.12/manual/cmake-properties.7.html#properties-on-targets
|
||||
cmake_print_properties(TARGETS nana PROPERTIES
|
||||
COMPILE_DEFINITIONS COMPILE_OPTIONS COMPILE_FLAGS LINK_LIBRARIES
|
||||
INCLUDE_DIRECTORIES INSTALL_NAME_DIR LINK_FLAGS VERSION
|
||||
)
|
||||
|
||||
|
||||
message ( "DESTDIR = " ${DESTDIR})
|
||||
message ( "CMAKE_INSTALL_PREFIX = " ${CMAKE_INSTALL_PREFIX})
|
||||
message ( "NANA_INCLUDE_DIR = " ${NANA_INCLUDE_DIR})
|
||||
|
||||
70
build/cmake/OS.cmake
Normal file
70
build/cmake/OS.cmake
Normal file
@ -0,0 +1,70 @@
|
||||
########### OS
|
||||
# https://blog.kowalczyk.info/article/j/guide-to-predefined-macros-in-c-compilers-gcc-clang-msvc-etc..html
|
||||
# http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(nana PUBLIC WIN32) # todo: why not simple test for _WIN32 in code??
|
||||
set(CMAKE_DEBUG_POSTFIX "_d") # ??
|
||||
# Global MSVC definitions. You may prefer the hand-tuned sln and projects from the nana repository.
|
||||
if(MSVC)
|
||||
option(MSVC_USE_MP "Set to ON to build nana with the /MP option (Visual Studio 2005 and above)." ON)
|
||||
option(MSVC_USE_STATIC_RUNTIME "Set to ON to build nana with the /MT(d) option." ON)
|
||||
|
||||
# Change the MSVC Compiler flags
|
||||
if(MSVC_USE_MP)
|
||||
target_compile_options(nana PUBLIC "/MP" )
|
||||
endif()
|
||||
|
||||
if(MSVC_USE_STATIC_RUNTIME)
|
||||
foreach(flag
|
||||
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
||||
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
if(NANA_CMAKE_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ) # deprecated ?????
|
||||
target_compile_definitions(nana PUBLIC STD_THREAD_NOT_SUPPORTED
|
||||
PUBLIC NANA_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ )
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
target_compile_definitions(nana PUBLIC APPLE) # ??? not added by compilers? use __APPLE__ ?
|
||||
target_include_directories(nana PUBLIC /opt/X11/include/)
|
||||
target_link_libraries(nana PRIVATE iconv)
|
||||
set(ENABLE_AUDIO OFF)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
|
||||
find_package(X11 REQUIRED) # X11 - todo test PRIVATE
|
||||
target_link_libraries(nana
|
||||
PUBLIC ${X11_LIBRARIES}
|
||||
PUBLIC ${X11_Xft_LIB}
|
||||
)
|
||||
target_include_directories(nana SYSTEM
|
||||
PUBLIC ${X11_Xft_INCLUDE_PATH}
|
||||
PUBLIC ${X11_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
find_package(Freetype) # Freetype - todo test PRIVATE
|
||||
if (FREETYPE_FOUND)
|
||||
find_package(Fontconfig REQUIRED)
|
||||
target_include_directories(nana SYSTEM
|
||||
PUBLIC ${FREETYPE_INCLUDE_DIRS}
|
||||
PUBLIC ${FONTCONFIG_INCLUDE_DIR}
|
||||
)
|
||||
target_link_libraries(nana
|
||||
PUBLIC ${FREETYPE_LIBRARIES}
|
||||
PUBLIC ${FONTCONFIG_LIBRARIES}
|
||||
)
|
||||
endif(FREETYPE_FOUND)
|
||||
endif(UNIX)
|
||||
48
build/cmake/compilers.cmake
Normal file
48
build/cmake/compilers.cmake
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
########### Compilers
|
||||
#
|
||||
# Using gcc: gcc 4.8 don't support C++14 and make_unique. You may want to update at least to 4.9.
|
||||
# gcc 5.3 and 5.4 include filesytem, but you need to add the link flag: -lstdc++fs
|
||||
#
|
||||
# In Windows, with CLion Allways check in File/Settings.../toolchains
|
||||
# You could install MinGW-w64 from the TDM-GCC Compiler Suite for Windows which will update you to gcc 5.1.
|
||||
# It is posible to follow https://computingabdn.com/softech/mingw-howto-install-gcc-for-windows/
|
||||
# and install MinGW with gcc 7.1 with has STD_THREADS and fs, from: https://sourceforge.net/projects/mingw-w64/files/
|
||||
#
|
||||
# see at end of: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dynamic_or_shared.html
|
||||
#
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AND NOT MINGW??
|
||||
|
||||
target_compile_options(nana PRIVATE -Wall
|
||||
PUBLIC -g )
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON) # todo - test this
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(nana PRIVATE Threads::Threads)
|
||||
# target_compile_options(nana PUBLIC -pthread)
|
||||
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
if("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
|
||||
target_compile_options(nana PUBLIC -I/usr/local/include)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# target_link_libraries(nana PRIVATE stdc++fs) # ??
|
||||
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
if (APPLE AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # APPLE Clang
|
||||
target_compile_options(nana PUBLIC -stdlib=libstdc++)
|
||||
endif ()
|
||||
|
||||
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||
target_compile_options(nana PRIVATE -fmax-errors=3)
|
||||
endif()
|
||||
|
||||
@ -4,10 +4,10 @@ option(NANA_CMAKE_ENABLE_AUDIO "Enable class audio::play for PCM playback." OFF)
|
||||
if(NANA_CMAKE_ENABLE_AUDIO)
|
||||
target_compile_definitions(nana PUBLIC NANA_ENABLE_AUDIO)
|
||||
if(UNIX)
|
||||
find_package(ASOUND)
|
||||
find_package(ASOUND) # ? https://github.com/hintjens/demidi/blob/master/Findasound.cmake
|
||||
if(ASOUND_FOUND)
|
||||
target_include_directories(nana PUBLIC ${ASOUND_INCLUDE_DIRS})
|
||||
target_link_libraries(nana PUBLIC ${ASOUND_LIBRARY})
|
||||
target_link_libraries(nana PUBLIC ${ASOUND_LIBRARIES})
|
||||
else()
|
||||
message(FATAL_ERROR "libasound is not found")
|
||||
endif()
|
||||
|
||||
@ -9,8 +9,8 @@ if(NANA_CMAKE_ENABLE_JPEG)
|
||||
if(NANA_CMAKE_LIBJPEG_FROM_OS)
|
||||
find_package(JPEG)
|
||||
if(JPEG_FOUND)
|
||||
target_include_directories(nana PUBLIC ${JPEG_INCLUDE_DIR})
|
||||
target_link_libraries (nana PUBLIC ${JPEG_LIBRARY})
|
||||
target_include_directories(nana PUBLIC ${JPEG_INCLUDE_DIRS})
|
||||
target_link_libraries (nana PUBLIC ${JPEG_LIBRARIES})
|
||||
target_compile_definitions(nana PUBLIC USE_LIBJPEG_FROM_OS)
|
||||
endif()
|
||||
else()
|
||||
|
||||
@ -11,8 +11,10 @@ if(NANA_CMAKE_ENABLE_PNG)
|
||||
target_include_directories(nana PUBLIC ${PNG_INCLUDE_DIRS})
|
||||
target_link_libraries (nana PUBLIC ${PNG_LIBRARIES})
|
||||
target_compile_definitions(nana PUBLIC USE_LIBPNG_FROM_OS ${PNG_DEFINITIONS})
|
||||
# target_include_directories (nana SYSTEM PUBLIC PNG::PNG) # ??
|
||||
# target_compile_definitions (nana PUBLIC USE_LIBPNG_FROM_OS)
|
||||
endif()
|
||||
else()
|
||||
target_compile_definitions(nana PUBLIC -lpng)
|
||||
target_link_libraries(nana PUBLIC png) # provided by nana?
|
||||
endif()
|
||||
endif()
|
||||
23
build/cmake/install_nana.cmake
Normal file
23
build/cmake/install_nana.cmake
Normal file
@ -0,0 +1,23 @@
|
||||
option(NANA_CMAKE_INSTALL "Install nana when compile the library (to be consumed without cmake)" OFF)
|
||||
|
||||
# Install the include directories too.
|
||||
if(NANA_CMAKE_INSTALL)
|
||||
# this is the prefered method to consume nana directly with some specific bulid system
|
||||
# Is your responsability to ensure all compiler options are compatible with the compilation
|
||||
# of the project linking to the nana lib here generated
|
||||
target_sources(nana PRIVATE ${HEADERS})
|
||||
target_include_directories(nana PRIVATE ${NANA_INCLUDE_DIR})
|
||||
message("The compiled Nana library will be installed in ${CMAKE_INSTALL_PREFIX}/lib")
|
||||
# Actually in DESTDIR/CMAKE_INSTALL_PREFIX/lib but in windows there is no DESTDIR/ part.
|
||||
install(TARGETS nana
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
RUNTIME DESTINATION bin)
|
||||
install(DIRECTORY ${NANA_INCLUDE_DIR}/nana DESTINATION include) # in ${CMAKE_INSTALL_PREFIX}/include/nana
|
||||
message("The Nana include files will be installed in ${CMAKE_INSTALL_PREFIX}/include")
|
||||
else()
|
||||
# this is the prefered method to consume nana with cmake
|
||||
target_sources(nana PUBLIC ${HEADERS})
|
||||
target_include_directories(nana PUBLIC ${NANA_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
@ -21,27 +21,33 @@ if(NANA_CMAKE_NANA_FILESYSTEM_FORCE)
|
||||
|
||||
elseif(NANA_CMAKE_STD_FILESYSTEM_FORCE)
|
||||
target_compile_definitions(nana PUBLIC STD_FILESYSTEM_FORCE)
|
||||
target_compile_options (nana PUBLIC -lstdc++fs)
|
||||
target_link_libraries (nana PUBLIC stdc++fs)
|
||||
|
||||
elseif(NANA_CMAKE_FIND_BOOST_FILESYSTEM OR NANA_CMAKE_BOOST_FILESYSTEM_FORCE)
|
||||
if(NANA_CMAKE_BOOST_FILESYSTEM_FORCE)
|
||||
elseif(NANA_CMAKE_BOOST_FILESYSTEM_FORCE)
|
||||
target_compile_definitions(nana PUBLIC BOOST_FILESYSTEM_FORCE)
|
||||
else()
|
||||
target_compile_options (nana PUBLIC -lstdc++fs)
|
||||
endif()
|
||||
|
||||
# https://cmake.org/cmake/help/git-master/module/FindBoost.html
|
||||
# Implicit dependencies such as Boost::filesystem requiring Boost::system will be automatically detected and satisfied,
|
||||
# even if system is not specified when using find_package and if Boost::system is not added to target_link_libraries.
|
||||
# If using Boost::thread, then Thread::Thread will also be added automatically.
|
||||
find_package(Boost COMPONENTS filesystem)
|
||||
find_package(Boost REQUIRED COMPONENTS filesystem)
|
||||
if(Boost_FOUND)
|
||||
target_compile_definitions(nana PUBLIC BOOST_FILESYSTEM_AVAILABLE)
|
||||
target_include_directories(nana PUBLIC "${Boost_INCLUDE_DIR}") # ?? SYSTEM
|
||||
target_link_libraries (nana PUBLIC ${Boost_LIBRARIES})
|
||||
# target_link_libraries (nana PUBLIC Boost::Boost)
|
||||
endif()
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
set(Boost_USE_STATIC_RUNTIME ON)
|
||||
|
||||
else()
|
||||
# todo test for std (for now just force nana or boost if there no std)
|
||||
target_link_libraries (nana PUBLIC stdc++fs)
|
||||
|
||||
# todo if not test for boost
|
||||
# if not add nana filesystem
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
|
||||
option(BUILD_SHARED_LIBS "Compile nana as a shared library." OFF)
|
||||
|
||||
if(BUILD_SHARED_LIBS) # todo test
|
||||
|
||||
if(WIN32)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
if(MSVC)
|
||||
@ -28,3 +33,19 @@
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libnana.lib" DESTINATION lib)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AND NOT MINGW??
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_options(nana PUBLIC -lgcc -lstdc++)
|
||||
else()
|
||||
|
||||
if(MINGW)
|
||||
target_compile_options(nana PUBLIC -static) # -static ?? cmake knows BUILD_SHARED_LIBS
|
||||
else()
|
||||
target_compile_options(nana PUBLIC -static-libgcc -static-libstdc++)
|
||||
endif()
|
||||
endif(BUILD_SHARED_LIBS)
|
||||
|
||||
endif()
|
||||
@ -1,69 +0,0 @@
|
||||
# - Try to find the Fontconfig
|
||||
# Once done this will define
|
||||
#
|
||||
# FONTCONFIG_FOUND - system has Fontconfig
|
||||
# FONTCONFIG_INCLUDE_DIR - The include directory to use for the fontconfig headers
|
||||
# FONTCONFIG_LIBRARIES - Link these to use FONTCONFIG
|
||||
# FONTCONFIG_DEFINITIONS - Compiler switches required for using FONTCONFIG
|
||||
|
||||
# Copyright (c) 2006,2007 Laurent Montel, <montel@kde.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
if (FONTCONFIG_LIBRARIES AND FONTCONFIG_INCLUDE_DIR)
|
||||
|
||||
# in cache already
|
||||
set(FONTCONFIG_FOUND TRUE)
|
||||
|
||||
else (FONTCONFIG_LIBRARIES AND FONTCONFIG_INCLUDE_DIR)
|
||||
|
||||
if (NOT WIN32)
|
||||
# use pkg-config to get the directories and then use these values
|
||||
# in the FIND_PATH() and FIND_LIBRARY() calls
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_FONTCONFIG fontconfig)
|
||||
|
||||
set(FONTCONFIG_DEFINITIONS ${PC_FONTCONFIG_CFLAGS_OTHER})
|
||||
endif (NOT WIN32)
|
||||
|
||||
find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h
|
||||
PATHS
|
||||
${PC_FONTCONFIG_INCLUDEDIR}
|
||||
${PC_FONTCONFIG_INCLUDE_DIRS}
|
||||
/usr/X11/include
|
||||
)
|
||||
|
||||
find_library(FONTCONFIG_LIBRARIES NAMES fontconfig
|
||||
PATHS
|
||||
${PC_FONTCONFIG_LIBDIR}
|
||||
${PC_FONTCONFIG_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Fontconfig DEFAULT_MSG FONTCONFIG_LIBRARIES FONTCONFIG_INCLUDE_DIR )
|
||||
|
||||
mark_as_advanced(FONTCONFIG_LIBRARIES FONTCONFIG_INCLUDE_DIR)
|
||||
|
||||
endif (FONTCONFIG_LIBRARIES AND FONTCONFIG_INCLUDE_DIR)
|
||||
Loading…
x
Reference in New Issue
Block a user