From 00c923df8f7dd2a69ecb66b277b0373722b7d820 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Nov 2017 23:04:52 +0000 Subject: [PATCH 01/12] Use target_compile_features instead of setting CXX_STANDARD. This allows child projects to just link to nana and automatically inherit the -std=c++14 setting. Minimum cmake version for this to work is 3.1. --- CMakeLists.txt | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a43b5b5..24793395 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,8 @@ # It seems that project() defines essential system variables like CMAKE_FIND_LIBRARY_PREFIXES. # https://bbs.archlinux.org/viewtopic.php?id=84967 -project(nana) -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +project(nana VERSION 1.5.5 LANGUAGES CXX) option(NANA_CMAKE_INSTALL_INCLUDES "Install nana includes when compile the library" ON) option(NANA_CMAKE_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ "replaced boost.thread with meganz's mingw-std-threads." OFF) @@ -147,11 +147,9 @@ endif(UNIX) if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Clang || GNU if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -g") # Clang - + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g") # Clang else ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -g") # GNU - + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g") # GNU endif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") endif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") @@ -354,6 +352,19 @@ if(NANA_CMAKE_INSTALL_INCLUDES) message("The Nana include files will be installed in ${CMAKE_INSTALL_PREFIX}/include") endif(NANA_CMAKE_INSTALL_INCLUDES) +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: message ("") From a09d23210f45f528abb38a950590346acbdf1d93 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Nov 2017 23:35:17 +0000 Subject: [PATCH 02/12] Use target_include_directories instead of include_directories. Also change the linked libraries where necessary and link to fontconfig, which fixes my build error. --- CMakeLists.txt | 110 +++++++++++++++++------------ cmake/Modules/FindFontconfig.cmake | 69 ++++++++++++++++++ 2 files changed, 134 insertions(+), 45 deletions(-) create mode 100644 cmake/Modules/FindFontconfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 24793395..d71d267b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ # https://bbs.archlinux.org/viewtopic.php?id=84967 cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) project(nana VERSION 1.5.5 LANGUAGES CXX) option(NANA_CMAKE_INSTALL_INCLUDES "Install nana includes when compile the library" ON) @@ -64,6 +65,34 @@ if(POLICY CMP0004) # ignore leading space cmake_policy(SET CMP0004 OLD) endif() +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 /. + /detail + /filesystem + /gui + /gui/detail + /gui/widgets + /gui/widgets/skeletons + /paint + /paint/detail + /system + /threads ) +if(NANA_CMAKE_ENABLE_AUDIO) + list(APPEND NANA_SOURCE_SUBDIRS + /audio + /audio/detail ) +endif(NANA_CMAKE_ENABLE_AUDIO) +# collect all source files in the source-sub-dir +# To show .h files in Visual Studio, add them to the list of sources in add_executable / add_library +# and Use SOURCE_GROUP if all your sources are in the same directory +foreach(subdir ${NANA_SOURCE_SUBDIRS}) + aux_source_directory(${NANA_SOURCE_DIR}${subdir} sources) + # message("Subir: ${subdir}") # message("Files: ${sources}") +endforeach(subdir ${NANA_SOURCE_SUBDIRS}) + +add_library(${PROJECT_NAME} ${sources} ) ########### OS if(WIN32) @@ -120,6 +149,7 @@ if(APPLE) add_definitions(-DAPPLE) include_directories(/opt/X11/include/) list(APPEND NANA_LINKS -L/opt/X11/lib/ -liconv) + target_link_libraries(${PROJECT_NAME} PRIVATE iconv) set(ENABLE_AUDIO OFF) elseif(UNIX) add_definitions(-Dlinux) @@ -127,11 +157,28 @@ elseif(UNIX) endif(APPLE) if(UNIX) - list(APPEND NANA_LINKS -lX11) + find_package(X11 REQUIRED) + list(APPEND NANA_LINKS ${X11_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} + PRIVATE ${X11_LIBRARIES} + PRIVATE ${X11_Xft_LIB} + ) + target_include_directories(${PROJECT_NAME} SYSTEM + PRIVATE ${X11_Xft_INCLUDE_PATH} + PRIVATE ${X11_INCLUDE_DIR} + ) find_package(Freetype) if (FREETYPE_FOUND) - include_directories( ${FREETYPE_INCLUDE_DIRS}) - list(APPEND NANA_LINKS -lXft) + find_package(Fontconfig REQUIRED) + target_include_directories(${PROJECT_NAME} SYSTEM + PRIVATE ${FREETYPE_INCLUDE_DIRS} + PRIVATE ${FONTCONFIG_INCLUDE_DIR} + ) + list(APPEND NANA_LINKS ${FREETYPE_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} + PRIVATE ${FREETYPE_LIBRARIES} + PRIVATE ${FONTCONFIG_LIBRARIES} + ) endif(FREETYPE_FOUND) endif(UNIX) @@ -156,11 +203,14 @@ endif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # enable static linkage # GNU || CLang not MinGW if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AND NOT MINGW + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) if(NANA_CMAKE_SHARED_LIB) - list(APPEND NANA_LINKS -lgcc -lstdc++ -pthread) + list(APPEND NANA_LINKS -lgcc -lstdc++) else() - set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -pthread") + set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") # message("Setting NANA_LINKS to -static-libgcc -static-libstdc++ -pthread or ${NANA_LINKS}") endif(NANA_CMAKE_SHARED_LIB) @@ -168,9 +218,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AN # IS_GNUCXX < 5.3 else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) - # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++fs") # IS_GNUCXX 5.3 or more - list(APPEND NANA_LINKS -lstdc++fs) - + target_link_libraries(${PROJECT_NAME} PRIVATE stdc++fs) endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) endif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AND NOT MINGW @@ -189,10 +237,9 @@ if(NANA_CMAKE_ENABLE_PNG) if(NANA_CMAKE_LIBPNG_FROM_OS) find_package(PNG) if (PNG_FOUND) - include_directories( ${PNG_INCLUDE_DIRS}) list(APPEND NANA_LINKS ${PNG_LIBRARIES}) - add_definitions("-DNANA_ENABLE_PNG" - "-DUSE_LIBPNG_FROM_OS") + target_include_directories(${PROJECT_NAME} PRIVATE PNG::PNG) + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBPNG_FROM_OS) endif(PNG_FOUND) else() add_definitions(-DNANA_ENABLE_PNG) @@ -205,10 +252,10 @@ if(NANA_CMAKE_ENABLE_JPEG) if(NANA_CMAKE_LIBJPEG_FROM_OS) find_package(JPEG) if (JPEG_FOUND) - include_directories( ${JPEG_INCLUDE_DIR}) - list(APPEND NANA_LINKS ${JPEG_LIBRARY}) - add_definitions("-DNANA_ENABLE_JPEG" - "-DUSE_LIBJPEG_FROM_OS") + target_include_directories(${PROJECT_NAME PRIVATE ${JPEG_INCLUDE_DIR}) + list(APPEND NANA_LINKS ${JPEG_LIBRARIES}) + target_include_directories(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES}) + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBJPEG_FROM_OS) endif(JPEG_FOUND) else() add_definitions(-DNANA_ENABLE_JPEG) @@ -221,8 +268,9 @@ if(NANA_CMAKE_ENABLE_AUDIO) if(UNIX) find_package(ASOUND) if (ASOUND_FOUND) - include_directories( ${ASOUND_INCLUDE_DIRS}) + target_include_directories(${PROJECT_NAME PRIVATE ${ASOUND_INCLUDE_DIRS}) list(APPEND NANA_LINKS -lasound) + target_link_libraries(${PROJECT_NAME} PRIVATE ${ASOUND_LIBRARIES}) else(ASOUND_FOUND) message(FATAL_ERROR "libasound is not found") endif(ASOUND_FOUND) @@ -245,8 +293,8 @@ elseif (NANA_CMAKE_FIND_BOOST_FILESYSTEM OR NANA_CMAKE_BOOST_FILESYSTEM_FORCE) find_package(Boost COMPONENTS filesystem) if (Boost_FOUND) add_definitions(-DNANA_BOOST_FILESYSTEM_AVAILABLE) - include_directories(SYSTEM "${Boost_INCLUDE_DIR}") list(APPEND NANA_LINKS ${Boost_LIBRARIES}) ###### FIRST !!!!!!!!!!!!!!!!! add is not first + target_link_libraries(${PROJECT_NAME} PUBLIC Boost::Boost) endif (Boost_FOUND) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) # ?? @@ -267,33 +315,6 @@ endif(NANA_CMAKE_AUTOMATIC_GUI_TESTING) ####################### Main setting of Nana sources, targets and install -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 /. - /detail - /filesystem - /gui - /gui/detail - /gui/widgets - /gui/widgets/skeletons - /paint - /paint/detail - /system - /threads ) -if(NANA_CMAKE_ENABLE_AUDIO) - list(APPEND NANA_SOURCE_SUBDIRS - /audio - /audio/detail ) -endif(NANA_CMAKE_ENABLE_AUDIO) -# collect all source files in the source-sub-dir -# To show .h files in Visual Studio, add them to the list of sources in add_executable / add_library -# and Use SOURCE_GROUP if all your sources are in the same directory -foreach(subdir ${NANA_SOURCE_SUBDIRS}) - aux_source_directory(${NANA_SOURCE_DIR}${subdir} sources) - # message("Subir: ${subdir}") # message("Files: ${sources}") -endforeach(subdir ${NANA_SOURCE_SUBDIRS}) - if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") add_definitions(-fmax-errors=3) endif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") @@ -305,7 +326,6 @@ else() endif(NANA_CMAKE_SHARED_LIB) target_include_directories(${PROJECT_NAME} PUBLIC ${NANA_INCLUDE_DIR}) -target_link_libraries(${PROJECT_NAME} ${NANA_LINKS}) # Headers: use INCLUDE_DIRECTORIES # Libraries: use FIND_LIBRARY and link with the result of it (try to avoid LINK_DIRECTORIES) diff --git a/cmake/Modules/FindFontconfig.cmake b/cmake/Modules/FindFontconfig.cmake new file mode 100644 index 00000000..e6fa81d8 --- /dev/null +++ b/cmake/Modules/FindFontconfig.cmake @@ -0,0 +1,69 @@ +# - 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, +# +# 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) From 872ed69519fe36add89462de032d8fd873e7b86d Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Nov 2017 23:35:28 +0000 Subject: [PATCH 03/12] Whitespace changes --- CMakeLists.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d71d267b..29627f96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -373,17 +373,17 @@ if(NANA_CMAKE_INSTALL_INCLUDES) endif(NANA_CMAKE_INSTALL_INCLUDES) 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 + 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: From bfba8fa233e458590b36940d9f5cf304ac56b50d Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Nov 2017 23:37:17 +0000 Subject: [PATCH 04/12] Fix typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29627f96..7e2d90d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -254,7 +254,7 @@ if(NANA_CMAKE_ENABLE_JPEG) if (JPEG_FOUND) target_include_directories(${PROJECT_NAME PRIVATE ${JPEG_INCLUDE_DIR}) list(APPEND NANA_LINKS ${JPEG_LIBRARIES}) - target_include_directories(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES}) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBJPEG_FROM_OS) endif(JPEG_FOUND) else() From 7f35b240b56862b2784520305b4749539557fc68 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Nov 2017 23:37:55 +0000 Subject: [PATCH 05/12] Remove the NANA_LINKS variable since it's not tracking what's really happening anymore. --- CMakeLists.txt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e2d90d4..c0b48a52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,7 +148,6 @@ endif(WIN32) if(APPLE) add_definitions(-DAPPLE) include_directories(/opt/X11/include/) - list(APPEND NANA_LINKS -L/opt/X11/lib/ -liconv) target_link_libraries(${PROJECT_NAME} PRIVATE iconv) set(ENABLE_AUDIO OFF) elseif(UNIX) @@ -158,7 +157,6 @@ endif(APPLE) if(UNIX) find_package(X11 REQUIRED) - list(APPEND NANA_LINKS ${X11_LIBRARIES}) target_link_libraries(${PROJECT_NAME} PRIVATE ${X11_LIBRARIES} PRIVATE ${X11_Xft_LIB} @@ -174,7 +172,6 @@ if(UNIX) PRIVATE ${FREETYPE_INCLUDE_DIRS} PRIVATE ${FONTCONFIG_INCLUDE_DIR} ) - list(APPEND NANA_LINKS ${FREETYPE_LIBRARIES}) target_link_libraries(${PROJECT_NAME} PRIVATE ${FREETYPE_LIBRARIES} PRIVATE ${FONTCONFIG_LIBRARIES} @@ -208,10 +205,8 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AN target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) if(NANA_CMAKE_SHARED_LIB) - list(APPEND NANA_LINKS -lgcc -lstdc++) else() set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") - # message("Setting NANA_LINKS to -static-libgcc -static-libstdc++ -pthread or ${NANA_LINKS}") endif(NANA_CMAKE_SHARED_LIB) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) @@ -237,7 +232,6 @@ if(NANA_CMAKE_ENABLE_PNG) if(NANA_CMAKE_LIBPNG_FROM_OS) find_package(PNG) if (PNG_FOUND) - list(APPEND NANA_LINKS ${PNG_LIBRARIES}) target_include_directories(${PROJECT_NAME} PRIVATE PNG::PNG) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBPNG_FROM_OS) endif(PNG_FOUND) @@ -253,7 +247,6 @@ if(NANA_CMAKE_ENABLE_JPEG) find_package(JPEG) if (JPEG_FOUND) target_include_directories(${PROJECT_NAME PRIVATE ${JPEG_INCLUDE_DIR}) - list(APPEND NANA_LINKS ${JPEG_LIBRARIES}) target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES}) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBJPEG_FROM_OS) endif(JPEG_FOUND) @@ -269,7 +262,6 @@ if(NANA_CMAKE_ENABLE_AUDIO) find_package(ASOUND) if (ASOUND_FOUND) target_include_directories(${PROJECT_NAME PRIVATE ${ASOUND_INCLUDE_DIRS}) - list(APPEND NANA_LINKS -lasound) target_link_libraries(${PROJECT_NAME} PRIVATE ${ASOUND_LIBRARIES}) else(ASOUND_FOUND) message(FATAL_ERROR "libasound is not found") @@ -293,7 +285,6 @@ elseif (NANA_CMAKE_FIND_BOOST_FILESYSTEM OR NANA_CMAKE_BOOST_FILESYSTEM_FORCE) find_package(Boost COMPONENTS filesystem) if (Boost_FOUND) add_definitions(-DNANA_BOOST_FILESYSTEM_AVAILABLE) - list(APPEND NANA_LINKS ${Boost_LIBRARIES}) ###### FIRST !!!!!!!!!!!!!!!!! add is not first target_link_libraries(${PROJECT_NAME} PUBLIC Boost::Boost) endif (Boost_FOUND) set(Boost_USE_STATIC_LIBS ON) @@ -394,7 +385,6 @@ message ( "CMAKE_COMPILER_IS_GNUCXX = " ${CMAKE_COMPILER_IS_GNUCXX}) 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}) -message ( "NANA_LINKS = " ${NANA_LINKS}) message ( "DESTDIR = " ${DESTDIR}) message ( "CMAKE_INSTALL_PREFIX = " ${CMAKE_INSTALL_PREFIX}) message ( "NANA_INCLUDE_DIR = " ${NANA_INCLUDE_DIR}) From b5c69dc3867be16f3d40ecbd70d0075adc854c72 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Nov 2017 23:53:32 +0000 Subject: [PATCH 06/12] Use target_compile_definitions instead of add_definitions. This allows macro definitions to be inherited. There might be symbols that can be made private. This is likely breaking the build on non-linux systems. --- CMakeLists.txt | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0b48a52..5bac756c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ add_library(${PROJECT_NAME} ${sources} ) ########### OS if(WIN32) - add_definitions(-DWIN32) + target_compile_definitions(${PROJECT_NAME} PUBLIC WIN32) set(CMAKE_DEBUG_POSTFIX "_d") #Global MSVC definitions. You may prefer the hand-tuned sln and projects from the nana repository. if(MSVC) @@ -123,8 +123,10 @@ if(WIN32) if(MINGW) if(NANA_CMAKE_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ) - add_definitions(-DSTD_THREAD_NOT_SUPPORTED) - add_definitions(-DNANA_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ) + target_compile_definitions(${PROJECT_NAME} + PUBLIC STD_THREAD_NOT_SUPPORTED + PUBLIC NANA_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ + ) endif(NANA_CMAKE_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ) endif(MINGW) @@ -146,12 +148,12 @@ endif(WIN32) if(APPLE) - add_definitions(-DAPPLE) + target_compile_definitions(${PROJECT_NAME} PUBLIC APPLE) include_directories(/opt/X11/include/) target_link_libraries(${PROJECT_NAME} PRIVATE iconv) set(ENABLE_AUDIO OFF) elseif(UNIX) - add_definitions(-Dlinux) + target_compile_definitions(${PROJECT_NAME} PUBLIC linux) message("added -D linux") endif(APPLE) @@ -236,13 +238,13 @@ if(NANA_CMAKE_ENABLE_PNG) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBPNG_FROM_OS) endif(PNG_FOUND) else() - add_definitions(-DNANA_ENABLE_PNG) + target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_ENABLE_PNG) endif(NANA_CMAKE_LIBPNG_FROM_OS) endif(NANA_CMAKE_ENABLE_PNG) # Find JPEG if(NANA_CMAKE_ENABLE_JPEG) - add_definitions(-DNANA_ENABLE_JPEG) + target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_ENABLE_JPEG) if(NANA_CMAKE_LIBJPEG_FROM_OS) find_package(JPEG) if (JPEG_FOUND) @@ -257,7 +259,7 @@ endif(NANA_CMAKE_ENABLE_JPEG) # Find ASOUND if(NANA_CMAKE_ENABLE_AUDIO) - add_definitions(-DNANA_ENABLE_AUDIO) + target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_ENABLE_AUDIO) if(UNIX) find_package(ASOUND) if (ASOUND_FOUND) @@ -271,12 +273,12 @@ endif(NANA_CMAKE_ENABLE_AUDIO) # Find/Select filesystem if (NANA_CMAKE_NANA_FILESYSTEM_FORCE) - add_definitions(-DNANA_FILESYSTEM_FORCE) + target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_FILESYSTEM_FORCE) elseif (NANA_CMAKE_STD_FILESYSTEM_FORCE) - add_definitions(-DSTD_FILESYSTEM_FORCE) + target_compile_definitions(${PROJECT_NAME} PUBLIC STD_FILESYSTEM_FORCE) elseif (NANA_CMAKE_FIND_BOOST_FILESYSTEM OR NANA_CMAKE_BOOST_FILESYSTEM_FORCE) if (NANA_CMAKE_BOOST_FILESYSTEM_FORCE) - add_definitions(-DNANA_BOOST_FILESYSTEM_FORCE) + target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_BOOST_FILESYSTEM_FORCE) endif(NANA_CMAKE_BOOST_FILESYSTEM_FORCE) # 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, @@ -284,7 +286,7 @@ elseif (NANA_CMAKE_FIND_BOOST_FILESYSTEM OR NANA_CMAKE_BOOST_FILESYSTEM_FORCE) # If using Boost::thread, then Thread::Thread will also be added automatically. find_package(Boost COMPONENTS filesystem) if (Boost_FOUND) - add_definitions(-DNANA_BOOST_FILESYSTEM_AVAILABLE) + target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_BOOST_FILESYSTEM_AVAILABLE) target_link_libraries(${PROJECT_NAME} PUBLIC Boost::Boost) endif (Boost_FOUND) set(Boost_USE_STATIC_LIBS ON) @@ -294,13 +296,13 @@ endif (NANA_CMAKE_NANA_FILESYSTEM_FORCE) ######## Nana options -add_definitions(-DNANA_IGNORE_CONF) +target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_IGNORE_CONF) if(NANA_CMAKE_VERBOSE_PREPROCESSOR) - add_definitions(-DVERBOSE_PREPROCESSOR) + target_compile_definitions(${PROJECT_NAME} PUBLIC VERBOSE_PREPROCESSOR) endif(NANA_CMAKE_VERBOSE_PREPROCESSOR) if(NANA_CMAKE_AUTOMATIC_GUI_TESTING) - add_definitions(-DNANA_AUTOMATIC_GUI_TESTING) - enable_testing () + target_compile_definitions(${PROJECT_NAME} PRIVATE NANA_AUTOMATIC_GUI_TESTING) + enable_testing () endif(NANA_CMAKE_AUTOMATIC_GUI_TESTING) From d3f55776256de89965dc9488cf4d4f1e8076ac3e Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Nov 2017 23:53:55 +0000 Subject: [PATCH 07/12] These need be set *before* find_package, or it will be too late. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bac756c..d25dcb10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -284,13 +284,13 @@ elseif (NANA_CMAKE_FIND_BOOST_FILESYSTEM OR NANA_CMAKE_BOOST_FILESYSTEM_FORCE) # 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. + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_STATIC_RUNTIME ON) # ?? find_package(Boost COMPONENTS filesystem) if (Boost_FOUND) target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_BOOST_FILESYSTEM_AVAILABLE) target_link_libraries(${PROJECT_NAME} PUBLIC Boost::Boost) endif (Boost_FOUND) - set(Boost_USE_STATIC_LIBS ON) - set(Boost_USE_STATIC_RUNTIME ON) # ?? endif (NANA_CMAKE_NANA_FILESYSTEM_FORCE) From 309a95d32195fe6d8bba655d1189cf84b047ed1b Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Nov 2017 23:54:53 +0000 Subject: [PATCH 08/12] Maybe not needed anymore? --- CMakeLists.txt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d25dcb10..106a0bde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,16 +55,6 @@ option(NANA_CMAKE_NANA_FILESYSTEM_FORCE "Force nana filesystem over ISO and boos option(NANA_CMAKE_STD_FILESYSTEM_FORCE "Use of STD filesystem?(a compilation error will ocurre if not available)" OFF) option(NANA_CMAKE_BOOST_FILESYSTEM_FORCE "Force use of Boost filesystem if available (over STD)?" OFF) -########### Compatibility with CMake 3.1 -if(POLICY CMP0054) - # http://www.cmake.org/cmake/help/v3.1/policy/CMP0054.html - cmake_policy(SET CMP0054 OLD) -endif() -if(POLICY CMP0004) # ignore leading space - # http://www.cmake.org/cmake/help/v3.0/policy/CMP0004.html - cmake_policy(SET CMP0004 OLD) -endif() - 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 From 32e6ee532c7829b01446ff817d83e631bb5efbbd Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 10 Nov 2017 00:16:50 +0000 Subject: [PATCH 09/12] Fix build after rebase. --- CMakeLists.txt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 106a0bde..7090e19a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,11 @@ foreach(subdir ${NANA_SOURCE_SUBDIRS}) # message("Subir: ${subdir}") # message("Files: ${sources}") endforeach(subdir ${NANA_SOURCE_SUBDIRS}) -add_library(${PROJECT_NAME} ${sources} ) +if(NANA_CMAKE_SHARED_LIB) + add_library(${PROJECT_NAME} SHARED ${sources} ) +else() + add_library(${PROJECT_NAME} STATIC ${sources} ) +endif(NANA_CMAKE_SHARED_LIB) ########### OS if(WIN32) @@ -196,8 +200,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AN find_package(Threads REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) - if(NANA_CMAKE_SHARED_LIB) - else() + if(NOT NANA_CMAKE_SHARED_LIB) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") endif(NANA_CMAKE_SHARED_LIB) @@ -302,12 +305,6 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") add_definitions(-fmax-errors=3) endif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") -if(NANA_CMAKE_SHARED_LIB) - add_library(${PROJECT_NAME} SHARED ${sources} ) -else() - add_library(${PROJECT_NAME} STATIC ${sources} ) -endif(NANA_CMAKE_SHARED_LIB) - target_include_directories(${PROJECT_NAME} PUBLIC ${NANA_INCLUDE_DIR}) # Headers: use INCLUDE_DIRECTORIES From b9946f262403c6218f8edf7d3f5a9ddc994a2b88 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 10 Nov 2017 00:29:07 +0000 Subject: [PATCH 10/12] Fix up some wrong parts I missed to conform with the rest of my changes. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7090e19a..9af2d3a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,7 +227,7 @@ if(NANA_CMAKE_ENABLE_PNG) if(NANA_CMAKE_LIBPNG_FROM_OS) find_package(PNG) if (PNG_FOUND) - target_include_directories(${PROJECT_NAME} PRIVATE PNG::PNG) + target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE PNG::PNG) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBPNG_FROM_OS) endif(PNG_FOUND) else() @@ -241,12 +241,12 @@ if(NANA_CMAKE_ENABLE_JPEG) if(NANA_CMAKE_LIBJPEG_FROM_OS) find_package(JPEG) if (JPEG_FOUND) - target_include_directories(${PROJECT_NAME PRIVATE ${JPEG_INCLUDE_DIR}) + target_include_directories(${PROJECT_NAME SYSTEM PRIVATE ${JPEG_INCLUDE_DIR}) target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES}) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBJPEG_FROM_OS) endif(JPEG_FOUND) else() - add_definitions(-DNANA_ENABLE_JPEG) + target_compile_definitions(${PROJECT_NAME} PUBLIC NANA_ENABLE_JPEG) endif(NANA_CMAKE_LIBJPEG_FROM_OS) endif(NANA_CMAKE_ENABLE_JPEG) From 97297ae511bd7f26bcee334aad5143017eb5af05 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 10 Nov 2017 00:46:08 +0000 Subject: [PATCH 11/12] Fix cmake warning. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9af2d3a8..06b66eaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,7 +202,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AN if(NOT NANA_CMAKE_SHARED_LIB) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") - endif(NANA_CMAKE_SHARED_LIB) + endif(NOT NANA_CMAKE_SHARED_LIB) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) # IS_GNUCXX < 5.3 From b713b01dbe8489787842a1f306b0eedb29dc2be5 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 10 Nov 2017 00:49:46 +0000 Subject: [PATCH 12/12] Fix missing closing brace. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06b66eaf..64bb1bd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -241,7 +241,7 @@ if(NANA_CMAKE_ENABLE_JPEG) if(NANA_CMAKE_LIBJPEG_FROM_OS) find_package(JPEG) if (JPEG_FOUND) - target_include_directories(${PROJECT_NAME SYSTEM PRIVATE ${JPEG_INCLUDE_DIR}) + target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${JPEG_INCLUDE_DIR}) target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES}) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBJPEG_FROM_OS) endif(JPEG_FOUND) @@ -256,7 +256,7 @@ if(NANA_CMAKE_ENABLE_AUDIO) if(UNIX) find_package(ASOUND) if (ASOUND_FOUND) - target_include_directories(${PROJECT_NAME PRIVATE ${ASOUND_INCLUDE_DIRS}) + target_include_directories(${PROJECT_NAME} PRIVATE ${ASOUND_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} PRIVATE ${ASOUND_LIBRARIES}) else(ASOUND_FOUND) message(FATAL_ERROR "libasound is not found")