# HG changeset patch # User koda # Date 1363564693 -3600 # Node ID d9e57426e7597cc7059b2ca34e54a25bbd439172 # Parent 1b9f026e9fc6717faa7d0110a0cbceef522649ff barebone cmake config file to support pascal files, based off plplot's ada files diff -r 1b9f026e9fc6 -r d9e57426e759 cmake_modules/CMakeDeterminePascalCompiler.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/CMakeDeterminePascalCompiler.cmake Mon Mar 18 00:58:13 2013 +0100 @@ -0,0 +1,62 @@ +# Determine the compiler to use for Pascal programs +# NOTE, a generator may set CMAKE_Pascal_COMPILER before +# loading this file to force a compiler. +# use environment variable Pascal first if defined by user, next use +# the cmake variable CMAKE_GENERATOR_PASCAL which can be defined by a generator +# as a default compiler + +IF(NOT CMAKE_Pascal_COMPILER) + + # prefer the environment variable FPC + IF($ENV{FPC} MATCHES ".+") + GET_FILENAME_COMPONENT(CMAKE_Pascal_COMPILER_INIT $ENV{FPC} PROGRAM PROGRAM_ARGS CMAKE_Pascal_FLAGS_ENV_INIT) + IF(CMAKE_Pascal_FLAGS_ENV_INIT) + SET(CMAKE_Pascal_COMPILER_ARG1 "${CMAKE_Pascal_FLAGS_ENV_INIT}" CACHE STRING "First argument to Pascal compiler") + ENDIF(CMAKE_Pascal_FLAGS_ENV_INIT) + IF(EXISTS ${CMAKE_Pascal_COMPILER_INIT}) + ELSE(EXISTS ${CMAKE_Pascal_COMPILER_INIT}) + MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable FPC:\n$ENV{FPC}.") + ENDIF(EXISTS ${CMAKE_Pascal_COMPILER_INIT}) + ENDIF($ENV{FPC} MATCHES ".+") + + # next try prefer the compiler specified by the generator + IF(CMAKE_GENERATOR_PASCAL) + IF(NOT CMAKE_Pascal_COMPILER_INIT) + SET(CMAKE_Pascal_COMPILER_INIT ${CMAKE_GENERATOR_PASCAL}) + ENDIF(NOT CMAKE_Pascal_COMPILER_INIT) + ENDIF(CMAKE_GENERATOR_PASCAL) + + # finally list compilers to try + IF(CMAKE_Pascal_COMPILER_INIT) + SET(CMAKE_Pascal_COMPILER_LIST ${CMAKE_Pascal_COMPILER_INIT}) + ELSE(CMAKE_Pascal_COMPILER_INIT) + SET(CMAKE_Pascal_COMPILER_LIST fpc ppc386 ppcx64 ppcppc ppcarm) + ENDIF(CMAKE_Pascal_COMPILER_INIT) + + # Find the compiler. + FIND_PROGRAM(CMAKE_Pascal_COMPILER NAMES ${CMAKE_Pascal_COMPILER_LIST} DOC "Pascal compiler") + IF(CMAKE_Pascal_COMPILER_INIT AND NOT CMAKE_Pascal_COMPILER) + SET(CMAKE_Pascal_COMPILER "${CMAKE_Pascal_COMPILER_INIT}" CACHE FILEPATH "Pascal compiler" FORCE) + ENDIF(CMAKE_Pascal_COMPILER_INIT AND NOT CMAKE_Pascal_COMPILER) +ENDIF(NOT CMAKE_Pascal_COMPILER) +MARK_AS_ADVANCED(CMAKE_Pascal_COMPILER) + +GET_FILENAME_COMPONENT(COMPILER_LOCATION "${CMAKE_Pascal_COMPILER}" PATH) + +#FIND_PROGRAM(GNAT_EXECUTABLE_BUILDER NAMES gnatmake PATHS ${COMPILER_LOCATION} ) +FIND_PROGRAM(CMAKE_AR NAMES ar PATHS ${COMPILER_LOCATION} ) + +FIND_PROGRAM(CMAKE_RANLIB NAMES ranlib) +IF(NOT CMAKE_RANLIB) + SET(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib") +ENDIF(NOT CMAKE_RANLIB) +MARK_AS_ADVANCED(CMAKE_RANLIB) + +# configure variables set in this file for fast reload later on +#CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakePascalCompiler.cmake.in +CONFIGURE_FILE(${CMAKE_MODULE_PATH}/CMakePascalCompiler.cmake.in + "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakePascalCompiler.cmake" + IMMEDIATE) +MARK_AS_ADVANCED(CMAKE_AR) + +SET(CMAKE_Pascal_COMPILER_ENV_VAR "FPC") diff -r 1b9f026e9fc6 -r d9e57426e759 cmake_modules/CMakePascalCompiler.cmake.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/CMakePascalCompiler.cmake.in Mon Mar 18 00:58:13 2013 +0100 @@ -0,0 +1,12 @@ +SET(CMAKE_Pascal_COMPILER "@CMAKE_Pascal_COMPILER@") +SET(CMAKE_Pascal_COMPILER_ARG1 "@CMAKE_Pascal_COMPILER_ARG1@") +SET(CMAKE_AR "@CMAKE_AR@") +SET(CMAKE_RANLIB "@CMAKE_RANLIB@") +SET(CMAKE_Pascal_COMPILER_LOADED 1) + +SET(CMAKE_Pascal_COMPILER_ENV_VAR "FPC") + +SET(CMAKE_Pascal_SOURCE_FILE_EXTENSIONS "pas" "pp") +SET(CMAKE_Pascal_IGNORE_EXTENSIONS "o" "ppu" "obj" "def" "rc" "RC") +SET(CMAKE_Pascal_LINKER_PREFERENCE Prefered) +SET(CMAKE_Pascal_OUTPUT_EXTENSION ".o") diff -r 1b9f026e9fc6 -r d9e57426e759 cmake_modules/CMakePascalInformation.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/CMakePascalInformation.cmake Mon Mar 18 00:58:13 2013 +0100 @@ -0,0 +1,206 @@ +# This file sets the basic flags for the Pascal language in CMake. +# It also loads the available platform file for the system-compiler +# if it exists. + +GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_Pascal_COMPILER} NAME_WE) +SET(CMAKE_SYSTEM_AND_Pascal_COMPILER_INFO_FILE + ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake) +INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL) + +# This should be included before the _INIT variables are +# used to initialize the cache. Since the rule variables +# have if blocks on them, users can still define them here. +# But, it should still be after the platform file so changes can +# be made to those values. + +IF(CMAKE_USER_MAKE_RULES_OVERRIDE) + INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE}) +ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE) + +IF(CMAKE_USER_MAKE_RULES_OVERRIDE_Pascal) + INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_Pascal}) +ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_Pascal) + + +# for most systems a module is the same as a shared library +# so unless the variable CMAKE_MODULE_EXISTS is set just +# copy the values from the LIBRARY variables +IF(NOT CMAKE_MODULE_EXISTS) + SET(CMAKE_SHARED_MODULE_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_Pascal_FLAGS}) + SET(CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS}) +ENDIF(NOT CMAKE_MODULE_EXISTS) + +# Create a set of shared library variable specific to Pascal +# For 90% of the systems, these are the same flags as the C versions +# so if these are not set just copy the flags from the c version +#IF(NOT CMAKE_SHARED_LIBRARY_CREATE_Ada_FLAGS) +# SET(CMAKE_SHARED_LIBRARY_CREATE_Ada_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}) +#ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_Ada_FLAGS) + +#IF(NOT CMAKE_SHARED_LIBRARY_Ada_FLAGS) +# SET(CMAKE_SHARED_LIBRARY_Ada_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS}) +#ENDIF(NOT CMAKE_SHARED_LIBRARY_Ada_FLAGS) + +#IF(NOT CMAKE_SHARED_LIBRARY_LINK_Ada_FLAGS) +# SET(CMAKE_SHARED_LIBRARY_LINK_Ada_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}) +#ENDIF(NOT CMAKE_SHARED_LIBRARY_LINK_Ada_FLAGS) + +#IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Ada_FLAG) +# SET(CMAKE_SHARED_LIBRARY_RUNTIME_Ada_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}) +#ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Ada_FLAG) + +#IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Ada_FLAG_SEP) +# SET(CMAKE_SHARED_LIBRARY_RUNTIME_Ada_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP}) +#ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Ada_FLAG_SEP) + +# repeat for modules +#IF(NOT CMAKE_SHARED_MODULE_CREATE_Ada_FLAGS) +# SET(CMAKE_SHARED_MODULE_CREATE_Ada_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS}) +#ENDIF(NOT CMAKE_SHARED_MODULE_CREATE_Ada_FLAGS) + +#IF(NOT CMAKE_SHARED_MODULE_Ada_FLAGS) +# SET(CMAKE_SHARED_MODULE_Ada_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS}) +#ENDIF(NOT CMAKE_SHARED_MODULE_Ada_FLAGS) + +#IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Ada_FLAG) +# SET(CMAKE_SHARED_MODULE_RUNTIME_Ada_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG}) +#ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Ada_FLAG) + +#IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Ada_FLAG_SEP) +# SET(CMAKE_SHARED_MODULE_RUNTIME_Ada_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG_SEP}) +#ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Ada_FLAG_SEP) + +#IF(NOT CMAKE_INCLUDE_FLAG_Ada) +# SET(CMAKE_INCLUDE_FLAG_Ada ${CMAKE_INCLUDE_FLAG_C}) +#ENDIF(NOT CMAKE_INCLUDE_FLAG_Ada) + +#IF(NOT CMAKE_INCLUDE_FLAG_SEP_Ada) +# SET(CMAKE_INCLUDE_FLAG_SEP_Ada ${CMAKE_INCLUDE_FLAG_SEP_C}) +#ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_Ada) + +# Copy C version of this flag which is normally determined in platform file. +IF(NOT CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG) + SET(CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG}) +ENDIF(NOT CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG) + +SET(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.") + +SET (CMAKE_Pascal_FLAGS "$ENV{FPFLAGS} ${CMAKE_Pascal_FLAGS_INIT}" CACHE STRING + "Flags for Ada compiler.") + +INCLUDE(CMakeCommonLanguageInclude) + +# now define the following rule variables + +# CMAKE_Ada_CREATE_SHARED_LIBRARY +# CMAKE_Ada_CREATE_SHARED_MODULE +# CMAKE_Ada_CREATE_STATIC_LIBRARY +# CMAKE_Ada_COMPILE_OBJECT +# CMAKE_Ada_LINK_EXECUTABLE + +# variables supplied by the generator at use time +# +# the target without the suffix +# +# +# +# +# + +# Ada compiler information +# +# +# +# + +# Static library tools +# +# + + +# create an Ada shared library +IF(NOT CMAKE_Ada_CREATE_SHARED_LIBRARY) + SET(CMAKE_Ada_CREATE_SHARED_LIBRARY + " -o " + ) +ENDIF(NOT CMAKE_Ada_CREATE_SHARED_LIBRARY) + +# create an Ada shared module just copy the shared library rule +IF(NOT CMAKE_Ada_CREATE_SHARED_MODULE) + SET(CMAKE_Ada_CREATE_SHARED_MODULE ${CMAKE_Ada_CREATE_SHARED_LIBRARY}) +ENDIF(NOT CMAKE_Ada_CREATE_SHARED_MODULE) + +# create an Ada static library +IF(NOT CMAKE_Ada_CREATE_STATIC_LIBRARY) + SET(CMAKE_Ada_CREATE_STATIC_LIBRARY + " cr " + " ") +ENDIF(NOT CMAKE_Ada_CREATE_STATIC_LIBRARY) + +# compile a Pascal file into an object file +IF(NOT CMAKE_Pascal_COMPILE_OBJECT) + SET(CMAKE_Pascal_COMPILE_OBJECT " -Cn") +#" -o -Cn +ENDIF(NOT CMAKE_Pascal_COMPILE_OBJECT) + +# Constraints: GNAT_EXECUTABLE_BUILDER = gnatmake +# is required to do the compile+bind+link of +# Ada executables, and it requires a source file name which is constructed from +# .adb. The source file arguments of add_executable are +# all compiled by the above rule (which must remain that form since it +# is also used to compile objects for Ada libraries), but the results are +# ignored since they are put in a different directory while gnatmake assumes +# objects are located in the _current_ directory. Thus, put in a minimal +# source file (with correct .adb suffix to identify the Ada language) +# to reduce this useless compilation to a minimum. Usually, the main Ada +# routine qualifies since it is normally small. Thus, the normal usage is +# add_executable(foo foo.adb), but add_executable(foo path/minimal.adb) would +# work as well so long as both path/minimal.adb existed and foo.adb existed. +# Also, note there is no way to specify +# ${CMAKE_CURRENT_SOURCE_DIR}/.adb as the code for gnatmake to compile +# because in this context ${CMAKE_CURRENT_SOURCE_DIR} is set to the top +# of the source tree and not the expected sub-directory of the source tree. +# Thus, LINK_FLAGS -aI${CMAKE_CURRENT_SOURCE_DIR} must be set using +# set_target_properties in order to specify the directory where .adb +# exists. Note, LINK_FLAGS can also be used to set other gnatmake flags +# such as -aL. + +# In sum, you have to be careful of your target name, the nominal source file +# name has to be compilable, but otherwise it is ignored, and you must specify +# the required -aI and other GNAT_EXECUTABLE_BUILDER = gnatmake options +# using LINK_FLAGS specified with set_target_properties. +# However, so long as you pay attention to these +# constraints, add_executable should work for the Ada language. + +IF(NOT CMAKE_Pascal_LINK_EXECUTABLE) +#GET_FILENAME_COMPONENT(COMPILER_LOCATION "${CMAKE_Pascal_COMPILER}" PATH) + set(CMAKE_Pascal_LINK_EXECUTABLE "${CMAKE_BINARY_DIR}/ppas.sh") +# SET(CMAKE_Pascal_LINK_EXECUTABLE "${CMAKE_Pascal_COMPILER} .adb -cargs -largs ") +ENDIF(NOT CMAKE_Pascal_LINK_EXECUTABLE) + +IF(CMAKE_Ada_STANDARD_LIBRARIES_INIT) + SET(CMAKE_Ada_STANDARD_LIBRARIES "${CMAKE_Ada_STANDARD_LIBRARIES_INIT}" + CACHE STRING "Libraries linked by default with all Ada applications.") + MARK_AS_ADVANCED(CMAKE_Ada_STANDARD_LIBRARIES) +ENDIF(CMAKE_Ada_STANDARD_LIBRARIES_INIT) + +IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) + SET (CMAKE_Ada_FLAGS_DEBUG "${CMAKE_Ada_FLAGS_DEBUG_INIT}" CACHE STRING + "Flags used by the compiler during debug builds.") + SET (CMAKE_Ada_FLAGS_MINSIZEREL "${CMAKE_Ada_FLAGS_MINSIZEREL_INIT}" CACHE STRING + "Flags used by the compiler during release minsize builds.") + SET (CMAKE_Ada_FLAGS_RELEASE "${CMAKE_Ada_FLAGS_RELEASE_INIT}" CACHE STRING + "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).") + SET (CMAKE_Ada_FLAGS_RELWITHDEBINFO "${CMAKE_Ada_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING + "Flags used by the compiler during Release with Debug Info builds.") +ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) + +MARK_AS_ADVANCED( +CMAKE_Pascal_FLAGS +CMAKE_Pascal_FLAGS_DEBUG +CMAKE_Pascal_FLAGS_MINSIZEREL +CMAKE_Pascal_FLAGS_RELEASE +CMAKE_Pascal_FLAGS_RELWITHDEBINFO +) +SET(CMAKE_Pascal_INFORMATION_LOADED 1) + diff -r 1b9f026e9fc6 -r d9e57426e759 cmake_modules/CMakeTestPascalCompiler.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/CMakeTestPascalCompiler.cmake Mon Mar 18 00:58:13 2013 +0100 @@ -0,0 +1,54 @@ +# This file is used by EnableLanguage in cmGlobalGenerator to determine that +# the Ada builder GNAT_EXECUTABLE_BUILDER = gnatmake can actually compile +# and link the most basic of programs. If not, a fatal error is set and +# cmake stops processing commands and will not generate any makefiles or +# projects. + +IF(NOT CMAKE_Pascal_COMPILER_WORKS) + MESSAGE(STATUS "Check for working Pascal compiler: ${CMAKE_Pascal_COMPILER}") + FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testpascalcompiler.pas + "program testPascalCompiler; + begin + + end. + ") + + FILE(WRITE ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp/CMakeLists.txt + "set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules) + set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL \"\" FORCE) + project(test Pascal) + add_executable(testpascalcompiler testpascalcompiler.pas) + ") + +# To avoid try_compile recurse error, use any binary directory other than +# ${CMAKE_BINARY_DIR}. The choice of +# bindir = ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp is +# especially advantageous since it makes an in-source build which +# means that no special variables need to be set to find files. + try_compile(CMAKE_Pascal_COMPILER_WORKS + ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp + ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp + projectName + OUTPUT_VARIABLE OUTPUT + ) + SET(PASCAL_TEST_WAS_RUN 1) +ENDIF(NOT CMAKE_Pascal_COMPILER_WORKS) + +IF(NOT CMAKE_Pascal_COMPILER_WORKS) + MESSAGE(STATUS "Check for working Pascal compiler: ${CMAKE_Pascal_COMPILER} -- broken") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the Pascal compiler works failed with " + "the following output:\n${OUTPUT}\n\n") + MESSAGE(FATAL_ERROR "The Pascal builder \"${CMAKE_Pascal_COMPILER}\" " + "is not able to compile, and link a simple test program.\nIt fails " + "with the following output:\n ${OUTPUT}\n\n" + "CMake will not be able to correctly generate this project.") +ELSE(NOT CMAKE_Pascal_COMPILER_WORKS) + IF(PASCAL_TEST_WAS_RUN) + MESSAGE(STATUS "Check for working Pascal compiler: ${CMAKE_Pascal_COMPILER} -- works") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the Pascal compiler works passed with " + "the following output:\n${OUTPUT}\n\n") + ENDIF(PASCAL_TEST_WAS_RUN) + SET(CMAKE_Pascal_COMPILER_WORKS 1 CACHE INTERNAL "") +ENDIF(NOT CMAKE_Pascal_COMPILER_WORKS)