From: ibs Date: Mon, 19 Nov 2012 10:56:02 +0000 (+0400) Subject: 23485: The WOK doesn't generate cmake metafile building the OpenCascade X-Git-Tag: V6_7_1~100 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=6c14ac82469920bdeae035619a0c2bebf509b1a5;p=occt-wok.git 23485: The WOK doesn't generate cmake metafile building the OpenCascade WOK generates cmake metafile building the OpenCascade possibility has been added (using command with argument: wgenproj option -IDE=cmk) No_Exception flag added for win; _OCC64, HAVE_CONFIG_H, OCC_CONVERT_SIGNALS definitions added; -mthreads flag added for mingw the CMake meta-file lets to choose list of toolkits --- diff --git a/src/WOKTclLib/OS.tcl b/src/WOKTclLib/OS.tcl index 9dbf135..1a3e4a4 100644 --- a/src/WOKTclLib/OS.tcl +++ b/src/WOKTclLib/OS.tcl @@ -2970,6 +2970,142 @@ proc OS:MKVC { theOutDir {theModules {}} {theAllSolution ""} {theVcVer "vc8"} } } } +# Function to generate CMake meta file +proc OS:MKCMK { theOutDir {theModules {}} {theAllSolution ""} } { + puts stderr "Generating CMake meta project" + + set anOutFileName "CMakeLists.txt" + set aProjectName $theAllSolution + + set aFileBuff [list] + + #add to cmake meta file "cap" information + lappend aFileBuff "cmake_minimum_required ( VERSION 2.6)" + lappend aFileBuff "project(${aProjectName})" + lappend aFileBuff "" + lappend aFileBuff "set(BUILD_SHARED_LIBS ON)" + lappend aFileBuff "if (NOT DEFINED CMAKE_INSTALL_PREFIX)" + lappend aFileBuff " set(CMAKE_INSTALL_PREFIX \"[OS:casroot]\")" + lappend aFileBuff "endif()" + lappend aFileBuff "" + lappend aFileBuff "set(BITNESS $::env(ARCH))" + lappend aFileBuff "" + lappend aFileBuff "if (NOT DEFINED CMAKE_BUILD_TYPE)" + lappend aFileBuff " set(CMAKE_BUILD_TYPE \"Release\")" + lappend aFileBuff "endif()" + lappend aFileBuff "" + lappend aFileBuff "set (USED_TOOLKITS \"\")" + lappend aFileBuff "" + lappend aFileBuff "if (\$\{BITNESS\} STREQUAL 64)" + lappend aFileBuff " add_definitions(-D_OCC64)" + lappend aFileBuff "endif()" + lappend aFileBuff "" + lappend aFileBuff "add_definitions(-DHAVE_CONFIG_H)" + lappend aFileBuff "" + lappend aFileBuff "if (WIN32)" + lappend aFileBuff " set(SYSTEM win)" + lappend aFileBuff "else()" + lappend aFileBuff " set(SYSTEM lin)" + lappend aFileBuff " add_definitions(-DOCC_CONVERT_SIGNALS)" + lappend aFileBuff "endif()" + lappend aFileBuff "" + lappend aFileBuff "if (MINGW)" + lappend aFileBuff " SET(CMAKE_CXX_FLAGS \$\{CMAKE_CXX_FLAGS\} -mthreads)" + lappend aFileBuff " SET(CMAKE_C_FLAGS \$\{CMAKE_C_FLAGS\} -mthreads)" + lappend aFileBuff " SET(CMAKE_EXE_LINKER_FLAGS \$\{CMAKE_EXE_LINKER_FLAGS\} -mthreads -Wl,--export-all-symbols)" + lappend aFileBuff " SET(CMAKE_SHARED_LINKER_FLAGS \$\{CMAKE_SHARED_LINKER_FLAGS\} -mthreads -Wl,--export-all-symbols)" + lappend aFileBuff "endif()" + lappend aFileBuff "" + if {"$::env(WOKSTATION)" == "wnt"} { + lappend aFileBuff "set(CMAKE_CXX_FLAGS_RELEASE \$\{CMAKE_CXX_FLAGS_RELEASE\} No_Exception)" + } + #lappend aFileBuff "SET ( CMAKE_CXX_FLAGS \$\{CMAKE_CXX_FLAGS_RELEASE\} -Wall -fexceptions -fPIC)" + lappend aFileBuff "" + lappend aFileBuff "include_directories([join $::CSF_OPT_INC ";"])" + + if {$::ARCH == 32} { + lappend aFileBuff "link_directories([join $::CSF_OPT_LIB32 ";"])" + } else { + lappend aFileBuff "link_directories([join $::CSF_OPT_LIB64 ";"])" + } + lappend aFileBuff "" + lappend aFileBuff "if (DEFINED MSVC70)" + lappend aFileBuff " SET(COMPILER vc7)" + lappend aFileBuff "elseif (DEFINED MSVC80)" + lappend aFileBuff " SET(COMPILER vc8)" + lappend aFileBuff "elseif (DEFINED MSVC90)" + lappend aFileBuff " SET(COMPILER vc9)" + lappend aFileBuff "elseif (DEFINED MSVC10)" + lappend aFileBuff " SET(COMPILER vc10)" + lappend aFileBuff "else()" + lappend aFileBuff " SET(COMPILER \$\{CMAKE_GENERATOR\})" + lappend aFileBuff "endif()" + lappend aFileBuff "" + + foreach aModule $theModules { + foreach aToolKit [${aModule}:toolkits] { + set aDepToolkits [join [LibToLink [woklocate -u $aToolKit]] ";"] + lappend aFileBuff "set(${aToolKit}_DEPS \"${aDepToolkits}\")" + } + foreach anExecutable [OS:executable ${aModule}] { + set aDepToolkits [join [LibToLink [woklocate -u $anExecutable]] ";"] + lappend aFileBuff "set(${anExecutable}_DEPS \"${aDepToolkits}\")" + } + } + lappend aFileBuff "" + lappend aFileBuff "separate_arguments(USED_TOOLKITS)" + lappend aFileBuff "foreach( TOOLKIT \$\{USED_TOOLKITS\} )" + lappend aFileBuff " set(TurnONthe\$\{TOOLKIT\} ON)" + lappend aFileBuff " foreach( TK \$\{\$\{TOOLKIT\}_DEPS\})" + lappend aFileBuff " set(TurnONthe\$\{TK\} ON)" + lappend aFileBuff " endforeach()" + lappend aFileBuff "endforeach()" + lappend aFileBuff "" + #lappend aFileBuff "set(EXECUTABLE_OUTPUT_PATH \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/out)" + #lappend aFileBuff "set(LIBRARY_OUTPUT_PATH \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/out)" + lappend aFileBuff "" + foreach aModule $theModules { + foreach aToolKit [${aModule}:toolkits] { + #create directory + if {![file exists "$theOutDir/$aToolKit"]} { + file mkdir "$theOutDir/$aToolKit" + } + + #add directory to main cmake metafile + lappend aFileBuff "subdirs(${aToolKit})" + + # create cmake metafile into target subdir + osutils:cmktk $theOutDir $aToolKit false + } + foreach anExecutable [OS:executable ${aModule}] { + #create directory + if {![file exists "$theOutDir/$anExecutable"]} { + file mkdir "$theOutDir/$anExecutable" + } + + #add directory to main cmake metafile + lappend aFileBuff "subdirs(${anExecutable})" + + # create cmake metafile into target subdir + osutils:cmktk $theOutDir $anExecutable true + } + } + + # install toolkits and execs and other files + lappend aFileBuff "" + lappend aFileBuff "install( TARGETS \$\{${aProjectName}_TOOLKITS\} CONFIGURATIONS Debug DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/bind )" + lappend aFileBuff "install( TARGETS \$\{${aProjectName}_TOOLKITS\} CONFIGURATIONS Release DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/bin )" + lappend aFileBuff "" + lappend aFileBuff "install( TARGETS \$\{${aProjectName}_EXECUTABLES\} CONFIGURATIONS Debug DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/bind )" + lappend aFileBuff "install( TARGETS \$\{${aProjectName}_EXECUTABLES\} CONFIGURATIONS Release DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/bin )" + + #generate cmake meta file + set aFile [open [set fdsw [file join $theOutDir $anOutFileName]] w] + fconfigure $aFile -translation crlf + puts $aFile [join $aFileBuff "\n"] + close $aFile +} + # Generates Code Blocks workspace. proc OS:cworkspace { theSolName theModules theOutDir } { set aWsFilePath "${theOutDir}/${theSolName}.workspace" @@ -3063,8 +3199,8 @@ set aTKNullKey "TKNull" set THE_GUIDS_LIST($aTKNullKey) "{00000000-0000-0000-0000-000000000000}" # Entry function to generate project files and solutions for IDE -proc OS:MKPRC { {theOutDir {}} {theModules {}} {theIDE ""} } { - set aSupportedIDE { "vc7" "vc8" "vc9" "vc10" "cbp"} +proc OS:MKPRC { {theOutDir {}} {theProjectType {}} {theIDE ""} } { + set aSupportedIDE { "vc7" "vc8" "vc9" "vc10" "cbp" "cmk"} if { [lsearch $aSupportedIDE $theIDE] < 0 } { puts stderr "WOK does not support generation of project files for the selected IDE: $theIDE" @@ -3092,18 +3228,24 @@ proc OS:MKPRC { {theOutDir {}} {theModules {}} {theIDE ""} } { } # make list of modules and platforms - set aModules [OS:listmodules $theModules {win32}] + set aModules [OS:listmodules $theProjectType {win32}] # generate one solution for all projects if complete OS or VAS is processed set anAllSolution "" - if { $theModules == "OS" } { + if { $theProjectType == "OS" } { set anAllSolution "OCCT" - } elseif { $theModules == "VAS" } { + } elseif { $theProjectType == "VAS" } { set anAllSolution "Products" } # Create output directory set aWokStation "$::env(WOKSTATION)" + + # compatibility patch. + if { [lsearch -exact {vc7 vc8 vc9 vc10} $theIDE] != -1 } { + set aWokStation "msvc" + } + set anOutDir "${anOutRoot}/${aWokStation}/${theIDE}" OS:mkdir $anOutDir if { ! [file exists $anOutDir] } { @@ -3118,6 +3260,7 @@ proc OS:MKPRC { {theOutDir {}} {theModules {}} {theIDE ""} } { "vc9" - "vc10" { OS:MKVC $anOutDir $aModules $anAllSolution $theIDE } "cbp" { OS:MKCBP $anOutDir $aModules $anAllSolution } + "cmk" { OS:MKCMK $anOutDir $aModules $anAllSolution } } # Store generated GUIDs map diff --git a/src/WOKTclLib/osutils.tcl b/src/WOKTclLib/osutils.tcl index a8354f2..524bbd5 100755 --- a/src/WOKTclLib/osutils.tcl +++ b/src/WOKTclLib/osutils.tcl @@ -1782,20 +1782,40 @@ proc TESTAM { {root} {modules {}} {ll {}} } { # Generate Code::Blocks project file for ToolKit proc osutils:cbptk { theOutDir theToolKit } { - set aWokStation "$::env(WOKSTATION)" - set aWokArch "$::env(ARCH)" - - # collect list of referred libraries to link with set aUsedToolKits [list] set anIncPaths [list] set aTKDefines [list] set aTKSrcFiles [list] - foreach tkx [wokUtils:LIST:Purge [osutils:tk:close [woklocate -u $theToolKit]]] { - lappend aUsedToolKits "${tkx}" + + osutils:tkinfo $theOutDir $theToolKit aUsedToolKits anIncPaths aTKDefines aTKSrcFiles + + return [osutils:cbp $theOutDir $theToolKit $aTKSrcFiles $aUsedToolKits $anIncPaths $aTKDefines] +} + +proc osutils:tkinfo { theOutDir theToolKit theUsedToolKits theIncPaths theTKDefines theTKSrcFiles } { + set aWokStation "$::env(WOKSTATION)" + + set aRelatedPathPart "../../../.." + + # collect list of referred libraries to link with + upvar $theUsedToolKits anUsedToolKits + upvar $theIncPaths anIncPaths + upvar $theTKDefines aTKDefines + upvar $theTKSrcFiles aTKSrcFiles + + set aDepToolkits [LibToLink [woklocate -u $theToolKit]] + foreach tkx $aDepToolkits { + if {[uinfo -t [woklocate -u $tkx]] == "toolkit"} { + lappend anUsedToolKits "${tkx}" + } + if {[lsearch [w_info -l] $tkx] == "-1"} { + lappend anUsedToolKits "${tkx}" + } } + wokparam -l CSF - - foreach tk [lappend [wokUtils:LIST:Purge [osutils:tk:close [woklocate -u $theToolKit]]] $theToolKit] { + + foreach tk [lappend aDepToolkits $theToolKit] { foreach element [osutils:tk:hascsf [woklocate -p ${tk}:source:EXTERNLIB [wokcd]]] { if {[wokparam -t %$element] == 0} { continue @@ -1806,19 +1826,24 @@ proc osutils:cbptk { theOutDir theToolKit } { continue } set felem [file tail $fl] - if {[lsearch $aUsedToolKits $felem] == "-1"} { + if {[lsearch $anUsedToolKits $felem] == "-1"} { if {$felem != "\{\}" & $felem != "lib"} { if {[lsearch -nocase [osutils:optinal_libs] $felem] == -1} { - lappend aUsedToolKits [string trimleft "${felem}" "-l"] + lappend anUsedToolKits [string trimleft "${felem}" "-l"] } } } } } } - - lappend anIncPaths "../../../inc" + + lappend anIncPaths "$aRelatedPathPart/inc" set listloc [osutils:tk:units [woklocate -u $theToolKit]] + + if { [llength $listloc] == 0 } { + set listloc [woklocate -u $theToolKit] + } + if { "$aWokStation" == "wnt" } { set resultloc [osutils:justwnt $listloc] } else { @@ -1831,7 +1856,7 @@ proc osutils:cbptk { theOutDir theToolKit } { foreach aSrcFile [lsort $aSrcFiles] { if { ![info exists written([file tail $aSrcFile])] } { set written([file tail $aSrcFile]) 1 - lappend aTKSrcFiles "../../../[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $aSrcFile 3]]" + lappend aTKSrcFiles "${aRelatedPathPart}/[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $aSrcFile 3]]" } else { puts "Warning : more than one occurences for [file tail $aSrcFile]" } @@ -1843,8 +1868,8 @@ proc osutils:cbptk { theOutDir theToolKit } { } # common include paths - lappend anIncPaths "../../../drv/${xlo}" - lappend anIncPaths "../../../src/${xlo}" + lappend anIncPaths "${aRelatedPathPart}/drv/${xlo}" + lappend anIncPaths "${aRelatedPathPart}/src/${xlo}" } # macros for UNIX to use config.h file @@ -1861,10 +1886,92 @@ proc osutils:cbptk { theOutDir theToolKit } { lappend aTKDefines "OCC_CONVERT_SIGNALS" #lappend aTKDefines "_GNU_SOURCE=1" } +} - return [osutils:cbp $theOutDir $theToolKit $aTKSrcFiles $aUsedToolKits $anIncPaths $aTKDefines] +proc osutils:cmktk { theOutDir theToolKit {theIsExec false} } { + set anOutFileName "CMakeLists.txt" + + set aFileBuff [list] + + set anUsedToolKits [list] + set anIncPaths [list] + set aTKDefines [list] + set aTKSrcFiles [list] + + osutils:tkinfo $theOutDir $theToolKit anUsedToolKits anIncPaths aTKDefines aTKSrcFiles + + lappend aFileBuff "project(${theToolKit})\n" + + foreach aMacro $aTKDefines { + lappend aFileBuff "list( APPEND ${theToolKit}_PRECOMPILED_DEFS \"-D${aMacro}\" )" + } + + lappend aFileBuff "\nstring( REGEX REPLACE \";\" \" \" ${theToolKit}_PRECOMPILED_DEFS \"\$\{${theToolKit}_PRECOMPILED_DEFS\}\")" + + # common compiler options + #lappend aFileBuff "list( APPEND ${theToolKit}_COMPILER_OPTION \"-Wall\" \"-fexceptions\" \"-fPIC\" )\n" + + # compiler directories + lappend aFileBuff "\nlist( APPEND ${theToolKit}_COMPILER_DIRECTORIES \"$::env(WOK_LIBRARY)\" )" + foreach anIncPath $anIncPaths { + lappend aFileBuff "list( APPEND ${theToolKit}_COMPILER_DIRECTORIES \"$anIncPath\" )" + } + + # common linker options. + lappend aFileBuff "" + foreach aLibName $anUsedToolKits { + if { $aLibName != "" } { + lappend aFileBuff "list( APPEND ${theToolKit}_USED_LIBS ${aLibName} )" + } + } + + if { "$::env(WOKSTATION)" == "wnt" && $theToolKit == "TKOpenGl" } { + lappend aFileBuff "list( APPEND ${theToolKit}_USED_LIBS vfw32 )" + } + + lappend aFileBuff "" + foreach aTKSrcFile $aTKSrcFiles { + regsub -all "\\\\" ${aTKSrcFile} "/" aTKSrcFile + lappend aFileBuff "list( APPEND ${theToolKit}_USED_SRCFILES ${aTKSrcFile} )" + if {[string equal -nocase [file extension $aTKSrcFile] ".c"]} { + #lappend aFileBuff "set_source_files_properties(${aTKSrcFile} PROPERTIES COMPILE_FLAGS \"CC\")" + } + } + + lappend aFileBuff "" + lappend aFileBuff "if (\"\$\{USED_TOOLKITS\}\" STREQUAL \"\" OR DEFINED TurnONthe${theToolKit})" + if { $theIsExec == true } { + lappend aFileBuff " add_executable( ${theToolKit} \$\{${theToolKit}_USED_SRCFILES\} )" + lappend aFileBuff "" + lappend aFileBuff " install( TARGETS ${theToolKit} CONFIGURATIONS Debug DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/bind )" + lappend aFileBuff " install( TARGETS ${theToolKit} CONFIGURATIONS Release DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/bin )" + } else { + lappend aFileBuff " add_library( ${theToolKit} SHARED \$\{${theToolKit}_USED_SRCFILES\} )" + lappend aFileBuff "" + lappend aFileBuff " install( TARGETS ${theToolKit} CONFIGURATIONS Debug + RUNTIME DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/bind + ARCHIVE DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/libd + LIBRARY DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/libd)" + lappend aFileBuff " install( TARGETS ${theToolKit} CONFIGURATIONS Release + RUNTIME DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/bin + ARCHIVE DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/lib + LIBRARY DESTINATION \$\{CMAKE_INSTALL_PREFIX\}/\$\{SYSTEM\}\$\{BITNESS\}/\$\{COMPILER\}/lib)" + } + lappend aFileBuff "" + lappend aFileBuff " set_target_properties( ${theToolKit} PROPERTIES COMPILE_FLAGS \"\$\{${theToolKit}_PRECOMPILED_DEFS\}\" )" + lappend aFileBuff " include_directories( \$\{${theToolKit}_COMPILER_DIRECTORIES\} )" + lappend aFileBuff " target_link_libraries( ${theToolKit} \$\{${theToolKit}_USED_LIBS\} )" + lappend aFileBuff "endif()" + + #generate cmake meta file + set aFile [open "$theOutDir/$theToolKit/$anOutFileName" w] + fconfigure $aFile -translation crlf + puts $aFile [join $aFileBuff "\n"] + close $aFile } + + # Generate Code::Blocks project file for Executable proc osutils:cbpx { theOutDir theToolKit } { set aWokStation "$::env(WOKSTATION)" @@ -1890,6 +1997,7 @@ proc osutils:cbpx { theOutDir theToolKit } { } wokparam -l CSF + foreach tk $aDepToolkits { foreach element [osutils:tk:hascsf [woklocate -p ${tk}:source:EXTERNLIB [wokcd]]] { if {[wokparam -t %$element] == 0} { diff --git a/src/WOKsite/wok_tclshrc.tcl b/src/WOKsite/wok_tclshrc.tcl index 67a465a..b16fc03 100644 --- a/src/WOKsite/wok_tclshrc.tcl +++ b/src/WOKsite/wok_tclshrc.tcl @@ -309,11 +309,12 @@ proc wgenproj { args } { set aProcArgs $args # Setting default IDE. - # For Windows - Visual Studio (vc), Linux - Code Blocks (cbp), Mac OS X - Xcode (). + # For Windows - Visual Studio (vc), Linux - Code Blocks (cbp), Mac OS X - Xcode (cmk). set anIDE "" switch -exact -- "$::env(WOKSTATION)" { "wnt" {set anIDE "$::VCVER"} "lin" {set anIDE "cbp"} + "mac" {set anIDE "cmk"} } # Getting from arguments the name of IDE, for which we should generate project files.