pawn-compiler/source/compiler/CMakeLists.txt

208 lines
5.5 KiB
CMake
Raw Permalink Normal View History

project(pawnc C)
2015-04-02 15:20:27 +06:00
cmake_minimum_required(VERSION 2.8)
2014-01-10 01:44:21 +07:00
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
set(VERSION_MAJOR 3)
set(VERSION_MINOR 10)
2020-02-08 19:04:51 +06:00
set(VERSION_BUILD 10)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD})
set(VERSION_STR ${VERSION})
math(EXPR VERSION_INT "${VERSION_MAJOR} << 8 | ${VERSION_MINOR}")
2014-01-10 01:44:21 +07:00
# check for optional include files
2015-04-02 15:20:27 +06:00
include(CheckIncludeFile)
check_include_file("unistd.h" HAVE_UNISTD_H)
if(HAVE_UNISTD_H)
add_definitions(-DHAVE_UNISTD_H)
endif()
check_include_file("inttypes.h" HAVE_INTTYPES_H)
if(HAVE_INTTYPES_H)
add_definitions(-DHAVE_INTTYPES_H)
endif()
check_include_file("stdint.h" HAVE_STDINT_H)
if(HAVE_STDINT_H)
add_definitions(-DHAVE_STDINT_H)
endif()
check_include_file("alloca.h" HAVE_ALLOCA_H)
if(HAVE_ALLOCA_H)
add_definitions(-DHAVE_ALLOCA_H)
endif()
2017-02-11 19:39:54 +06:00
check_include_file("endian.h" HAVE_ENDIAN_H)
if(HAVE_ENDIAN_H)
add_definitions(-DHAVE_ENDIAN_H)
endif()
2014-01-10 01:44:21 +07:00
# check for optional library functions
include(CheckFunctionExists)
check_function_exists(strlcpy HAVE_STRLCPY)
if(HAVE_STRLCPY)
add_definitions(-DHAVE_STRLCPY)
endif()
check_function_exists(strlcat HAVE_STRLCAT)
if(HAVE_STRLCAT)
add_definitions(-DHAVE_STRLCAT)
endif()
2015-04-02 15:20:27 +06:00
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
2017-10-28 04:32:55 +06:00
if(MSVC LESS 1900)
# MSVC 2013 and below don't support the "inline" keyword
add_definitions(-Dinline=__inline)
endif()
2015-04-02 15:20:27 +06:00
endif()
2014-01-25 23:59:53 +07:00
2015-04-02 15:20:27 +06:00
if(UNIX)
add_definitions(-DLINUX -DENABLE_BINRELOC -g)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../linux)
2015-04-07 19:24:32 +06:00
link_libraries(pthread)
2015-04-02 15:20:27 +06:00
endif()
2014-01-10 01:44:21 +07:00
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/version.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
2014-01-10 01:44:21 +07:00
# The Pawn compiler shared library
2015-04-07 19:24:32 +06:00
set(PAWNC_SRCS
hashtable/wrap_hashtable.c
hashtable/wrap_hashtable.h
hashtable/hashtable.h
2015-04-07 19:24:32 +06:00
libpawnc.c
lstring.c
2017-01-21 14:33:18 +06:00
lstring.h
2015-04-07 19:24:32 +06:00
memfile.c
2017-01-21 14:33:18 +06:00
memfile.h
sc.h
2015-04-07 19:24:32 +06:00
sc1.c
sc2.c
sc3.c
sc4.c
sc5.c
sc6.c
sc7.c
sci18n.c
sclist.c
scmemfil.c
scstate.c
2017-01-21 14:33:18 +06:00
scvars.c
version.h)
2015-04-02 15:20:27 +06:00
set_source_files_properties(sc1.c COMPILE_FLAGS -DNO_MAIN)
if(WIN32)
set(PAWNC_SRCS ${PAWNC_SRCS} libpawnc.rc)
set_source_files_properties(libpawnc.c COMPILE_FLAGS -DPAWNC_DLL)
if(BORLAND)
2014-01-10 01:44:21 +07:00
# Borland linker uses a DEF file if one is in the output directory
2015-04-07 19:24:32 +06:00
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpawnc.def.borland
${CMAKE_CURRENT_BINARY_DIR}/pawnc.def
2015-04-07 19:24:32 +06:00
COPYONLY)
2015-04-02 15:20:27 +06:00
else()
2014-01-10 01:44:21 +07:00
# Microsoft Visual C/C++ supports a DEF file as if it were a source file
2015-04-02 15:20:27 +06:00
set(PAWNC_SRCS ${PAWNC_SRCS} libpawnc.def)
endif()
endif()
if(UNIX)
2015-04-07 19:24:32 +06:00
set(PAWNC_SRCS
${PAWNC_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/../linux/binreloc.c
)
2015-04-02 15:20:27 +06:00
endif()
add_library(pawnc SHARED ${PAWNC_SRCS})
if(WATCOM) #Watcom C/C++ does not support a .DEF file for the exports
set_target_properties(pawnc PROPERTIES LINK_FLAGS "/exp=libpawnc")
2015-04-06 17:00:27 +06:00
elseif(MINGW)
2015-04-07 19:24:32 +06:00
set_target_properties(pawnc PROPERTIES LINK_FLAGS
"-Wl,--enable-stdcall-fixup")
set_target_properties(pawnc PROPERTIES PREFIX "")
2015-04-02 15:20:27 +06:00
endif()
2014-01-10 01:44:21 +07:00
# The Pawn compiler driver (console program)
2015-04-02 15:20:27 +06:00
set(PAWNCC_SRCS pawncc.c)
if(WIN32)
set(PAWNCC_SRCS ${PAWNCC_SRCS} libpawnc.rc)
if(BORLAND)
2014-01-10 01:44:21 +07:00
# Borland linker uses a DEF file if one is in the output directory
2015-04-07 19:24:32 +06:00
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pawncc.def.borland
${CMAKE_CURRENT_BINARY_DIR}/pawncc.def
2015-04-07 19:24:32 +06:00
COPYONLY)
2015-04-02 15:20:27 +06:00
else()
2014-01-10 01:44:21 +07:00
# Microsoft Visual C/C++ supports a DEF file as if it were a source file
2015-04-02 15:20:27 +06:00
set(PAWNC_SRCS ${PAWNC_SRCS} pawncc.def)
endif()
endif()
add_executable(pawncc ${PAWNCC_SRCS})
target_link_libraries(pawncc pawnc)
2014-08-29 22:38:56 +07:00
# The Pawn disassembler
2015-04-07 19:24:32 +06:00
set(PAWNDISASM_SRCS
pawndisasm.c
2018-08-11 23:12:13 +06:00
sc.h
../amx/amx.h
../amx/amxdbg.h
2015-04-07 19:24:32 +06:00
../amx/amxdbg.c
)
2015-04-02 15:20:27 +06:00
add_executable(pawndisasm ${PAWNDISASM_SRCS})
if(UNIX)
target_link_libraries(pawndisasm dl)
endif()
# Install compiler and disassembler binaries
install(TARGETS pawnc pawncc pawndisasm
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib)
if(MSVC)
# If building with Microsoft Visual C++ also install corresponding
# Program Database files (for debugging)
install(
FILES ${PROJECT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/pawnc.pdb
${PROJECT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/pawncc.pdb
${PROJECT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/pawndisasm.pdb
DESTINATION bin)
endif()
2015-04-12 19:14:29 +06:00
# Generate targets for running compiler tests
include(CTest)
if(BUILD_TESTING)
2018-08-11 23:50:58 +06:00
set(PAWNRUNS_SRCS
pawnruns.c
../amx/amx.c
../amx/amx.h
../amx/amxaux.c
../amx/amxaux.h
../amx/amxcons.c
../amx/amxcore.c
2018-08-11 23:41:46 +06:00
)
if(UNIX)
set(PAWNRUNS_SRCS
${PAWNRUNS_SRCS}
../linux/getch.c
../linux/getch.h
../linux/binreloc.c
)
endif()
add_executable(pawnruns ${PAWNRUNS_SRCS})
if(UNIX)
target_link_libraries(pawnruns dl)
endif()
add_subdirectory(tests)
2018-08-11 23:41:46 +06:00
endif()
2015-04-12 19:14:29 +06:00
# Generate a binary package with CPack
set(CPACK_PACKAGE_NAME pawnc)
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION ${VERSION_STR})
if(WIN32)
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${VERSION_STR}-windows)
elseif(APPLE)
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${VERSION_STR}-macos)
else()
string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME_LOWER)
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${VERSION_STR}-${SYSTEM_NAME_LOWER})
endif()
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/../../license.txt)
2015-04-12 19:14:29 +06:00
include(CPack)