cmake_modules/CMakeDeterminePascalCompiler.cmake
branchcmake_pascal
changeset 8859 bead90828a94
parent 8852 0576439ef859
child 9413 37fcb9a796e6
equal deleted inserted replaced
8855:879270f627e0 8859:bead90828a94
     3 # loading this file to force a compiler.
     3 # loading this file to force a compiler.
     4 # use environment variable Pascal first if defined by user, next use
     4 # use environment variable Pascal first if defined by user, next use
     5 # the cmake variable CMAKE_GENERATOR_PASCAL which can be defined by a generator
     5 # the cmake variable CMAKE_GENERATOR_PASCAL which can be defined by a generator
     6 # as a default compiler
     6 # as a default compiler
     7 
     7 
     8 IF(NOT CMAKE_Pascal_COMPILER)
     8 if(NOT CMAKE_Pascal_COMPILER)
       
     9     # prefer the environment variable FPC
       
    10     if($ENV{FPC} MATCHES ".+")
       
    11         get_filename_component(CMAKE_Pascal_COMPILER_INIT $ENV{FPC} PROGRAM PROGRAM_ARGS CMAKE_Pascal_FLAGS_ENV_INIT)
       
    12         if(CMAKE_Pascal_FLAGS_ENV_INIT)
       
    13             set(CMAKE_Pascal_COMPILER_ARG1 "${CMAKE_Pascal_FLAGS_ENV_INIT}" CACHE STRING "First argument to Pascal compiler")
       
    14         endif(CMAKE_Pascal_FLAGS_ENV_INIT)
       
    15         if(EXISTS ${CMAKE_Pascal_COMPILER_INIT})
       
    16         else(EXISTS ${CMAKE_Pascal_COMPILER_INIT})
       
    17             message(FATAL_ERROR "Could not find compiler set in environment variable FPC:\n$ENV{FPC}.")
       
    18         endif(EXISTS ${CMAKE_Pascal_COMPILER_INIT})
       
    19     endif($ENV{FPC} MATCHES ".+")
     9 
    20 
    10   # prefer the environment variable FPC
    21     # next try prefer the compiler specified by the generator
    11   IF($ENV{FPC} MATCHES ".+")
    22     if(CMAKE_GENERATOR_PASCAL)
    12     GET_FILENAME_COMPONENT(CMAKE_Pascal_COMPILER_INIT $ENV{FPC} PROGRAM PROGRAM_ARGS CMAKE_Pascal_FLAGS_ENV_INIT)
    23         if(NOT CMAKE_Pascal_COMPILER_INIT)
    13     IF(CMAKE_Pascal_FLAGS_ENV_INIT)
    24             set(CMAKE_Pascal_COMPILER_INIT ${CMAKE_GENERATOR_PASCAL})
    14       SET(CMAKE_Pascal_COMPILER_ARG1 "${CMAKE_Pascal_FLAGS_ENV_INIT}" CACHE STRING "First argument to Pascal compiler")
    25         endif(NOT CMAKE_Pascal_COMPILER_INIT)
    15     ENDIF(CMAKE_Pascal_FLAGS_ENV_INIT)
    26     endif(CMAKE_GENERATOR_PASCAL)
    16     IF(EXISTS ${CMAKE_Pascal_COMPILER_INIT})
       
    17     ELSE(EXISTS ${CMAKE_Pascal_COMPILER_INIT})
       
    18       MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable FPC:\n$ENV{FPC}.")
       
    19     ENDIF(EXISTS ${CMAKE_Pascal_COMPILER_INIT})
       
    20   ENDIF($ENV{FPC} MATCHES ".+")
       
    21 
    27 
    22   # next try prefer the compiler specified by the generator
    28     # finally list compilers to try
    23   IF(CMAKE_GENERATOR_PASCAL)
    29     if(CMAKE_Pascal_COMPILER_INIT)
    24     IF(NOT CMAKE_Pascal_COMPILER_INIT)
    30         set(CMAKE_Pascal_COMPILER_LIST ${CMAKE_Pascal_COMPILER_INIT})
    25       SET(CMAKE_Pascal_COMPILER_INIT ${CMAKE_GENERATOR_PASCAL})
    31     else(CMAKE_Pascal_COMPILER_INIT)
    26     ENDIF(NOT CMAKE_Pascal_COMPILER_INIT)
    32         set(CMAKE_Pascal_COMPILER_LIST fpc)
    27   ENDIF(CMAKE_GENERATOR_PASCAL)
    33     endif(CMAKE_Pascal_COMPILER_INIT)
    28 
    34 
    29   # finally list compilers to try
    35     # Find the compiler.
    30   IF(CMAKE_Pascal_COMPILER_INIT)
    36     find_program(CMAKE_Pascal_COMPILER NAMES ${CMAKE_Pascal_COMPILER_LIST} DOC "Pascal compiler")
    31     SET(CMAKE_Pascal_COMPILER_LIST ${CMAKE_Pascal_COMPILER_INIT})
    37     if(CMAKE_Pascal_COMPILER_INIT AND NOT CMAKE_Pascal_COMPILER)
    32   ELSE(CMAKE_Pascal_COMPILER_INIT)
    38         set(CMAKE_Pascal_COMPILER "${CMAKE_Pascal_COMPILER_INIT}" CACHE FILEPATH "Pascal compiler" FORCE)
    33     SET(CMAKE_Pascal_COMPILER_LIST fpc)
    39     endif(CMAKE_Pascal_COMPILER_INIT AND NOT CMAKE_Pascal_COMPILER)
    34   ENDIF(CMAKE_Pascal_COMPILER_INIT)
    40 endif(NOT CMAKE_Pascal_COMPILER)
    35 
    41 mark_as_advanced(CMAKE_Pascal_COMPILER)
    36   # Find the compiler.
       
    37   FIND_PROGRAM(CMAKE_Pascal_COMPILER NAMES ${CMAKE_Pascal_COMPILER_LIST} DOC "Pascal compiler")
       
    38   IF(CMAKE_Pascal_COMPILER_INIT AND NOT CMAKE_Pascal_COMPILER)
       
    39     SET(CMAKE_Pascal_COMPILER "${CMAKE_Pascal_COMPILER_INIT}" CACHE FILEPATH "Pascal compiler" FORCE)
       
    40   ENDIF(CMAKE_Pascal_COMPILER_INIT AND NOT CMAKE_Pascal_COMPILER)
       
    41 ENDIF(NOT CMAKE_Pascal_COMPILER)
       
    42 MARK_AS_ADVANCED(CMAKE_Pascal_COMPILER)
       
    43 
    42 
    44 if(NOT CMAKE_Pascal_COMPILER_VERSION)
    43 if(NOT CMAKE_Pascal_COMPILER_VERSION)
    45   execute_process(COMMAND ${CMAKE_Pascal_COMPILER} -iV
    44     execute_process(COMMAND ${CMAKE_Pascal_COMPILER} -iV
    46                   OUTPUT_VARIABLE CMAKE_Pascal_COMPILER_VERSION
    45                     OUTPUT_VARIABLE CMAKE_Pascal_COMPILER_VERSION
    47                   OUTPUT_STRIP_TRAILING_WHITESPACE
    46                     OUTPUT_STRIP_TRAILING_WHITESPACE
    48                   ) # we assume no error for something so simple
    47                     ) # we assume no error for something so simple
    49 endif(NOT CMAKE_Pascal_COMPILER_VERSION)
    48 endif(NOT CMAKE_Pascal_COMPILER_VERSION)
    50 mark_as_advanced(CMAKE_Pascal_COMPILER_VERSION)
    49 mark_as_advanced(CMAKE_Pascal_COMPILER_VERSION)
    51 
    50 
    52 GET_FILENAME_COMPONENT(COMPILER_LOCATION "${CMAKE_Pascal_COMPILER}" PATH)
    51 get_filename_component(COMPILER_LOCATION "${CMAKE_Pascal_COMPILER}" PATH)
    53 
    52 
    54 # configure variables set in this file for fast reload later on
    53 # configure variables set in this file for fast reload later on
    55 if(${CMAKE_VERSION} VERSION_LESS 2.8.10)
    54 if(${CMAKE_VERSION} VERSION_LESS 2.8.10)
    56   CONFIGURE_FILE(${CMAKE_MODULE_PATH}/CMakePascalCompiler.cmake.in
    55     configure_file(${CMAKE_MODULE_PATH}/CMakePascalCompiler.cmake.in
    57                  "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakePascalCompiler.cmake"
    56                    "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakePascalCompiler.cmake"
    58                  IMMEDIATE )
    57                    IMMEDIATE )
    59 else(${CMAKE_VERSION} VERSION_LESS 2.8.10)
    58 else(${CMAKE_VERSION} VERSION_LESS 2.8.10)
    60   CONFIGURE_FILE(${CMAKE_MODULE_PATH}/CMakePascalCompiler.cmake.in
    59     configure_file(${CMAKE_MODULE_PATH}/CMakePascalCompiler.cmake.in
    61                 "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakePascalCompiler.cmake"
    60                   "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakePascalCompiler.cmake"
    62                  IMMEDIATE )
    61                    IMMEDIATE )
    63 endif(${CMAKE_VERSION} VERSION_LESS 2.8.10)
    62 endif(${CMAKE_VERSION} VERSION_LESS 2.8.10)
    64 
    63 
    65 SET(CMAKE_Pascal_COMPILER_ENV_VAR "FPC")
    64 set(CMAKE_Pascal_COMPILER_ENV_VAR "FPC")
       
    65