POV-Ray : Newsgroups : povray.programming : Interested in CMake support (build system, IDE integration) : Re: Interested in CMake support (build system, IDE integration) Server Time
21 Apr 2024 06:45:19 EDT (-0400)
  Re: Interested in CMake support (build system, IDE integration)  
From: LanuHum
Date: 22 Oct 2016 06:45:00
Message: <web.580b4292dc6ec2767a3e03fe0@news.povray.org>
For example, the structure is different from the master and hgpovray.
Now I understand why stupid written configuration files gnumake.
CMakeListsGenerator.py

import os,sys

external_library = ['SDL','ILMBASE','OPENEXR','JPEG','PNG','TIFF']
pkg_modules = ['sdl','IlmBase','OpenEXR','libtiff-4']
cmake_names = ['SDL','ILMBASE','OPENEXR','TIFF']
cmake_packages = ['PkgConfig','JPEG','PNG']

cmakelist = open('CMakeLists.txt','w')
cmakelist.write('cmake_minimum_required(VERSION 2.8)\n\n')
cmakelist.write('project(povanim)\n\n')
if sys.platform in {'linux'}:
    cmakelist.write('set( CMAKE_CXX_FLAGS "-pipe -Wno-multichar \\\n')
    cmakelist.write('   -Wno-write-strings -fno-enforce-eh-specs \\\n')
    cmakelist.write('   -Wno-non-template-friend -s -O3 \\\n')
    cmakelist.write('   -ffast-math -march=native -pthread")\n\n')

sources = {}
unix_source_folders = {'source', 'platform', 'unix', 'vfe'}
win_source_folders = {'source', 'platform', 'windows', 'vfe'}
if sys.platform in {'linux'}:
    source_folders = unix_source_folders

if sys.platform[:3] == 'win':
    source_folders = win_source_folders
root_dir = os.getcwd()
root = root_dir.split('/')[-1]

prefix='POVRAY'

for folder in source_folders:
    source_key = folder.upper()
    source_key = prefix + '_' + source_key
    source_dir1 = os.path.join(root_dir,folder)
    value = source_dir1.split('/')
    plus = False
    source_value = ''
    for v in value:
        if v == root:
            plus = True
            continue
        if plus:
            source_value += v
            plus = False
    sources[source_key] = source_value
    src1 = os.listdir(source_dir1)
    for ob in src1:
        source_dir2 = os.path.join(source_dir1,ob)
        source_key1 = source_key
        if os.path.isdir(source_dir2):
            src2 = os.listdir(source_dir2)
            isCPP = False
            for ob1 in src2:
                if ob1.endswith('.cpp'):
                    isCPP = True
                    break
            if isCPP:
                source_key1 += ('_' + ob.upper())
                source_value1 = source_value
                source_value1 += ('/' + ob)
                sources[source_key1] = source_value1
                for ob1 in src2:
                    source_dir3 = os.path.join(source_dir2,ob1)
                    source_key2 = source_key1
                    if os.path.isdir(source_dir3):
                        src3 = os.listdir(source_dir3)
                        isCPP1 = False
                        for ob2 in src3:
                            if ob2.endswith('.cpp'):
                                isCPP1 = True
                                break
                        if isCPP1:
                            source_key2 += ('_' + ob1.upper())
                            source_value2 = source_value1
                            source_value2 += ('/' + ob1)
                            sources[source_key2] = source_value2
                        else:
                            continue
            else:
                continue

for i,k in enumerate(sources):
    cmakelist.write('set(%s    %s)\n'%(k,sources[k]))
cmakelist.write('\n\n')

for i,k in enumerate(sources):
    aux = k.replace('_','')
    cmakelist.write('aux_source_directory( ${%s}    %s)\n'%(k,aux))
cmakelist.write('\n\n')

for pack in cmake_packages:
    cmakelist.write('find_package(%s REQUIRED)\n'%pack)
cmakelist.write('\n\n')

for i,mod in enumerate(pkg_modules):
    cmake_name = mod.upper()
    cmakelist.write('pkg_search_module(%s REQUIRED %s)\n'%(cmake_names[i],mod))
cmakelist.write('\n\n')

cmakelist.write('include_directories(\n')
for i,k in enumerate(sources):
    aux = k.split('_')
    if len(aux) == 2:
        cmakelist.write('       ${%s}\n'%(k))
for lib in external_library:
    cmakelist.write('       ${%s_INCLUDE_DIRS}\n'%lib)
cmakelist.write(')\n')
cmakelist.write('\n\n')

cmakelist.write('add_executable(\n')
cmakelist.write('       ${PROJECT_NAME}\n')
for i,k in enumerate(sources):
    aux = k.replace('_','')
    cmakelist.write('       ${%s}\n'%(aux))
cmakelist.write(')\n')
cmakelist.write('\n\n')

cmakelist.write('target_link_libraries(\n')
cmakelist.write('       ${PROJECT_NAME}\n')

for lib in external_library:
    cmakelist.write('       ${%s_LIBRARIES}\n'%lib)
cmakelist.write('       -lz -lm boost_thread boost_system\n')
cmakelist.write(')\n')

cmakelist.close()


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.