lundi 28 novembre 2016

CMake generates weird project structure for Xcode

I'm trying to generate an Xcode project with CMake but the output is strange.

This is my CMakeLists:

if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
    message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt.")
endif()

cmake_minimum_required(VERSION 3.0)
project(myproject)

set(PROJECT_VERSION, 0.1.0)
set(PROJECT_VERSION_MAJOR, 0)
set(PROJECT_VERSION_MINOR, 1)
set(PROJECT_VERSION_PATCH, 0)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_BUILD_TYPE DEBUG)
enable_language(CXX)

if(NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE DEBUG)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DASIO_STANDALONE -std=c++11 -pedantic -Wno-padded -Wno-undef -Wno-old-style-cast -gdwarf-2")

# Clang only settings
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -ferror-limit=0 -fcolor-diagnostics -Wno-c++98-compat -Wno-documentation -Wno-c++98-compat-pedantic -Wno-weak-vtables -Wno-global-constructors -Wno-exit-time-destructors")
endif()

if (CMAKE_BUILD_TYPE MATCHES DEBUG)
#  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DASIO_ENABLE_HANDLER_TRACKING")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -glldb")
endif()

# Download Asio from github
if (CMAKE_VERSION VERSION_LESS 3.2)
    set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
    set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()
include(DownloadProject.cmake)

download_project(PROJ               fmt
                 GIT_REPOSITORY     http://ift.tt/2gADP06
                 GIT_TAG            3.0.0
                 ${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
include_directories(${fmt_SOURCE_DIR})

download_project(PROJ               asio
                 GIT_REPOSITORY     http://ift.tt/2ftOMo0
                 GIT_TAG            asio-1-10-8 # asio-1-10-8
                 ${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
exec_program(COMMAND "./autogen.sh" WORKING_DIRECTORY ${asio_SOURCE_DIR}/asio)
exec_program(COMMAND "./configure --without-boost" WORKING_DIRECTORY ${asio_SOURCE_DIR}/asio)
include_directories(${asio_SOURCE_DIR}/asio/include)

download_project(PROJ               spdlog
                 GIT_REPOSITORY     http://ift.tt/2gAyLJ0
                 GIT_TAG            v0.11.0
                 ${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
include_directories(${spdlog_SOURCE_DIR}/include/)

# Build library
set(SOURCE_FILES
    src/AA.cpp src/AA.h
    src/internal/BB.h src/internal/BB.cpp
    src/internal/client/CC.cpp src/internal/client/CC.h)
add_library(myproject STATIC ${SOURCE_FILES})
#add_library(myproject SHARED ${SOURCE_FILES})

# Add tests
enable_testing()
add_custom_target(tests ${CMAKE_CTEST_COMMAND} -V)
add_subdirectory(tests)

# Installation target
install(TARGETS myproject DESTINATION lib)
install(FILES Database.h DESTINATION include)

# Generate docs
include(Docs.cmake)

This works well when generating Make files but when trying to generate an Xcode project I get a very strange folder structure with most of my source files missing and the directory in which they're included does not seem to matter.

myproject
   |- Sources
        |- doc
        |- tests
        |- myproject
        |     |- Source Files
        |     |     |- <random .h files>
        |     |- Header Files
        |           |- <random .cpp files>
        |- ALL BUILD
        |       |- <CMakeLists.txt>
        |- ZERO BUILD
        |       |- <CMakeLists.txt>
        |- CTestDashboardChecks
        |       |- <CMakeLists.txt>
        |- TARGET
                |- <CMakeLists.txt>

Basically the project structure does not match my folder structure, there's missing files and a bunch of folders I did not expect to see there. How can I generate an Xcode project correctly?

Aucun commentaire:

Enregistrer un commentaire