Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake support #20

Open
4e1e0603 opened this issue Jul 25, 2021 · 2 comments
Open

CMake support #20

4e1e0603 opened this issue Jul 25, 2021 · 2 comments

Comments

@4e1e0603
Copy link

Hi, many thanks for all the work. Is there interest in the use of CMake? With CMake, the project will be more portable across different os and build systems.

@nobane
Copy link

nobane commented Jun 21, 2022

+1 this would be nice to have!

@Philosoph228
Copy link

Philosoph228 commented Dec 18, 2024

You can write CMakeLists.txt by yourself

cmake_minimum_required(VERSION 3.16 FATAL_ERROR)

project(glsl-parser LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Compiler flags
if (MSVC)
    # MSVC-specific flags
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR- /EHs- /W4 /O2")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
else()
    # Non-MSVC flags
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptoins -Wall -Wextra -Wformat -O3")
endif()

# Source files
set(SOURCES
    ast.cpp
    lexer.cpp
    parser.cpp
    util.cpp
)

# Header files
set(HEADERS
    ast.h
    lexemes.h
    lexer.h
    parser.h
    util.h
)

# Static library target
add_library(${PROJECT_NAME} STATIC ${SOURCES})

# Public include directories
target_include_directories(${PROJECT_NAME} PUBLIC
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
    $<INSTALL_INTERFACE:include>
)

# MSVC-specific setting
if(MSVC)
    target_compile_options(${PROJECT_NAME} PRIVATE /permissive- /Zc:preprocessor /W4)
endif()

# Installation rules
include(GNUInstallDirs)

# Install the library
install(TARGETS ${PROJECT_NAME}
    EXPORT ${PROJECT_NAME}Targets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# Install the headers
install(FILES ${HEADERS}
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)

# Export the target for use by other projects
install(EXPORT ${PROJECT_NAME}Targets
    FILE ${PROJECT_NAME}Targets.cmake
    NAMESPACE glsl-parser::
    DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants