Changeset - r24427:8a2677a5edb7
[Not reviewed]
master
0 6 0
glx22 - 4 years ago 2020-12-12 23:24:55
glx@openttd.org
Add: [CMake] Option to only build tools/docs
6 files changed with 98 insertions and 65 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -32,6 +32,78 @@ set_directory_options()
 
include(Static)
 
set_static_if_needed()
 

	
 
if(MSVC)
 
    # C++17 for MSVC
 
    set(CMAKE_CXX_STANDARD 17)
 
else()
 
    # C++11 for all other targets
 
    set(CMAKE_CXX_STANDARD 11)
 
endif()
 

	
 
set(CMAKE_CXX_STANDARD_REQUIRED YES)
 
set(CMAKE_CXX_EXTENSIONS NO)
 

	
 
set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
 

	
 
# An empty target for the tools
 
add_custom_target(tools)
 

	
 
include(Endian)
 
add_endian_definition()
 

	
 
include(CompileFlags)
 
compile_flags()
 

	
 
if(APPLE OR UNIX)
 
    add_definitions(-DUNIX)
 
endif()
 

	
 
if(UNIX)
 
    find_package(Doxygen)
 
endif()
 

	
 
list(APPEND GENERATED_SOURCE_FILES "${CMAKE_BINARY_DIR}/generated/rev.cpp")
 
if(WIN32)
 
    list(APPEND GENERATED_SOURCE_FILES "${CMAKE_BINARY_DIR}/generated/ottdres.rc")
 
endif()
 

	
 
# Generate a target to determine version, which is execute every 'make' run
 
add_custom_target(find_version
 
        ${CMAKE_COMMAND}
 
                -DFIND_VERSION_BINARY_DIR=${CMAKE_BINARY_DIR}/generated
 
                -DCPACK_BINARY_DIR=${CMAKE_BINARY_DIR}
 
                -P "${CMAKE_SOURCE_DIR}/cmake/scripts/FindVersion.cmake"
 
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
 
        BYPRODUCTS ${GENERATED_SOURCE_FILES}
 
)
 

	
 
# Documentation
 
if(DOXYGEN_EXECUTABLE)
 
    add_custom_target(docs)
 
    add_custom_target(docs_source
 
        ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/docs
 
        COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
 
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
 
        COMMENT "Generating documentation for source"
 
    )
 
    add_dependencies(docs_source
 
        find_version
 
    )
 
    add_dependencies(docs
 
        docs_source
 
    )
 
endif()
 

	
 
include(AddCustomXXXTimestamp)
 

	
 
if(OPTION_TOOLS_ONLY)
 
    if(HOST_BINARY_DIR)
 
        unset(HOST_BINARY_DIR CACHE)
 
    endif()
 
    add_subdirectory(${CMAKE_SOURCE_DIR}/src)
 
    return()
 
endif()
 

	
 
# Prefer -pthread over -lpthread, which is often the better option of the two.
 
set(CMAKE_THREAD_PREFER_PTHREAD YES)
 
# Make sure we have Threads available.
 
@@ -72,10 +144,6 @@ find_package(Xaudio2)
 

	
 
find_package(Grfcodec)
 

	
 
if(UNIX)
 
    find_package(Doxygen)
 
endif()
 

	
 
# IPO is only properly supported from CMake 3.9. Despite the fact we are
 
# CMake 3.5, still enable IPO if we detect we are 3.9+.
 
if(POLICY CMP0069)
 
@@ -103,57 +171,7 @@ if(APPLE)
 
    endif()
 
endif()
 

	
 
if(MSVC)
 
    # C++17 for MSVC
 
    set(CMAKE_CXX_STANDARD 17)
 
else()
 
    # C++11 for all other targets
 
    set(CMAKE_CXX_STANDARD 11)
 
endif()
 

	
 
set(CMAKE_CXX_STANDARD_REQUIRED YES)
 
set(CMAKE_CXX_EXTENSIONS NO)
 

	
 
set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
 

	
 
list(APPEND GENERATED_SOURCE_FILES "${CMAKE_BINARY_DIR}/generated/rev.cpp")
 
if(WIN32)
 
    list(APPEND GENERATED_SOURCE_FILES "${CMAKE_BINARY_DIR}/generated/ottdres.rc")
 
endif()
 

	
 
# Generate a target to determine version, which is execute every 'make' run
 
add_custom_target(find_version
 
        ${CMAKE_COMMAND}
 
                -DFIND_VERSION_BINARY_DIR=${CMAKE_BINARY_DIR}/generated
 
                -DCPACK_BINARY_DIR=${CMAKE_BINARY_DIR}
 
                -P "${CMAKE_SOURCE_DIR}/cmake/scripts/FindVersion.cmake"
 
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
 
        BYPRODUCTS ${GENERATED_SOURCE_FILES}
 
)
 

	
 
# An empty target for the tools
 
add_custom_target(tools)
 

	
 
# Documentation
 
if(DOXYGEN_EXECUTABLE)
 
    add_custom_target(docs)
 
    add_custom_target(docs_source
 
        ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/docs
 
        COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
 
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
 
        COMMENT "Generating documentation for source"
 
    )
 
    add_dependencies(docs_source
 
        find_version
 
    )
 
    add_dependencies(docs
 
        docs_source
 
    )
 
endif()
 

	
 
include(SourceList)
 
include(Endian)
 
add_endian_definition()
 

	
 
# Needed by rev.cpp
 
include_directories(${CMAKE_SOURCE_DIR}/src)
 
@@ -162,14 +180,10 @@ include_directories(${CMAKE_SOURCE_DIR}/
 

	
 
include(MSVCFilters)
 

	
 
include(CompileFlags)
 
compile_flags()
 

	
 
add_executable(openttd WIN32 ${GENERATED_SOURCE_FILES})
 
set_target_properties(openttd PROPERTIES OUTPUT_NAME "${BINARY_NAME}")
 
# All other files are added via target_sources()
 

	
 
include(AddCustomXXXTimestamp)
 
add_subdirectory(${CMAKE_SOURCE_DIR}/src)
 
add_subdirectory(${CMAKE_SOURCE_DIR}/media/baseset)
 

	
 
@@ -192,10 +206,6 @@ endif()
 
set_target_properties(openttd PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
 
process_compile_flags()
 

	
 
if(APPLE OR UNIX)
 
    add_definitions(-DUNIX)
 
endif()
 

	
 
include(LinkPackage)
 
link_package(PNG TARGET PNG::PNG ENCOURAGED)
 
link_package(ZLIB TARGET ZLIB::ZLIB ENCOURAGED)
cmake/Options.cmake
Show inline comments
 
@@ -57,6 +57,12 @@ function(set_options)
 
    option(OPTION_USE_ASSERTS "Use assertions; leave enabled for nightlies, betas, and RCs" ON)
 
    option(OPTION_USE_THREADS "Use threads" ON)
 
    option(OPTION_USE_NSIS "Use NSIS to create windows installer; enable only for stable releases" OFF)
 
    option(OPTION_TOOLS_ONLY "Build only tools target" OFF)
 
    option(OPTION_DOCS_ONLY "Build only docs target" OFF)
 

	
 
    if (OPTION_DOCS_ONLY)
 
        set(OPTION_TOOLS_ONLY ON PARENT_SCOPE)
 
    endif()
 
endfunction()
 

	
 
# Show the values of the generic options.
src/CMakeLists.txt
Show inline comments
 
add_subdirectory(script)
 
add_subdirectory(settingsgen)
 
add_subdirectory(strgen)
 

	
 
if(OPTION_TOOLS_ONLY)
 
    return()
 
endif()
 

	
 
add_subdirectory(3rdparty)
 
add_subdirectory(ai)
 
add_subdirectory(blitter)
 
@@ -11,11 +19,8 @@ add_subdirectory(network)
 
add_subdirectory(os)
 
add_subdirectory(pathfinder)
 
add_subdirectory(saveload)
 
add_subdirectory(script)
 
add_subdirectory(settingsgen)
 
add_subdirectory(sound)
 
add_subdirectory(spriteloader)
 
add_subdirectory(strgen)
 
add_subdirectory(table)
 
add_subdirectory(video)
 
add_subdirectory(widgets)
src/script/CMakeLists.txt
Show inline comments
 
add_subdirectory(api)
 

	
 
if(OPTION_TOOLS_ONLY)
 
    return()
 
endif()
 

	
 
add_files(
 
    script_config.cpp
 
    script_config.hpp
src/script/api/CMakeLists.txt
Show inline comments
 
@@ -131,6 +131,10 @@ foreach(API "ai;AI" "game;GS" "template;
 
    )
 
endforeach()
 

	
 
if(OPTION_TOOLS_ONLY)
 
    return()
 
endif()
 

	
 
add_library(openttd::script_api ALIAS script_api)
 

	
 

	
src/strgen/CMakeLists.txt
Show inline comments
 
@@ -22,6 +22,10 @@ if (NOT HOST_BINARY_DIR)
 
    add_dependencies(tools strgen)
 
endif()
 

	
 
if(OPTION_TOOLS_ONLY)
 
    return()
 
endif()
 

	
 
# Source Files
 
add_files(strgen_base.cpp)
 

	
0 comments (0 inline, 0 general)