#---------------------------------------------------------------------------------------------------------------------------------------------
# This is the start
#---------------------------------------------------------------------------------------------------------------------------------------------

################
## bsBuildLibs ##
#################
macro(bsBuildLibs)
    foreach(lib ${ARGN})
        bsIncludeLib(${lib})
        bsGetLibExamples(${lib})
        bsIncludeLibExamples(${lib})
    endforeach()
endmacro()

##################
## bsIncludeLib ##
##################
macro(bsIncludeLib)
    set(fn "${CMAKE_SOURCE_DIR}/tools/cmake/modules/lib_${ARGV0}.cmake")
    if(EXISTS ${fn})
        include(lib_${ARGV0})
    else()
        message(FATAL_ERROR "Unable to find library configuration file:
${lib_${ARGV0}}!")
    endif()
endmacro()

######################
## bsGetLibExamples ##
######################
macro(bsGetLibExamples)
    string(TOUPPER ${lib} lib_upper)
    set(WITH_LIB_${lib_upper}_EXAMPLES "")
    # get all examples
    get_cmake_property(_vars VARIABLES)
    foreach(_var ${_vars})
        string(TOUPPER ${lib} lib_upper)
        if(_var MATCHES "^WITH_LIB_${lib_upper}_EXAMPLE_([A-Za-z]+)$")
            list(APPEND WITH_LIB_${lib_upper}_EXAMPLES ${CMAKE_MATCH_1})
        endif()
    endforeach()
endmacro()

###########################
## bsIncludeLibsExamples ##
###########################
macro(bsIncludeLibExamples)
    foreach(lib ${ARGN})
        string(TOUPPER ${lib} lib_upper)
        if(DEFINED "WITH_LIB_${lib_upper}_EXAMPLES")
            foreach(example IN LISTS WITH_LIB_${lib_upper}_EXAMPLES)
                string(TOLOWER ${example} example_lower)
                set(fn
"${CMAKE_SOURCE_DIR}/tools/cmake/modules/lib_${lib}_example_${example_lower}.cmake")
                set(lib_name "lib_${lib}_example_${example_lower}")
                if(EXISTS ${fn})
                    message(STATUS "Bulding lib ${lib}, example:
${example}")
                    include(${lib_name})
                else()
                    message(FATAL_ERROR "Could not find example file
${fn} for library ${lib} and (example: ${example_lower})!")
                endif()
            endforeach()
        endif()
    endforeach()
endmacro()





########################################
## FIRST FILE I INCLUDE with inclde() ##
########################################

set(ALL_LIBS "glad;glfw")

set(WITH_LIB_GLAD 1)
set(WITH_LIB_GLAD_EXAMPLE_CBASIC 1)

set(WITH_LIB_GLFW 1)
set(WITH_LIB_GLFW_EXAMPLE_CBASIC 1)
set(WITH_LIB_GLFW_EXAMPLE_CPPBASIC 1)

bsBuildLibs(${ALL_LIBS})

---------------------------------------------------------------------------------------------------------------------------------------------

if turns into loading different files that are part of the compilation:
- First the ALL_LIBS list get looped and all examples for the libraries
are filtered out
- i then i have one example .cmake file for every example with the same
name sheme as you see at the first set() lines like
WITH_LIB_GLAD_EXAMPLE_CBASIC -
 this file is included and there should the build process be
acompilshed (the filename here would be lib_glad_example_cbasic.c).

Here is an example if lib_glad.cmake.

---------------------------------------------------------------------------------------------------------------------------------------------


IF(WITH_LIB_GLAD)
    ###################
    ## first example ##
    ###################
    find_package(OpenGL REQUIRED)
    find_package(X11 REQUIRED)
    find_package(Threads REQUIRED)

    set(LIB_GLAD_INC_PATH
        ${OUTPUT_PATH}/glad/include
        ${OPENGL_INCLUDE_DIR}
        ${X11_INCLUDE_DIR}
    )

    set(LIB_GLAD_LIB_PATH
        ${OUTPUT_PATH}/glad/lib
        ${OPENGL_LIBRARIES}
        ${X11_LIBRARIES}
    )

    set(LIB_GLAD_STATIC_LIBS
        glad
        m
        rt
        ${CMAKE_DL_LIBS}
        OpenGL::GL
        Threads::Threads
        X11::X11
        X11::Xxf86vm
        X11::Xi
        X11::Xrandr
        X11::Xcursor
        X11::Xinerama
    )

    cmake_print_variables(OUTPUT_PATH)
    ExternalProject_Add(external_glad
        PREFIX ${CMAKE_BINARY_DIR}/glad-log
        GIT_REPOSITORY ${GLAD_REPO}
        GIT_TAG ${GLAD_TAG}
        GIT_PROGRESS true
        GIT_SHALLOW True
        SOURCE_DIR ${CMAKE_BINARY_DIR}/glad
        UPDATE_COMMAND ""
        PATCH_COMMAND ""
        INSTALL_DIR ${CMAKE_BINARY_DIR}/glad
        CMAKE_ARGS -DCMAKE_BUILD_TYPE:String=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH}/glad -DGLAD_INSTALL=True
        #CONFIGURE_COMMAND ""
        INSTALL_COMMAND ""
    )

ENDIF()

###########################
## second file i include ##
###########################
IF(WITH_LIB_GLAD AND WITH_LIB_GLAD_EXAMPLE_CBASIC)

    add_executable(LIB_GLAD_EXAMPLE_CBASIC ${LIB_GLAD_EXAMPLE_CBASIC_SRC})
    set(CMAKE_C_COMPILER ${LIB_GLAD_EXAMPLE_CBASIC_COMPILER})

    cmake_print_variables(LIB_GLAD_INC_PATH)
    target_include_directories(LIB_GLAD_EXAMPLE_CBASIC PRIVATE
${LIB_GLAD_INC_PATH})
    target_link_directories(LIB_GLAD_EXAMPLE_CBASIC PRIVATE
${LIB_GLAD_LIB_PATH})
    target_link_libraries(LIB_GLAD_EXAMPLE_CBASIC PRIVATE
${LIB_GLAD_STATIC_LIBS})

    set(LIB_GLAD_EXAMPLE_CBASIC_C_FLAGS_DEBUG
${LIB_GLAD_EXAMPLE_CBASIC_C_FLAGS_DEBUG})
    set(LIB_GLAD_EXAMPLE_CBASIC_C_FALGS_RELEASE
${LIB_GLAD_EXAMPLE_CBASIC_C_FLAGS_RELEASE})

    cmake_print_variables(LIB_GLAD_EXAMPLE_CBASIC_INSTALL_PATH)
    set_target_properties(LIB_GLAD_EXAMPLE_CBASIC PROPERTIES
OUTPUT_NAME_RELEASE ${LIB_GLAD_EXAMPLE_CBASIC_OUTPUT_NAME_RELEASE})
    set_target_properties(LIB_GLAD_EXAMPLE_CBASIC PROPERTIES
OUTPUT_NAME_DEBUG ${LIB_GLAD_EXAMPLE_CBASIC_OUTPUT_NAME_DEBUG})
    add_dependencies(LIB_GLAD_EXAMPLE_CBASIC
${LIB_GLAD_EXAMPLE_CBASIC_DEPS})
    install(
        TARGETS LIB_GLAD_EXAMPLE_CBASIC
        RUNTIME DESTINATION ${LIB_GLAD_EXAMPLE_CBASIC_INSTALL_PATH}
    )


ENDIF()

and here is the example build file lib_glad_example_cbasic.cmake:

# i tried to remove the IF but it's the same result

if(WITH_LIB_GLAD AND WITH_LIB_GLAD_EXAMPLE_CBASIC)

    message(STATUS "---> Building example WITH_LIB_GLAD_EXAMPLE_CBASIC")

    add_executable(LIB_GLAD_EXAMPLE_CBASIC ${LIB_GLAD_EXAMPLE_CBASIC_SRC})
    set(CMAKE_C_COMPILER ${LIB_GLAD_EXAMPLE_CBASIC_COMPILER})

    cmake_print_variables(LIB_GLAD_INC_PATH)
    target_include_directories(LIB_GLAD_EXAMPLE_CBASIC PRIVATE
${LIB_GLAD_INC_PATH})
    target_link_directories(LIB_GLAD_EXAMPLE_CBASIC PRIVATE
${LIB_GLAD_LIB_PATH})
    target_link_libraries(LIB_GLAD_EXAMPLE_CBASIC PRIVATE
${LIB_GLAD_STATIC_LIBS})

    set(LIB_GLAD_EXAMPLE_CBASIC_C_FLAGS_DEBUG
${LIB_GLAD_EXAMPLE_CBASIC_C_FLAGS_DEBUG})
    set(LIB_GLAD_EXAMPLE_CBASIC_C_FALGS_RELEASE
${LIB_GLAD_EXAMPLE_CBASIC_C_FLAGS_RELEASE})

    cmake_print_variables(LIB_GLAD_EXAMPLE_CBASIC_INSTALL_PATH)
    set_target_properties(LIB_GLAD_EXAMPLE_CBASIC PROPERTIES
OUTPUT_NAME_RELEASE ${LIB_GLAD_EXAMPLE_CBASIC_OUTPUT_NAME_RELEASE})
    set_target_properties(LIB_GLAD_EXAMPLE_CBASIC PROPERTIES
OUTPUT_NAME_DEBUG ${LIB_GLAD_EXAMPLE_CBASIC_OUTPUT_NAME_DEBUG})
    add_dependencies(LIB_GLAD_EXAMPLE_CBASIC
${LIB_GLAD_EXAMPLE_CBASIC_DEPS})
    install(
        TARGETS LIB_GLAD_EXAMPLE_CBASIC
        RUNTIME DESTINATION ${LIB_GLAD_EXAMPLE_CBASIC_INSTALL_PATH}
    )
ENDIF()


---------------------------------------------------------------------------------------------------------------------------------------------

Now my problem is that the variable CMAKE_BUILD_TYPE automaticaly is set
to debug but i'm using cmake 3.14 with the line:

# avoid having empty buildtype
IF(NOT DEFINED CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "The build type of the
project. (default:Release)")
ENDIF()

and the build_tool directory from the ExternalProject_Add is never
installed but it is tried to compile the example file. It worked before
i'm confused
that something because of the order of how things are working is making
me trouble.

I hope someone can help me out here, it would be the rest work of the
puzzle to make things work uniquely for my libs and their examples.

best regrads!

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to