Skip to content
Snippets Groups Projects
CMakeLists.txt 2.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • cmake_minimum_required(VERSION 3.8)
    
    project(
    	"B-ASIC"
    	VERSION 0.0.1
    	DESCRIPTION "Better ASIC Toolbox for python3"
    	LANGUAGES C CXX
    )
    
    find_package(fmt 5.2.1 REQUIRED)
    find_package(pybind11 CONFIG REQUIRED)
    
    set(LIBRARY_NAME "b_asic")
    set(TARGET_NAME "_${LIBRARY_NAME}")
    
    if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
    	include(GNUInstallDirs)
    	set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}")
    endif()
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_PDB_OUTPUT_DIRECTORY_DEBUG "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_PDB_OUTPUT_DIRECTORY_RELEASE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    
    pybind11_add_module(
    	"${TARGET_NAME}"
    	"${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp"
    )
    
    target_include_directories(
    	"${TARGET_NAME}"
        PRIVATE
            "${CMAKE_CURRENT_SOURCE_DIR}/src"
    )
    
    target_compile_features(
    	"${TARGET_NAME}"
    	PRIVATE
    		cxx_std_17
    )
    target_compile_options(
    	"${TARGET_NAME}"
    	PRIVATE
    		$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:
    			-W -Wall -Wextra -Werror -Wno-psabi
    			$<$<CONFIG:Debug>:-g>
    			$<$<NOT:$<CONFIG:Debug>>:-O3>
    		>
    		$<$<CXX_COMPILER_ID:MSVC>:
    			/W3 /WX /permissive- /utf-8
    			$<$<CONFIG:Debug>:/Od>
    			$<$<NOT:$<CONFIG:Debug>>:/Ot>
    		>
    )
    
    target_link_libraries(
    	"${TARGET_NAME}"
    	PRIVATE
    		fmt::fmt
    )
    
    add_custom_target(
    	remove_old_python_dir ALL
    	COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${LIBRARY_NAME}"
    	COMMENT "Removing old python directory ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${LIBRARY_NAME}"
    )
    add_custom_target(
    	copy_python_dir ALL
    	COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_LIST_DIR}/${LIBRARY_NAME}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${LIBRARY_NAME}"
    	COMMENT "Copying python files to ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${LIBRARY_NAME}"
    	DEPENDS "${TARGET_NAME}" remove_old_python_dir
    )